[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4773] trunk/py/scripts/addons/ io_scene_fbx: support for texture UV wrap on cycles materials.
Campbell Barton
ideasman42 at gmail.com
Thu Sep 26 10:24:24 CEST 2013
Revision: 4773
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4773
Author: campbellbarton
Date: 2013-09-26 08:24:24 +0000 (Thu, 26 Sep 2013)
Log Message:
-----------
support for texture UV wrap on cycles materials.
Modified Paths:
--------------
trunk/py/scripts/addons/io_scene_fbx/cycles_shader_compat.py
trunk/py/scripts/addons/io_scene_fbx/import_fbx.py
Modified: trunk/py/scripts/addons/io_scene_fbx/cycles_shader_compat.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/cycles_shader_compat.py 2013-09-26 07:02:57 UTC (rev 4772)
+++ trunk/py/scripts/addons/io_scene_fbx/cycles_shader_compat.py 2013-09-26 08:24:24 UTC (rev 4773)
@@ -303,7 +303,7 @@
@staticmethod
def _mapping_create_helper(node_dst, socket_src,
- translation, rotation, scale):
+ translation, rotation, scale, clamp):
tree = node_dst.id_data
nodes = tree.nodes
links = tree.links
@@ -311,26 +311,46 @@
# in most cases:
# (socket_src == self.node_texcoords.outputs['UV'])
- node_map = nodes.new(type='ShaderNodeMapping')
- node_map.location = node_dst.location
- node_map.location.x -= CyclesShaderWrapper._col_size
+ node_map = None
- node_map.width = 160.0
+ # find an existing mapping node (allows multiple calls)
+ if node_dst.inputs["Vector"].links:
+ node_map = node_dst.inputs["Vector"].links[0].from_node
+ if node_map is None:
+ node_map = nodes.new(type='ShaderNodeMapping')
+ node_map.location = node_dst.location
+ node_map.location.x -= CyclesShaderWrapper._col_size
+
+ node_map.width = 160.0
+
+ # link mapping -> image node
+ links.new(node_map.outputs["Vector"],
+ node_dst.inputs["Vector"])
+
+ # link coord -> mapping
+ links.new(socket_src,
+ node_map.inputs["Vector"])
+
if translation is not None:
node_map.translation = translation
if scale is not None:
node_map.scale = scale
if rotation is not None:
node_map.rotation = rotation
+ if clamp is not None:
+ # awkward conversion UV clamping to minmax
+ node_map.min = (0.0, 0.0, 0.0)
+ node_map.max = (1.0, 1.0, 1.0)
- # link mapping -> image node
- links.new(node_map.outputs["Vector"],
- node_dst.inputs["Vector"])
+ if clamp in {(False, False), (True, True)}:
+ node_map.use_min = node_map.use_max = clamp[0]
+ else:
+ node_map.use_min = node_map.use_max = True
+ # use bool as index
+ node_map.min[not clamp[0]] = -1000000000.0
+ node_map.max[not clamp[0]] = 1000000000.0
- # link coord -> mapping
- links.new(socket_src,
- node_map.inputs["Vector"])
return node_map
# note, all ***_mapping_set() functions currenly work the same way
@@ -350,9 +370,9 @@
self._image_create_helper(image, node, (node.inputs["Color2"],)))
def diffuse_mapping_set(self, coords='UV',
- translation=None, rotation=None, scale=None):
+ translation=None, rotation=None, scale=None, clamp=None):
return self._mapping_create_helper(
- self.node_image_diff, self.node_texcoords.outputs[coords], translation, rotation, scale)
+ self.node_image_diff, self.node_texcoords.outputs[coords], translation, rotation, scale, clamp)
def specular_color_set(self, color):
self.node_bsdf_spec.mute = max(color) <= 0.0
@@ -364,9 +384,9 @@
self._image_create_helper(image, node, (node.inputs["Color2"],)))
def specular_mapping_set(self, coords='UV',
- translation=None, rotation=None, scale=None):
+ translation=None, rotation=None, scale=None, clamp=None):
return self._mapping_create_helper(
- self.node_image_spec, self.node_texcoords.outputs[coords], translation, rotation, scale)
+ self.node_image_spec, self.node_texcoords.outputs[coords], translation, rotation, scale, clamp)
def hardness_value_set(self, value):
node = self.node_mix_color_hard
@@ -378,9 +398,9 @@
self._image_create_helper(image, node, (node.inputs["Color2"],)))
def hardness_mapping_set(self, coords='UV',
- translation=None, rotation=None, scale=None):
+ translation=None, rotation=None, scale=None, clamp=None):
return self._mapping_create_helper(
- self.node_image_hard, self.node_texcoords.outputs[coords], translation, rotation, scale)
+ self.node_image_hard, self.node_texcoords.outputs[coords], translation, rotation, scale, clamp)
def reflect_color_set(self, color):
node = self.node_mix_color_refl
@@ -399,9 +419,9 @@
self._image_create_helper(image, node, (node.inputs["Color2"],)))
def reflect_mapping_set(self, coords='UV',
- translation=None, rotation=None, scale=None):
+ translation=None, rotation=None, scale=None, clamp=None):
return self._mapping_create_helper(
- self.node_image_refl, self.node_texcoords.outputs[coords], translation, rotation, scale)
+ self.node_image_refl, self.node_texcoords.outputs[coords], translation, rotation, scale, clamp)
def alpha_value_set(self, value):
self.node_bsdf_alpha.mute &= (value >= 1.0)
@@ -418,9 +438,9 @@
self._image_create_helper(image, node, (node.inputs["Color2"],), use_alpha=True))
def alpha_mapping_set(self, coords='UV',
- translation=None, rotation=None, scale=None):
+ translation=None, rotation=None, scale=None, clamp=None):
return self._mapping_create_helper(
- self.node_image_alpha, self.node_texcoords.outputs[coords], translation, rotation, scale)
+ self.node_image_alpha, self.node_texcoords.outputs[coords], translation, rotation, scale, clamp)
def alpha_image_set_from_diffuse(self):
# XXX, remove?
@@ -449,9 +469,9 @@
self.node_image_normalmap.color_space = 'NONE'
def normal_mapping_set(self, coords='UV',
- translation=None, rotation=None, scale=None):
+ translation=None, rotation=None, scale=None, clamp=None):
return self._mapping_create_helper(
- self.node_image_normalmap, self.node_texcoords.outputs[coords], translation, rotation, scale)
+ self.node_image_normalmap, self.node_texcoords.outputs[coords], translation, rotation, scale, clamp)
def bump_factor_set(self, value):
node = self.node_mix_color_bump
@@ -464,9 +484,9 @@
self._image_create_helper(image, node, (node.inputs["Color2"],)))
def bump_mapping_set(self, coords='UV',
- translation=None, rotation=None, scale=None):
+ translation=None, rotation=None, scale=None, clamp=None):
return self._mapping_create_helper(
- self.node_image_bump, self.node_texcoords.outputs[coords], translation, rotation, scale)
+ self.node_image_bump, self.node_texcoords.outputs[coords], translation, rotation, scale, clamp)
def mapping_set_from_diffuse(self,
specular=True,
Modified: trunk/py/scripts/addons/io_scene_fbx/import_fbx.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/import_fbx.py 2013-09-26 07:02:57 UTC (rev 4772)
+++ trunk/py/scripts/addons/io_scene_fbx/import_fbx.py 2013-09-26 08:24:24 UTC (rev 4773)
@@ -1181,7 +1181,8 @@
return (elem_props_get_vector_3d(fbx_props, b'Translation', (0.0, 0.0, 0.0)),
elem_props_get_vector_3d(fbx_props, b'Rotation', (0.0, 0.0, 0.0)),
elem_props_get_vector_3d(fbx_props, b'Scaling', (1.0, 1.0, 1.0)),
- )
+ (bool(elem_props_get_enum(fbx_props, b'WrapModeU', 0)),
+ bool(elem_props_get_enum(fbx_props, b'WrapModeV', 0))))
if not use_cycles:
# Simple function to make a new mtex and set defaults
@@ -1218,7 +1219,8 @@
tex_map = texture_mapping_get(fbx_lnk)
if (tex_map[0] == (0.0, 0.0, 0.0) and
tex_map[1] == (0.0, 0.0, 0.0) and
- tex_map[2] == (1.0, 1.0, 1.0)):
+ tex_map[2] == (1.0, 1.0, 1.0) and
+ tex_map[3] == (False, False)):
use_mapping = False
else:
@@ -1227,6 +1229,7 @@
"translation": tex_map[0],
"rotation": [-i for i in tex_map[1]],
"scale": [((1.0 / i) if i != 0.0 else 1.0) for i in tex_map[2]],
+ "clamp": tex_map[3],
}
if lnk_type == b'DiffuseColor':
More information about the Bf-extensions-cvs
mailing list