Skip to content

Commit

Permalink
Add vray renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
celentes committed Jun 14, 2020
1 parent c0c2049 commit 10de2c7
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
6 changes: 6 additions & 0 deletions UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class PBMC_Dialog(c4d.gui.GeDialog):
bindings_hide = True

def query_renderers(self):
if c4d.plugins.FindPlugin(1038954) is not None:
print "PBMC: Found vray plugin"
import vray
self.renderers["VRay"] = vray
self.rnd = vray
if c4d.plugins.FindPlugin(1041569) is not None:
print "PBMC: Found octane plugin"
import octane
Expand Down Expand Up @@ -248,6 +253,7 @@ def Command(self, id, msg):
_name = self.renderers.keys()[_id]
_rnd = self.renderers[_name]
self.rnd = _rnd
self.redraw_bindings()
print "PBMC: Setting renderer to " + _name

return True
3 changes: 3 additions & 0 deletions c4d.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import arnold
reload(arnold)

import vray
reload(vray)

# TODO: bloody specs

# Main function
Expand Down
1 change: 1 addition & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ cp photobash_material_converter.pyp ~/c4d_pbmc
mkdir ~/c4d_pbmc/src
cp arnold.py ~/c4d_pbmc/src
cp octane.py ~/c4d_pbmc/src
cp vray.py ~/c4d_pbmc/src
cp UI.py ~/c4d_pbmc/src
cp TextureMapping.py ~/c4d_pbmc/src
82 changes: 82 additions & 0 deletions vray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import c4d
import TextureMapping as tm

class binding:
def __init__(self, name, id):
self._name = name
self._id = id
def id(self):
return self._id
def name(self):
return self._name

#VRayStandardMaterial[c4d.VRAYSTDMATERIAL_DIFFUSECOLOR_TEX]
#VRayStandardMaterial[c4d.VRAYSTDMATERIAL_OPACITY_TEX]
#VRayStandardMaterial[c4d.VRAYSTDMATERIAL_REFLECTGLOSSINESS_TEX]
#VRayStandardMaterial[c4d.VRAYSTDMATERIAL_REFLECTCOLOR_TEX]
#VRayStandardMaterial[c4d.VRAYSTDMATERIAL_SELFILLUMCOLOR_TEX]
#VRayStandardMaterial[c4d.VRAYSTDMATERIAL_BUMP_BUMPMAP]

VRAY_BINDINS = {
"Diffuse" : binding("Diffuse", c4d.VRAYSTDMATERIAL_DIFFUSECOLOR_TEX),
"Specular" : binding("Reflection", c4d.VRAYSTDMATERIAL_REFLECTCOLOR_TEX),
"Roughness" : binding("RGlossiness", c4d.VRAYSTDMATERIAL_REFLECTGLOSSINESS_TEX),
"Bump" : binding("Bump", c4d.VRAYSTDMATERIAL_BUMP_BUMPMAP),
"Opacity" : binding("Opacity", c4d.VRAYSTDMATERIAL_OPACITY_TEX),
"Emission" : binding("Self-Illumination", c4d.VRAYSTDMATERIAL_SELFILLUMCOLOR_TEX),
}

def get_binding(tex_type):
if tex_type in VRAY_BINDINS:
return VRAY_BINDINS[tex_type]
else:
return None

def get_binding_name(tex_type):
binding = get_binding(tex_type)
if binding is not None:
return binding.name()
else:
return tm.NOTMAPPED_STR

def create_texture(filename):
shd = c4d.BaseShader(c4d.Xbitmap)
shd[c4d.BITMAPSHADER_FILENAME] = filename
return shd

def create_material(name):
ID_VRAY_STANDARD_MATERIAL = 1038954
mat = c4d.BaseMaterial(ID_VRAY_STANDARD_MATERIAL)
mat.SetName(name+"_vray")
return mat

def bind_texture(mat, tex_path, binding):
print "setting " + binding.name()
shd = create_texture(tex_path)
shd.SetName(binding.name())

# Gloss = 1/Roughness
if binding.name() == "RGlossiness":
shd[c4d.BITMAPSHADER_BLACKPOINT] = 1
shd[c4d.BITMAPSHADER_WHITEPOINT] = 0
#mat[c4d.VRAYSTDMATERIAL_BRDFUSEROUGHNESS] = 1

mat.InsertShader(shd)
mat[binding.id()] = shd
return

def upgrade_material(mat, directories):
name = mat.GetName()
texfiles = tm.get_texture_filenames(directories, name)

vray_mat = create_material(name+"_vray")
for tex_path in texfiles:
tex_type = tm.get_texture_type(name,tex_path)
binding = get_binding(tex_type)
if binding is None:
continue
else:
bind_texture(vray_mat, tex_path, binding)
doc = c4d.documents.GetActiveDocument()
doc.InsertMaterial(vray_mat)
return vray_mat

0 comments on commit 10de2c7

Please sign in to comment.