[Bf-extensions-cvs] [1b1ad46] master: Fix T45203: X3D import issues: no support of instancing!!!

Bastien Montagne noreply at git.blender.org
Fri Jun 26 18:44:02 CEST 2015


Commit: 1b1ad4665b852c1c52dcbdb0176cf2eb7f0d88f8
Author: Bastien Montagne
Date:   Fri Jun 26 18:39:23 2015 +0200
Branches: master
https://developer.blender.org/rBA1b1ad4665b852c1c52dcbdb0176cf2eb7f0d88f8

Fix T45203: X3D import issues: no support of instancing!!!

Previously, that script whould create an object (two, actually!), mesh, material etc.
for every 'Shape' node, even when x3d format has intancing capabilities.
That would made importing files with many copies of same object insanely long.

Now we support instances of objects, geometry (aka meshes), materials (aka appearance)
and images, should be enough for now.

Also, fixed some old cruft like still using tessface stuff in a few minor places and such.

===================================================================

M	io_scene_x3d/__init__.py
M	io_scene_x3d/import_x3d.py

===================================================================

diff --git a/io_scene_x3d/__init__.py b/io_scene_x3d/__init__.py
index c43e00a..78851a6 100644
--- a/io_scene_x3d/__init__.py
+++ b/io_scene_x3d/__init__.py
@@ -21,7 +21,7 @@
 bl_info = {
     "name": "Web3D X3D/VRML2 format",
     "author": "Campbell Barton, Bart, Bastien Montagne",
-    "version": (1, 0, 1),
+    "version": (1, 1, 0),
     "blender": (2, 74, 0),
     "location": "File > Import-Export",
     "description": "Import-Export X3D, Import VRML2",
diff --git a/io_scene_x3d/import_x3d.py b/io_scene_x3d/import_x3d.py
index 840f635..aec4f89 100644
--- a/io_scene_x3d/import_x3d.py
+++ b/io_scene_x3d/import_x3d.py
@@ -370,6 +370,7 @@ class vrmlNode(object):
                  'lineno',
                  'filename',
                  'blendObject',
+                 'blendData',
                  'DEF_NAMESPACE',
                  'ROUTE_IPO_NAMESPACE',
                  'PROTO_NAMESPACE',
@@ -380,6 +381,7 @@ class vrmlNode(object):
         self.node_type = node_type
         self.parent = parent
         self.blendObject = None
+        self.blendData = None
         self.x3dNode = None  # for x3d import only
         if parent:
             parent.children.append(self)
@@ -2037,197 +2039,212 @@ def importMesh_Box(geom, ancestry):
 
 
 def importShape(node, ancestry, global_matrix):
-    vrmlname = node.getDefName()
-    if not vrmlname:
-        vrmlname = 'Shape'
-
-    # works 100% in vrml, but not x3d
-    #appr = node.getChildByName('appearance') # , 'Appearance'
-    #geom = node.getChildByName('geometry') # , 'IndexedFaceSet'
-
-    # Works in vrml and x3d
-    appr = node.getChildBySpec('Appearance')
-    geom = node.getChildBySpec(['IndexedFaceSet', 'IndexedLineSet', 'PointSet', 'Sphere', 'Box', 'Cylinder', 'Cone'])
-
-    # For now only import IndexedFaceSet's
-    if geom:
-        bpymat = None
-        bpyima = None
-        texmtx = None
-
-        image_depth = 0  # so we can set alpha face flag later
-        is_vcol = (geom.getChildBySpec('Color') is not None)
-
-        if appr:
-
-            #mat = appr.getChildByName('material') # 'Material'
-            #ima = appr.getChildByName('texture') # , 'ImageTexture'
-            #if ima and ima.getSpec() != 'ImageTexture':
-            #   print('\tWarning: texture type "%s" is not supported' % ima.getSpec())
-            #   ima = None
-            # textx = appr.getChildByName('textureTransform')
-
-            mat = appr.getChildBySpec('Material')
-            ima = appr.getChildBySpec('ImageTexture')
+    def apply_texmtx(blendata, texmtx):
+        for luv in bpydata.uv_layers.active.data:
+            luv.uv = texmtx * luv.uv
 
-            textx = appr.getChildBySpec('TextureTransform')
+    bpyob = node.getRealNode().blendObject
 
-            if textx:
-                texmtx = translateTexTransform(textx, ancestry)
-
-            # print(mat, ima)
-            if mat or ima:
-
-                if not mat:
-                    mat = ima  # This is a bit dumb, but just means we use default values for all
-
-                # all values between 0.0 and 1.0, defaults from VRML docs
-                bpymat = bpy.data.materials.new(vrmlname)
-                bpymat.ambient = mat.getFieldAsFloat('ambientIntensity', 0.2, ancestry)
-                bpymat.diffuse_color = mat.getFieldAsFloatTuple('diffuseColor', [0.8, 0.8, 0.8], ancestry)
-
-                # NOTE - blender dosnt support emmisive color
-                # Store in mirror color and approximate with emit.
-                emit = mat.getFieldAsFloatTuple('emissiveColor', [0.0, 0.0, 0.0], ancestry)
-                bpymat.mirror_color = emit
-                bpymat.emit = (emit[0] + emit[1] + emit[2]) / 3.0
+    if bpyob is not None:
+        bpyob = node.blendData = node.blendObject = bpyob.copy()
+        bpy.context.scene.objects.link(bpyob).select = True
+    else:
+        vrmlname = node.getDefName()
+        if not vrmlname:
+            vrmlname = 'Shape'
+
+        # works 100% in vrml, but not x3d
+        #appr = node.getChildByName('appearance') # , 'Appearance'
+        #geom = node.getChildByName('geometry') # , 'IndexedFaceSet'
+
+        # Works in vrml and x3d
+        appr = node.getChildBySpec('Appearance')
+        geom = node.getChildBySpec(['IndexedFaceSet', 'IndexedLineSet', 'PointSet', 'Sphere', 'Box', 'Cylinder', 'Cone'])
+
+        # For now only import IndexedFaceSet's
+        if geom:
+            bpymat = None
+            bpyima = None
+            texmtx = None
+
+            image_depth = 0  # so we can set alpha face flag later
+            is_vcol = (geom.getChildBySpec('Color') is not None)
+
+            if appr:
+                #mat = appr.getChildByName('material') # 'Material'
+                #ima = appr.getChildByName('texture') # , 'ImageTexture'
+                #if ima and ima.getSpec() != 'ImageTexture':
+                #   print('\tWarning: texture type "%s" is not supported' % ima.getSpec())
+                #   ima = None
+                # textx = appr.getChildByName('textureTransform')
+
+                mat = appr.getChildBySpec('Material')
+                ima = appr.getChildBySpec('ImageTexture')
+
+                textx = appr.getChildBySpec('TextureTransform')
+
+                if textx:
+                    texmtx = translateTexTransform(textx, ancestry)
+
+                bpymat = appr.getRealNode().blendData
+
+                if bpymat is None:
+                    # print(mat, ima)
+                    if mat or ima:
+                        if not mat:
+                            mat = ima  # This is a bit dumb, but just means we use default values for all
+
+                        # all values between 0.0 and 1.0, defaults from VRML docs
+                        bpymat = bpy.data.materials.new(vrmlname)
+                        bpymat.ambient = mat.getFieldAsFloat('ambientIntensity', 0.2, ancestry)
+                        bpymat.diffuse_color = mat.getFieldAsFloatTuple('diffuseColor', [0.8, 0.8, 0.8], ancestry)
+
+                        # NOTE - blender dosnt support emmisive color
+                        # Store in mirror color and approximate with emit.
+                        emit = mat.getFieldAsFloatTuple('emissiveColor', [0.0, 0.0, 0.0], ancestry)
+                        bpymat.mirror_color = emit
+                        bpymat.emit = (emit[0] + emit[1] + emit[2]) / 3.0
+
+                        bpymat.specular_hardness = int(1 + (510 * mat.getFieldAsFloat('shininess', 0.2, ancestry)))  # 0-1 -> 1-511
+                        bpymat.specular_color = mat.getFieldAsFloatTuple('specularColor', [0.0, 0.0, 0.0], ancestry)
+                        bpymat.alpha = 1.0 - mat.getFieldAsFloat('transparency', 0.0, ancestry)
+                        if bpymat.alpha < 0.999:
+                            bpymat.use_transparency = True
+                        if is_vcol:
+                            bpymat.use_vertex_color_paint = True
 
-                bpymat.specular_hardness = int(1 + (510 * mat.getFieldAsFloat('shininess', 0.2, ancestry)))  # 0-1 -> 1-511
-                bpymat.specular_color = mat.getFieldAsFloatTuple('specularColor', [0.0, 0.0, 0.0], ancestry)
-                bpymat.alpha = 1.0 - mat.getFieldAsFloat('transparency', 0.0, ancestry)
-                if bpymat.alpha < 0.999:
-                    bpymat.use_transparency = True
-                if is_vcol:
-                    bpymat.use_vertex_color_paint = True
+                    if ima:
+                        bpyima = ima.getRealNode().blendData
 
-            if ima:
-                ima_urls = ima.getFieldAsString('url', None, ancestry)
+                        if bpyima is None:
+                            ima_urls = ima.getFieldAsString('url', None, ancestry)
 
-                if ima_urls is None:
-                    try:
-                        ima_urls = ima.getFieldAsStringArray('url', ancestry)  # in some cases we get a list of images.
-                    except:
-                        ima_urls = None
-                else:
-                    if '" "' in ima_urls:
-                        # '"foo" "bar"' --> ['foo', 'bar']
-                        ima_urls = [w.strip('"') for w in ima_urls.split('" "')]
-                    else:
-                        ima_urls = [ima_urls]
-                # ima_urls is a list or None
-
-                if ima_urls is None:
-                    print("\twarning, image with no URL, this is odd")
+                            if ima_urls is None:
+                                try:
+                                    ima_urls = ima.getFieldAsStringArray('url', ancestry)  # in some cases we get a list of images.
+                                except:
+                                    ima_urls = None
+                            else:
+                                if '" "' in ima_urls:
+                                    # '"foo" "bar"' --> ['foo', 'bar']
+                                    ima_urls = [w.strip('"') for w in ima_urls.split('" "')]
+                                else:
+                                    ima_urls = [ima_urls]
+                            # ima_urls is a list or None
+
+                            if ima_urls is None:
+                                print("\twarning, image with no URL, this is odd")
+                            else:
+                                for f in ima_urls:
+                                    bpyima = image_utils.load_image(f, os.path.dirname(node.getFilename()), place_holder=False,
+                                                                    recursive=False, convert_callback=imageConvertCompat)
+                                    if bpyima:
+                                        break
+
+                                if bpyima:
+                                    texture = bpy.data.textures.new(bpyima.name, 'IMAGE')
+                                    texture.image = bpyima
+
+                                    # Adds textures for materials (rendering)
+                                    try:
+                                        image_depth = bpyima.depth
+                                    except:
+                          

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list