Skip to content

Commit

Permalink
Merge branch 'tsvilans-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jesterKing committed Aug 22, 2019
2 parents dec1e86 + ff26114 commit af509de
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 51 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@ Until then things can, and will, break.
Installation on Windows
=======================


* Install [Python 3.7.1 (64-bit)](https://www.python.org/ftp/python/3.7.1/python-3.7.1-amd64.exe), have the installer add Python 3.7 to your PATH as well. Make sure pip gets installed (using the defaults from the first button, together with the checkbox for adding to PATH should get that set up).
* Open a cmd.exe (start > run > cmd.exe)
* install `rhino3dm.py` by typing in the command prompt: `pip3.7 install --user rhino3dm`
* Get the correct zip file from https://github.com/jesterKing/import_3dm/releases/latest (the one with import_3dm in the name)
* Start Blender 2.80
* In top menu press Edit > User Preferences...
* Select the section Add-ons
* In the bottom of that window select Install add-on from file...
* Browse to where you saved the zip file, select it and press the Install add-on from file button in the top right of the file browser
* Done. Probably a good idea to restart Blender.

From version 0.0.4 onward all dependencies will be automatically installed.

If you just now downloaded Blender 2.80 you can either use the operator search menu by pressing F3, or through File > Import.

Installation on Mac OS X
Expand Down
20 changes: 12 additions & 8 deletions import_3dm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
bl_info = {
"name": "Import Rhinoceros 3D",
"author": "Nathan 'jesterKing' Letwory, Joel Putnam, Tom Svilans",
"version": (0, 0, 3),
"version": (0, 0, 4),
"blender": (2, 80, 0),
"location": "File > Import > Rhinoceros 3D (.3dm)",
"description": "This addon lets you import Rhinoceros 3dm files",
Expand All @@ -40,8 +40,6 @@
from bpy.props import StringProperty, BoolProperty, EnumProperty
from bpy.types import Operator

import rhino3dm as r3d

from .read3dm import read_3dm


Expand All @@ -68,16 +66,23 @@ class Import3dm(Operator, ImportHelper):
)

import_views: BoolProperty(
name="Import views.",
name="Import standard views.",
description="Import standard views (Top, Front, Right, Perspective) as cameras.",
default=True,
default=False,
)

import_named_views: BoolProperty(
name="Import named views.",
description="Import named views as cameras.",
default=True,
)
)


update_materials: BoolProperty(
name="Update materials.",
description="Update existing materials. Otherwise, create new materials if existing ones are found.",
default=True,
)

# type: EnumProperty(
# name="Example Enum",
Expand All @@ -90,8 +95,7 @@ class Import3dm(Operator, ImportHelper):
# )

def execute(self, context):
return read_3dm(context, self.filepath, self.import_hidden, self.import_views, self.import_named_views)

return read_3dm(context, self.filepath, self.import_hidden, self.import_views, self.import_named_views, self.update_materials)

# Only needed if you want to add into a dynamic menu
def menu_func_import(self, context):
Expand Down
11 changes: 6 additions & 5 deletions import_3dm/converters/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from . import utils


def handle_layers(context, model, toplayer, layerids, materials):
def handle_layers(context, model, toplayer, layerids, materials, update):
"""
In context read the Rhino layers from model
then update the layerids dictionary passed in.
Expand All @@ -42,10 +42,11 @@ def handle_layers(context, model, toplayer, layerids, materials):
matname = l.Name + "+" + str(l.Id)
if matname not in materials:
laymat = utils.get_iddata(context.blend_data.materials, l.Id, l.Name, None)
laymat.use_nodes = True
r, g, b, _ = l.Color
principled = PrincipledBSDFWrapper(laymat, is_readonly=False)
principled.base_color = (r/255.0, g/255.0, b/255.0)
if update:
laymat.use_nodes = True
r, g, b, _ = l.Color
principled = PrincipledBSDFWrapper(laymat, is_readonly=False)
principled.base_color = (r/255.0, g/255.0, b/255.0)
materials[matname] = laymat
# second pass so we can link layers to each other
for l in model.Layers:
Expand Down
57 changes: 29 additions & 28 deletions import_3dm/converters/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,39 +100,40 @@ def material_name(m):
return m.Name + "~" + str(h)


def handle_materials(context, model, materials):
def handle_materials(context, model, materials, update):
"""
"""
for m in model.Materials:
matname = material_name(m)
if matname not in materials:
blmat = utils.get_iddata(context.blend_data.materials, None, m.Name, None)
blmat.use_nodes = True
refl = m.Reflectivity
transp = m.Transparency
ior = m.IndexOfRefraction
roughness = m.ReflectionGlossiness
transrough = m.RefractionGlossiness
spec = m.Shine / 255.0

if m.DiffuseColor == _black and m.Reflectivity > 0.0 and m.Transparency == 0.0:
r, g, b, _ = m.ReflectionColor
elif m.DiffuseColor == _black and m.Reflectivity == 0.0 and m.Transparency > 0.0:
r, g, b, _ = m.TransparentColor
refl = 0.0
elif m.DiffuseColor == _black and m.Reflectivity > 0.0 and m.Transparency > 0.0:
r, g, b, _ = m.TransparentColor
refl = 0.0
else:
r, g, b, a = m.DiffuseColor
if refl > 0.0 and transp > 0.0:
if update:
blmat.use_nodes = True
refl = m.Reflectivity
transp = m.Transparency
ior = m.IndexOfRefraction
roughness = m.ReflectionGlossiness
transrough = m.RefractionGlossiness
spec = m.Shine / 255.0

if m.DiffuseColor == _black and m.Reflectivity > 0.0 and m.Transparency == 0.0:
r, g, b, _ = m.ReflectionColor
elif m.DiffuseColor == _black and m.Reflectivity == 0.0 and m.Transparency > 0.0:
r, g, b, _ = m.TransparentColor
refl = 0.0
principled = PrincipledBSDFWrapper(blmat, is_readonly=False)
principled.base_color = (r/255.0, g/255.0, b/255.0)
principled.metallic = refl
principled.transmission = transp
principled.ior = ior
principled.roughness = roughness
principled.specular = spec
principled.node_principled_bsdf.inputs[16].default_value = transrough
elif m.DiffuseColor == _black and m.Reflectivity > 0.0 and m.Transparency > 0.0:
r, g, b, _ = m.TransparentColor
refl = 0.0
else:
r, g, b, a = m.DiffuseColor
if refl > 0.0 and transp > 0.0:
refl = 0.0
principled = PrincipledBSDFWrapper(blmat, is_readonly=False)
principled.base_color = (r/255.0, g/255.0, b/255.0)
principled.metallic = refl
principled.transmission = transp
principled.ior = ior
principled.roughness = roughness
principled.specular = spec
principled.node_principled_bsdf.inputs[16].default_value = transrough
materials[matname] = blmat
73 changes: 68 additions & 5 deletions import_3dm/read3dm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,73 @@

import os.path
import bpy
import rhino3dm as r3d

def install_dependencies():
import sys
import os
try:
try:
import pip
except:
from subprocess import run as sprun
print("Installing pip... "),
pyver = ""
if sys.platform != "win32":
pyver = "python{}.{}".format(
sys.version_info.major,
sys.version_info.minor
)

ensurepip = os.path.normpath(
os.path.join(
os.path.dirname(bpy.app.binary_path_python),
"..", "lib", pyver, "ensurepip"
)
)
res = sprun([bpy.app.binary_path_python, ensurepip])

if res.returncode == 0:
import pip
else:
raise Exception("Failed to install pip.")

modulespath = os.path.normpath(
os.path.join(
bpy.utils.script_path_user(),
"addons",
"modules"
)
)
if not os.path.exists(modulespath):
os.makedirs(modulespath)
print("Installing rhino3dm to {}... ".format(modulespath)),

try:
from pip import main as pipmain
except:
from pip._internal import main as pipmain

res = pipmain(["install", "--upgrade", "--target", modulespath, "rhino3dm"])
if res > 0:
raise Exception("Failed to install rhino3dm.")
except:
raise Exception("Failed to install dependencies. Please make sure you have pip installed.")

try:
import rhino3dm as r3d
except:
print("Failed to load rhino3dm.")
from sys import platform
if platform == "win32":
install_dependencies()
import rhino3dm as r3d
else:
print("Platform {} cannot automatically install dependencies.".format(platform))
raise

from . import converters

def read_3dm(context, filepath, import_hidden, import_views, import_named_views):
def read_3dm(context, filepath, import_hidden, import_views, import_named_views, update_materials):
top_collection_name = os.path.splitext(os.path.basename(filepath))[0]
if top_collection_name in context.blend_data.collections.keys():
toplayer = context.blend_data.collections[top_collection_name]
Expand All @@ -46,9 +109,9 @@ def read_3dm(context, filepath, import_hidden, import_views, import_named_views)
if import_named_views:
converters.handle_views(context, model, toplayer, model.NamedViews, "NamedViews", scale)

converters.handle_materials(context, model, materials)
converters.handle_materials(context, model, materials, update_materials)

converters.handle_layers(context, model, toplayer, layerids, materials)
converters.handle_layers(context, model, toplayer, layerids, materials, update_materials)

for ob in model.Objects:
og = ob.Geometry
Expand Down Expand Up @@ -90,4 +153,4 @@ def read_3dm(context, filepath, import_hidden, import_views, import_named_views)
except Exception:
pass

return {'FINISHED'}
return {'FINISHED'}

0 comments on commit af509de

Please sign in to comment.