Revision: 15274
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15274
Author:   bdiego
Date:     2008-06-18 22:18:37 +0200 (Wed, 18 Jun 2008)

Log Message:
-----------
branches/blender-2.47

Merge from trunk:
        Revision: 15239
        Revision: 15240
        Revision: 15242
        Revision: 15247
        Revision: 15256
        Revision: 15262

Modified Paths:
--------------
    branches/blender-2.47/release/scripts/ms3d_import.py
    branches/blender-2.47/source/blender/imbuf/intern/cineon/dpxlib.c
    branches/blender-2.47/source/blender/src/transform_constraints.c
    
branches/blender-2.47/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
    branches/blender-2.47/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
    branches/blender-2.47/source/gameengine/Converter/BL_ActionActuator.cpp
    branches/blender-2.47/source/gameengine/Ketsji/KX_GameObject.h
    branches/blender-2.47/source/gameengine/Ketsji/KX_IpoActuator.cpp
    branches/blender-2.47/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    branches/blender-2.47/source/gameengine/Ketsji/KX_KetsjiEngine.h
    branches/blender-2.47/source/gameengine/Ketsji/KX_RayCast.cpp

Modified: branches/blender-2.47/release/scripts/ms3d_import.py
===================================================================
--- branches/blender-2.47/release/scripts/ms3d_import.py        2008-06-18 
19:58:05 UTC (rev 15273)
+++ branches/blender-2.47/release/scripts/ms3d_import.py        2008-06-18 
20:18:37 UTC (rev 15274)
@@ -43,28 +43,28 @@
 
 
 # Converts ms3d euler angles to a rotation matrix
-def RM(a):
-       sy = sin(a[2])
-       cy = cos(a[2])
-       sp = sin(a[1])
-       cp = cos(a[1])
-       sr = sin(a[0])
+def RM(a):
+       sy = sin(a[2])
+       cy = cos(a[2])
+       sp = sin(a[1])
+       cp = cos(a[1])
+       sr = sin(a[0])
        cr = cos(a[0])
-       return Matrix([cp*cy, sr*sp*cy+cr*-sy, cr*sp*cy+-sr*-sy],[cp*sy, 
sr*sp*sy+cr*cy, cr*sp*sy+-sr*cy], [-sp, sr*cp, cr*cp])
+       return Matrix([cp*cy, cp*sy, -sp], [sr*sp*cy+cr*-sy, sr*sp*sy+cr*cy, 
sr*cp],[cr*sp*cy+-sr*-sy, cr*sp*sy+-sr*cy, cr*cp])
 
 
 # Converts ms3d euler angles to a quaternion
-def RQ(a):
-       angle = a[2] * 0.5;
-       sy = sin(angle);
-       cy = cos(angle);
-       angle = a[1] * 0.5;
-       sp = sin(angle);
-       cp = cos(angle);
-       angle = a[0] * 0.5;
-       sr = sin(angle);
-       cr = cos(angle);
-       return Quaternion(cr*cp*cy+sr*sp*sy, sr*cp*cy-cr*sp*sy, 
cr*sp*cy+sr*cp*sy, cr*cp*sy-sr*sp*cy)
+def RQ(a):
+       angle = a[2] * 0.5;
+       sy = sin(angle);
+       cy = cos(angle);
+       angle = a[1] * 0.5;
+       sp = sin(angle);
+       cp = cos(angle);
+       angle = a[0] * 0.5;
+       sr = sin(angle);
+       cr = cos(angle);
+       return Quaternion(cr*cp*cy+sr*sp*sy, sr*cp*cy-cr*sp*sy, 
cr*sp*cy+sr*cp*sy, cr*cp*sy-sr*sp*cy)
 
 
 # takes a texture filename and tries to load it
@@ -94,15 +94,20 @@
        except IOError:
                return "Failed to open the file!"
 
-       # read id
+       # get the file size
+       file.seek(0, os.SEEK_END);
+       fileSize = file.tell();
+       file.seek(0, os.SEEK_SET);
+
+       # read id to check if the file is a MilkShape3D file
        id = file.read(10)
        if id!="MS3D000000":
-               return "The file is not a MS3D file!"
+               return "The file is not a MS3D file!"
 
        # read version
        version = struct.unpack("i", file.read(4))[0]
        if version!=4:
-               return "The file has invalid version!"
+               return "The file has invalid version!"
 
        # Create the mesh
        scn.objects.selected = []
@@ -118,20 +123,20 @@
        for i in xrange(numVertices):
                # skip flags
                file.read(1)
-
+
                # read coords
                coords.append(struct.unpack("fff", file.read(3*4)))
 
                # read bone ids 
-               boneIds.append(struct.unpack("B", file.read(1))[0])
-
+               boneIds.append(struct.unpack("b", file.read(1))[0])
+
                # skip refcount         
                file.read(1)
 
        # add the vertices to the mesh
        mesh.verts.extend(coords)
 
-       # read number of triangles
+       # read number of triangles
        numTriangles = struct.unpack("H", file.read(2))[0]
        
        # read triangles
@@ -141,10 +146,10 @@
                # skip flags
                file.read(2)
 
-               # read indices (faces)
+               # read indices (faces)
                faces.append(struct.unpack("HHH", file.read(3*2)))
 
-               # read normals
+               # read normals
                normals = struct.unpack("fffffffff", file.read(3*3*4))
 
                # read texture coordinates
@@ -171,35 +176,36 @@
        for i in xrange(numTriangles):
                mesh.faces[i].uv = [Vector(uvs[i][0]), Vector(uvs[i][1]), 
Vector(uvs[i][2])]
 
-       # read number of groups
+       # read number of groups
        numGroups = struct.unpack("H", file.read(2))[0]
 
        # read groups
        for i in xrange(numGroups):
-               # skip flags
+               # skip flags
                file.read(1)
 
                # skip name
                file.read(32)
 
-               # read the number of triangles in the group
+               # read the number of triangles in the group
                numGroupTriangles = struct.unpack("H", file.read(2))[0]
-
+
                # read the group triangles
-               if numGroupTriangles > 0:
+               if numGroupTriangles > 0:
                        triangleIndices = struct.unpack(str(numGroupTriangles) 
+ "H", file.read(2*numGroupTriangles));
-
+
                # read material
-               material = struct.unpack("B", file.read(1))[0]
-               for j in xrange(numGroupTriangles):
-                       mesh.faces[triangleIndices[j]].mat = material
+               material = struct.unpack("b", file.read(1))[0]
+               if material>=0:
+                       for j in xrange(numGroupTriangles):
+                               mesh.faces[triangleIndices[j]].mat = material
 
-       # read the number of materials
-       numMaterials = struct.unpack("H", file.read(2))[0]
+       # read the number of materials
+       numMaterials = struct.unpack("H", file.read(2))[0]
 
        # read materials
        for i in xrange(numMaterials):
-               # read name
+               # read name
                name = uku(file.read(32))
 
                # create the material
@@ -210,7 +216,7 @@
                ambient = struct.unpack("ffff", file.read(4*4))[0:3]
                mat.setAmb((ambient[0]+ambient[1]+ambient[2])/3)
 
-               # read diffuse color
+               # read diffuse color
                diffuse = struct.unpack("ffff", file.read(4*4))[0:3]
                mat.setRGBCol(diffuse)
 
@@ -224,7 +230,6 @@
 
                # read shininess
                shininess = struct.unpack("f", file.read(4))[0]
-               print "Shininess: " + str(shininess)
 
                # read transparency             
                transparency = struct.unpack("f", file.read(4))[0]
@@ -235,7 +240,7 @@
                # read mode
                mode = struct.unpack("B", file.read(1))[0]
 
-               # read texturemap
+               # read texturemap
                texturemap = uku(file.read(128))
                if len(texturemap)>0:
                        colorTexture = Blender.Texture.New(name + "_texture")
@@ -243,7 +248,7 @@
                        colorTexture.setImage(loadImage(path, texturemap))
                        mat.setTexture(0, colorTexture, 
Blender.Texture.TexCo.UV, Blender.Texture.MapTo.COL)
 
-               # read alphamap
+               # read alphamap
                alphamap = uku(file.read(128))
                if len(alphamap)>0:
                        alphaTexture = Blender.Texture.New(name + "_alpha")
@@ -251,12 +256,12 @@
                        alphaTexture.setImage(loadImage(path, alphamap))
                        mat.setTexture(1, alphaTexture, 
Blender.Texture.TexCo.UV, Blender.Texture.MapTo.ALPHA)          
 
-       # read animation
-       fps = struct.unpack("f", file.read(4))[0]
-       time = struct.unpack("f", file.read(4))[0]
-       frames = struct.unpack("i", file.read(4))[0]
-
-       # read the number of joints
+       # read animation
+       fps = struct.unpack("f", file.read(4))[0]
+       time = struct.unpack("f", file.read(4))[0]
+       frames = struct.unpack("i", file.read(4))[0]
+
+       # read the number of joints
        numJoints = struct.unpack("H", file.read(2))[0]
 
        # create the armature
@@ -272,20 +277,22 @@
                armature.makeEditable()
 
        # read joints
+       joints = []
        rotKeys = {}
-       posKeys = {}
+       posKeys = {}
        for i in xrange(numJoints):
                # skip flags
                file.read(1)
 
-               # read name
+               # read name
                name = uku(file.read(32))
+               joints.append(name)
 
                # create the bone
                bone = Blender.Armature.Editbone()
                armature.bones[name] = bone
 
-               # read parent
+               # read parent
                parent = uku(file.read(32))
                if len(parent)>0:
                        bone.parent = armature.bones[parent]
@@ -295,11 +302,13 @@
 
                # read position
                pos = struct.unpack("fff", file.read(3*4))
-
+               
                # set head
                if bone.hasParent():
-                       bone.head = bone.parent.matrix * Vector(pos) + 
bone.parent.head
-                       bone.matrix = bone.parent.matrix * RM(rot)
+                       bone.head =  Vector(pos) * bone.parent.matrix + 
bone.parent.head
+                       tempM = RM(rot) * bone.parent.matrix
+                       tempM.transpose;
+                       bone.matrix = tempM
                else:
                        bone.head = Vector(pos)
                        bone.matrix = RM(rot)
@@ -317,24 +326,24 @@
                                vgroup.append(index)
                mesh.assignVertsToGroup(name, vgroup, 1.0, 1)
        
-               # read the number of rotation keys
-               numKeyFramesRot = struct.unpack("H", file.read(2))[0]
-                       
-               # read the number of postions keys
-               numKeyFramesPos = struct.unpack("H", file.read(2))[0]
-
-               # read rotation keys
+               # read the number of rotation keys
+               numKeyFramesRot = struct.unpack("H", file.read(2))[0]
+                       
+               # read the number of postions keys
+               numKeyFramesPos = struct.unpack("H", file.read(2))[0]
+
+               # read rotation keys
                rotKeys[name] = []              
                for j in xrange(numKeyFramesRot):
                        # read time
                        time = fps * struct.unpack("f", file.read(4))[0]
                        # read data
                        rotKeys[name].append([time, struct.unpack("fff", 
file.read(3*4))])
-
-               # read position keys
+
+               # read position keys
                posKeys[name] = []
                for j in xrange(numKeyFramesPos):
-                       # read time
+                       # read time
                        time = fps * struct.unpack("f", file.read(4))[0]
                        # read data
                        posKeys[name].append([time, struct.unpack("fff", 
file.read(3*4))])
@@ -352,16 +361,114 @@
 
        # create animation key frames
        for name, pbone in pose.bones.items():
-               # create position keys
-               for key in posKeys[name]:
+               # create position keys
+               for key in posKeys[name]:
                        pbone.loc = Vector(key[1])
-                       pbone.insertKey(armOb, int(key[0]), 
Blender.Object.Pose.LOC, True)
+                       pbone.insertKey(armOb, int(key[0]+0.5), 
Blender.Object.Pose.LOC, True)
 
-               # create rotation keys
-               for key in rotKeys[name]:
+               # create rotation keys
+               for key in rotKeys[name]:
                        pbone.quat = RQ(key[1])
-                       pbone.insertKey(armOb, int(key[0]), 
Blender.Object.Pose.ROT, True)
+                       pbone.insertKey(armOb, int(key[0]+0.5), 
Blender.Object.Pose.ROT, True)
+
+       # The old format ends here. If there is more data then the file is 
newer version
+
+       # check to see if there are any comments
+       if file.tell()<fileSize:
+
+               # read sub version
+               subVersion = struct.unpack("i", file.read(4))[0]
+
+               # Is the sub version a supported one
+               if subVersion==1:
+
+                       # Group comments
+                       numComments = struct.unpack("i", file.read(4))[0]
+                       for i in range(numComments):
+                               file.read(4) # index
+                               size = struct.unpack("i", file.read(4))[0] # 
comment size
+                               if size>0:
+                                       print "Group comment: " + 
file.read(size)
+
+                       # Material comments
+                       numComments = struct.unpack("i", file.read(4))[0]
+                       for i in range(numComments):
+                               file.read(4) # index
+                               size = struct.unpack("i", file.read(4))[0] # 
comment size
+                               if size>0:
+                                       print "Material comment: " + 
file.read(size)
+
+                       # Joint comments
+                       numComments = struct.unpack("i", file.read(4))[0]
+                       for i in range(numComments):
+                               file.read(4) # index
+                               size = struct.unpack("i", file.read(4))[0] # 
comment size
+                               if size>0:
+                                       print "Joint comment: " + 
file.read(size)
+
+                       # Model comments
+                       numComments = struct.unpack("i", file.read(4))[0]
+                       for i in range(numComments):
+                               file.read(4) # index
+                               size = struct.unpack("i", file.read(4))[0] # 
comment size
+                               if size>0:
+                                       print "Model comment: " + 
file.read(size)
+
+               # Unknown version give a warning
+               else:
+                       print "Warning: Unknown version!"
+
+               
+       # check to see if there is any extra vertex data
+       if file.tell()<fileSize:
+               
+               # read the subversion
+               subVersion = struct.unpack("i", file.read(4))[0]
+
+               # is the version supported
+               if subVersion==2:
+                       # read the extra data for each vertex
+                       for i in xrange(numVertices):
+                               # bone ids
+                               ids = struct.unpack("bbb", file.read(3))
+                               # weights
+                               weights = struct.unpack("BBB", file.read(3))
+                               # extra
+                               extra = struct.unpack("I", file.read(4))
+                               # add extra vertices with weights to deform 
groups

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to