[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4721] contrib/py/scripts/addons/ io_scene_fpx: started to implement curve to mesh conversion + UVMap
Alexander N.
alpha-beta-release at gmx.net
Sun Sep 1 23:43:00 CEST 2013
Revision: 4721
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4721
Author: beta-tester
Date: 2013-09-01 21:42:59 +0000 (Sun, 01 Sep 2013)
Log Message:
-----------
started to implement curve to mesh conversion + UVMap
Modified Paths:
--------------
contrib/py/scripts/addons/io_scene_fpx/__init__.py
contrib/py/scripts/addons/io_scene_fpx/fpx_import.py
contrib/py/scripts/addons/io_scene_fpx/fpx_ui.py
contrib/py/scripts/addons/io_scene_fpx/fpx_utils.py
Modified: contrib/py/scripts/addons/io_scene_fpx/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_scene_fpx/__init__.py 2013-09-01 03:32:21 UTC (rev 4720)
+++ contrib/py/scripts/addons/io_scene_fpx/__init__.py 2013-09-01 21:42:59 UTC (rev 4721)
@@ -34,7 +34,7 @@
'name': "Future Pinball FPx format (.fpm/.fpl/.fpt)",
'description': "Import Future Pinball Model, Library and Table files",
'author': "Alexander Nussbaumer",
- 'version': (0, 0, 0, '2013-08-31'),
+ 'version': (0, 0, 0, '2013-09-01'),
'blender': (2, 68, 0),
'location': "File > Import",
'warning': "",
Modified: contrib/py/scripts/addons/io_scene_fpx/fpx_import.py
===================================================================
--- contrib/py/scripts/addons/io_scene_fpx/fpx_import.py 2013-09-01 03:32:21 UTC (rev 4720)
+++ contrib/py/scripts/addons/io_scene_fpx/fpx_import.py 2013-09-01 21:42:59 UTC (rev 4721)
@@ -948,10 +948,12 @@
self.append_texture_material(child, fpx_image_name, light_on, uv_layer)
return
+ print("#DEBUG append_texture_material *:", fpx_image_name)
fpx_image_object = self.fpx_images.get(fpx_image_name)
if not fpx_image_object:
fpx_image_name = FpxUtilities.toGoodName(fpx_image_name)
fpx_image_object = self.fpx_images.get(fpx_image_name)
+ print("#DEBUG append_texture_material **:", fpx_image_name)
if fpx_image_object:
blender_image = self.__blend_data.images.get(fpx_image_object[self.BLENDER_OBJECT_NAME])
if blender_image:
@@ -1164,6 +1166,67 @@
if not blender_object.data.materials.get(bm_name):
blender_object.data.materials.append(blender_material)
+ def apply_uv_map_from_texspace(self, blender_object, fpx_image_name):
+ box_x = blender_object.bound_box[0][0]
+ box_y = blender_object.bound_box[0][1]
+ tex_size_width = blender_object.data.texspace_size[0] * 2.0
+ tex_size_length = blender_object.data.texspace_size[1] * 2.0
+ tex_loc_x = blender_object.data.texspace_location[0]
+ tex_loc_y = blender_object.data.texspace_location[1]
+
+ offset_x = tex_size_width - 2.0 * (tex_loc_x - box_x)
+ offset_y = tex_size_length - 2.0 * (tex_loc_y - box_y)
+
+ blender_object.select = True
+ self.__context.scene.objects.active = blender_object
+ self.__context.scene.update()
+ if ops.object.convert.poll():
+ ops.object.convert()
+ else:
+ if ops.object.mode_set.poll():
+ ops.object.mode_set(mode='OBJECT')
+ print("#DEBUG ops.object.mode_set(mode='OBJECT')")
+ if ops.object.convert.poll():
+ ops.object.convert()
+ print("#DEBUG ops.object.convert()")
+
+ mesh = blender_object.data
+
+ bm = bmesh.new()
+ bm.from_mesh(mesh)
+
+ uv_layer = bm.loops.layers.uv.new("UVMap")
+ tex_layer = bm.faces.layers.tex.new(uv_layer.name)
+
+ blender_image = None
+ if fpx_image_name:
+ print("#DEBUG fpx_image_name *:", fpx_image_name)
+ fpx_image_object = self.fpx_images.get(fpx_image_name)
+ if not fpx_image_object:
+ fpx_image_name = FpxUtilities.toGoodName(fpx_image_name)
+ fpx_image_object = self.fpx_images.get(fpx_image_name)
+ print("#DEBUG fpx_image_name **:", fpx_image_name)
+ if fpx_image_object:
+ blender_image = self.__blend_data.images.get(fpx_image_object[self.BLENDER_OBJECT_NAME])
+ else:
+ print("#DEBUG fpx_image_name ***:", fpx_image_name, "not found")
+
+ for bmf in bm.faces:
+ for ivert, bmv in enumerate(bmf.verts):
+ u = ((0.5 * offset_x + (bmv.co[0] - box_x)) / tex_size_width)
+ v = ((0.5 * offset_y + (bmv.co[1] - box_y)) / tex_size_length)
+ while u < 0:
+ u += 1
+ while v < 0:
+ v += 1
+ bmf.loops[ivert][uv_layer].uv = (u, v)
+
+ if blender_image:
+ bmf[tex_layer].image = blender_image
+
+ bm.to_mesh(mesh)
+ bm.free()
+
def append_light_material(self, blender_object, color=(0.9, 0.9, 0.8, 1.0)):
if not blender_object:
return
@@ -1396,11 +1459,6 @@
self.create_curve_points(act_spline, fpx_points)
obj.location = Vector((obj.location.x, obj.location.y, (top - cu.extrude)))
- if texture and not sphere_map_the_top:
- self.append_texture_material(obj, texture)
- elif transparency:
- self.append_christal_material(obj)
-
if cookie_cut:
cu.use_auto_texspace = False
cu.texspace_location = Vector((self.__table_width / 2.0, self.__table_length / 2.0, 0))
@@ -1411,6 +1469,17 @@
cu.texspace_location = Vector(obj.bound_box[0]) + (obj.dimensions / 2.0)
cu.texspace_size = Vector(obj.dimensions / 2.0)
+ if self.convert_to_mesh:
+ self.apply_uv_map_from_texspace(obj, texture)
+
+ if texture and not sphere_map_the_top:
+ if self.convert_to_mesh:
+ self.append_texture_material(obj, texture, uv_layer='UVMap')
+ else:
+ self.append_texture_material(obj, texture)
+ elif transparency:
+ self.append_christal_material(obj)
+
return obj
def CreateRubberShapeable(self, fpx_item, name, layers, fpx_points, surface):
@@ -1572,8 +1641,6 @@
obj.location = Vector((obj.location.x, obj.location.y, (surface + cu.extrude)))
- if texture and not sphere_map_the_top:
- self.append_texture_material(obj, texture)
if cookie_cut:
cu.use_auto_texspace = False
cu.texspace_location = Vector((self.__table_width / 2.0, self.__table_length / 2.0, 0))
@@ -1584,6 +1651,15 @@
cu.texspace_location = Vector(obj.bound_box[0]) + (obj.dimensions / 2.0)
cu.texspace_size = Vector(obj.dimensions / 2.0)
+ if self.convert_to_mesh:
+ self.apply_uv_map_from_texspace(obj, texture)
+
+ if texture and not sphere_map_the_top:
+ if self.convert_to_mesh:
+ self.append_texture_material(obj, texture, uv_layer='UVMap')
+ else:
+ self.append_texture_material(obj, texture)
+
return obj
def CreateLightRound(self, fpx_item, name, layers, position_xy, surface):
@@ -1619,7 +1695,6 @@
obj.location = Vector((obj.location.x, obj.location.y, surface))
if texture:
- self.append_texture_material(obj, texture, light_on=True)
if cookie_cut:
cu.use_auto_texspace = False
cu.texspace_location = Vector((self.__table_width / 2.0, self.__table_length / 2.0, 0))
@@ -1638,6 +1713,15 @@
size = max(obj.dimensions)
cu.texspace_size = (size, size, 0)
+ if self.convert_to_mesh:
+ self.apply_uv_map_from_texspace(obj, texture)
+
+ if texture and not sphere_map_the_top:
+ if self.convert_to_mesh:
+ self.append_texture_material(obj, texture, uv_layer='UVMap', light_on=True)
+ else:
+ self.append_texture_material(obj, texture, light_on=True)
+
return obj
def CreateLightShapeable(self, fpx_item, name, layers, fpx_points, surface):
@@ -1657,7 +1741,6 @@
obj.location = Vector((obj.location.x, obj.location.y, surface))
if texture:
- self.append_texture_material(obj, texture, light_on=True)
if cookie_cut:
cu.use_auto_texspace = False
cu.texspace_location = Vector((self.__table_width / 2.0, self.__table_length / 2.0, 0))
@@ -1676,6 +1759,15 @@
size = max(obj.dimensions)
cu.texspace_size = (size, size, 0)
+ if self.convert_to_mesh:
+ self.apply_uv_map_from_texspace(obj, texture)
+
+ if texture and not sphere_map_the_top:
+ if self.convert_to_mesh:
+ self.append_texture_material(obj, texture, uv_layer='UVMap', light_on=True)
+ else:
+ self.append_texture_material(obj, texture, light_on=True)
+
return obj
def CreateLightImage(self, fpx_item, name, layers, position_xy, surface):
Modified: contrib/py/scripts/addons/io_scene_fpx/fpx_ui.py
===================================================================
--- contrib/py/scripts/addons/io_scene_fpx/fpx_ui.py 2013-09-01 03:32:21 UTC (rev 4720)
+++ contrib/py/scripts/addons/io_scene_fpx/fpx_ui.py 2013-09-01 21:42:59 UTC (rev 4721)
@@ -95,7 +95,7 @@
PROP_DEFAULT_RESOLUTION_RUBBER_BEVEL = 8
PROP_DEFAULT_RESOLUTION_RUBBER = 8
PROP_DEFAULT_RESOLUTION_SHAPE = 8
- PROP_DEFAULT_CONVERT_TO_MESH = False
+ PROP_DEFAULT_CONVERT_TO_MESH = True
PROP_DEFAULT_USE_HERMITE_HANDLE = True
###########################################################################
@@ -867,8 +867,8 @@
box = layout.box()
box.label(fpx_str['LABEL_NAME_TABLE_OPTIONS'], icon=FpxUI.ICON_MODEL)
- if self.convert_to_mesh:
- NotImplemented(box)
+ #if self.convert_to_mesh:
+ # NotImplemented(box)
flow = box.column_flow()
flow.prop(self, 'convert_to_mesh', icon='MOD_TRIANGULATE')
flow = box.column_flow()
Modified: contrib/py/scripts/addons/io_scene_fpx/fpx_utils.py
===================================================================
--- contrib/py/scripts/addons/io_scene_fpx/fpx_utils.py 2013-09-01 03:32:21 UTC (rev 4720)
+++ contrib/py/scripts/addons/io_scene_fpx/fpx_utils.py 2013-09-01 21:42:59 UTC (rev 4721)
@@ -38,30 +38,10 @@
class FpxUtilities:
+ ###########################################################################
TAG_NAME = "raw_dump"
- ###########################################################################
@staticmethod
- def toGoodName(s):
- if not s:
- return s
-
- sx = []
- for c in s:
- if (
- (c != '_') and (c != '.') and
- (c != '[') and (c != ']') and
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list