diff options
-rw-r--r-- | release/scripts/ms3d_import.py | 132 | ||||
-rw-r--r-- | source/blender/imbuf/intern/cineon/dpxlib.c | 45 | ||||
-rw-r--r-- | source/blender/src/transform_constraints.c | 16 | ||||
-rw-r--r-- | source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp | 6 | ||||
-rw-r--r-- | source/gameengine/BlenderRoutines/KX_BlenderGL.cpp | 7 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_ActionActuator.cpp | 8 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 3 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_IpoActuator.cpp | 6 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 13 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.h | 10 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_RayCast.cpp | 2 |
11 files changed, 218 insertions, 30 deletions
diff --git a/release/scripts/ms3d_import.py b/release/scripts/ms3d_import.py index 78ffbb92847..c1438cbfc97 100644 --- a/release/scripts/ms3d_import.py +++ b/release/scripts/ms3d_import.py @@ -50,7 +50,7 @@ def RM(a): 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 @@ -94,7 +94,12 @@ def import_ms3d(path): 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!" @@ -123,7 +128,7 @@ def import_ms3d(path): 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) @@ -190,9 +195,10 @@ def import_ms3d(path): 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] @@ -224,7 +230,6 @@ def import_ms3d(path): # read shininess shininess = struct.unpack("f", file.read(4))[0] - print "Shininess: " + str(shininess) # read transparency transparency = struct.unpack("f", file.read(4))[0] @@ -272,6 +277,7 @@ def import_ms3d(path): armature.makeEditable() # read joints + joints = [] rotKeys = {} posKeys = {} for i in xrange(numJoints): @@ -280,6 +286,7 @@ def import_ms3d(path): # read name name = uku(file.read(32)) + joints.append(name) # create the bone bone = Blender.Armature.Editbone() @@ -295,11 +302,13 @@ def import_ms3d(path): # 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) @@ -355,13 +364,111 @@ def import_ms3d(path): # 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]: 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 + if ids[0]>=0 or ids[1]>=0 or ids[2]>=0: + mesh.assignVertsToGroup(joints[boneIds[i]], [i], 0.01*weights[0], 1) + if ids[0]>=0: + mesh.assignVertsToGroup(joints[ids[0]], [i], 0.01*weights[1], 1) + if ids[1]>=0: + mesh.assignVertsToGroup(joints[ids[1]], [i], 0.01*weights[2], 1) + if ids[2]>=0: + mesh.assignVertsToGroup(joints[ids[2]], [i], 0.01*(100-(weights[0]+weights[1]+weights[2])), 1) + + elif subVersion==1: + # read 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)) + # add extra vertices with weights to deform groups + if ids[0]>=0 or ids[1]>=0 or ids[2]>=0: + mesh.assignVertsToGroup(joints[boneIds[i]], [i], 0.01*weights[0], 1) + if ids[0]>=0: + mesh.assignVertsToGroup(joints[ids[0]], [i], 0.01*weights[1], 1) + if ids[1]>=0: + mesh.assignVertsToGroup(joints[ids[1]], [i], 0.01*weights[2], 1) + if ids[2]>=0: + mesh.assignVertsToGroup(joints[ids[2]], [i], 0.01*(100-(weights[0]+weights[1]+weights[2])), 1) + + # non supported subversion give a warning + else: + print "Warning: Unknown subversion!" + # rest of the extra data in the file is not imported/used + + # refresh the view Blender.Redraw() # close the file @@ -378,4 +485,3 @@ def fileCallback(filename): Blender.Draw.PupMenu("An error occured during import: " + error + "|Not all data might have been imported succesfully.", 2) Blender.Window.FileSelector(fileCallback, 'Import') - diff --git a/source/blender/imbuf/intern/cineon/dpxlib.c b/source/blender/imbuf/intern/cineon/dpxlib.c index a81e632a797..500c09ba265 100644 --- a/source/blender/imbuf/intern/cineon/dpxlib.c +++ b/source/blender/imbuf/intern/cineon/dpxlib.c @@ -441,10 +441,15 @@ intern_dpxOpen(int mode, const char* bytestuff, int bufsize) { default: break; } } - dpx->bitsPerPixel = 10; - /* dpx->bitsPerPixel = header.imageInfo.channel[0].bits_per_pixel; */ - dpx->imageOffset = ntohl(header.fileInfo.offset); + /* dpx->bitsPerPixel = 10; */ + dpx->bitsPerPixel = header.imageInfo.channel[0].bits_per_pixel; + if (dpx->bitsPerPixel != 10) { + if (verbose) d_printf("Don't support depth: %d\n", dpx->bitsPerPixel); + dpxClose(dpx); + return 0; + } + dpx->imageOffset = ntohl(header.fileInfo.offset); dpx->lineBufferLength = pixelsToLongs(dpx->width * dpx->depth); dpx->lineBuffer = malloc(dpx->lineBufferLength * 4); if (dpx->lineBuffer == 0) { @@ -471,6 +476,26 @@ intern_dpxOpen(int mode, const char* bytestuff, int bufsize) { dpx->fileYPos = 0; logImageGetByteConversionDefaults(&dpx->params); + /* The SMPTE define this code: + * 2 - Linear + * 3 - Logarithmic + * + * Note that transfer_characteristics is U8, don't need + * check the byte order. + */ + switch (header.imageInfo.channel[0].transfer_characteristics) { + case 2: + dpx->params.doLogarithm= 0; + break; + case 3: + dpx->params.doLogarithm= 1; + break; + default: + if (verbose) d_printf("Un-supported Transfer Characteristics: %d\n", header.imageInfo.channel[0].transfer_characteristics); + dpxClose(dpx); + return 0; + break; + } setupLut(dpx); dpx->getRow = &dpxGetRowBytes; @@ -563,6 +588,18 @@ dpxCreate(const char* filename, int width, int height, int depth) { ++shortFilename; } initDpxMainHeader(dpx, &header, shortFilename); + logImageGetByteConversionDefaults(&dpx->params); + /* Need set the file type before write the header! + * 2 - Linear + * 3 - Logarithmic + * + * Note that transfer characteristics is U8, don't need + * check the byte order. + */ + if (dpx->params.doLogarithm == 0) + header.imageInfo.channel[0].transfer_characteristics= 2; + else + header.imageInfo.channel[0].transfer_characteristics= 3; if (fwrite(&header, sizeof(header), 1, dpx->file) == 0) { if (verbose) d_printf("Couldn't write image header\n"); @@ -570,8 +607,6 @@ dpxCreate(const char* filename, int width, int height, int depth) { return 0; } dpx->fileYPos = 0; - - logImageGetByteConversionDefaults(&dpx->params); setupLut(dpx); dpx->getRow = 0; diff --git a/source/blender/src/transform_constraints.c b/source/blender/src/transform_constraints.c index 769ebd2ea97..2d01c2303fc 100644 --- a/source/blender/src/transform_constraints.c +++ b/source/blender/src/transform_constraints.c @@ -550,6 +550,10 @@ void setUserConstraint(TransInfo *t, int mode, const char ftext[]) { void BIF_setLocalLockConstraint(char axis, char *text) { TransInfo *t = BIF_GetTransInfo(); + if (t->total == 0) { + return; + } + switch (axis) { case 'x': setLocalConstraint(t, (CON_AXIS1|CON_AXIS2), text); @@ -566,6 +570,10 @@ void BIF_setLocalLockConstraint(char axis, char *text) { void BIF_setLocalAxisConstraint(char axis, char *text) { TransInfo *t = BIF_GetTransInfo(); + if (t->total == 0) { + return; + } + switch (axis) { case 'X': setLocalConstraint(t, CON_AXIS0, text); @@ -584,6 +592,10 @@ void BIF_setSingleAxisConstraint(float vec[3], char *text) { TransInfo *t = BIF_GetTransInfo(); float space[3][3], v[3]; + if (t->total == 0) { + return; + } + VECCOPY(space[0], vec); v[0] = vec[2]; @@ -622,6 +634,10 @@ void BIF_setDualAxisConstraint(float vec1[3], float vec2[3], char *text) { TransInfo *t = BIF_GetTransInfo(); float space[3][3]; + if (t->total == 0) { + return; + } + VECCOPY(space[0], vec1); VECCOPY(space[1], vec2); Crossf(space[2], space[0], space[1]); diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index fa8409b123e..eb575c70ad7 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -372,6 +372,12 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, // start the engine ketsjiengine->StartEngine(true); + + // Set the animation playback rate for ipo's and actions + // the framerate below should patch with FPS macro defined in blendef.h + // Could be in StartEngine set the framerate, we need the scene to do this + ketsjiengine->SetAnimFrameRate( (((double) blscene->r.frs_sec) / blscene->r.frs_sec_base) ); + // the mainloop while (!exitrequested) { diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp index 7c9dbcdaab2..2a5cc14018f 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp @@ -133,7 +133,12 @@ void BL_RenderText(int mode,const char* textstr,int textlen,struct MTFace* tface characters = 0; } - if(!col) glColor3f(1.0f, 1.0f, 1.0f); + /* When OBCOL flag is on the color is set in IndexPrimitives_3DText */ + if (tface->mode & TF_OBCOL) { /* Color has been set */ + col= NULL; + } else { + if(!col) glColor3f(1.0f, 1.0f, 1.0f); + } glPushMatrix(); for (index = 0; index < characters; index++) { diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 1055c8771ef..ad126ebf123 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -134,14 +134,14 @@ void BL_ActionActuator::SetStartTime(float curtime) float direction = m_startframe < m_endframe ? 1.0 : -1.0; if (!(m_flag & ACT_FLAG_REVERSE)) - m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_FIXED_FRAME_PER_SEC; + m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate(); else - m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_FIXED_FRAME_PER_SEC; + m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate(); } void BL_ActionActuator::SetLocalTime(float curtime) { - float delta_time = (curtime - m_starttime)*KX_FIXED_FRAME_PER_SEC; + float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate(); if (m_endframe < m_startframe) delta_time = -delta_time; @@ -385,7 +385,7 @@ bool BL_ActionActuator::Update(double curtime, bool frame) blend_poses(m_pose, m_blendpose, 1.0 - newweight, ACTSTRIPMODE_BLEND); /* Increment current blending percentage */ - m_blendframe = (curtime - m_blendstart)*KX_FIXED_FRAME_PER_SEC; + m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate(); if (m_blendframe>m_blendin) m_blendframe = m_blendin; diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 5dae59d1d63..57be41c0358 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -45,9 +45,8 @@ #include "GEN_Map.h" #include "GEN_HashedPtr.h" #include "KX_Scene.h" +#include "KX_KetsjiEngine.h" /* for m_anim_framerate */ -#define KX_FIXED_FRAME_PER_SEC 25.0f -#define KX_FIXED_SEC_PER_FRAME (1.0f / KX_FIXED_FRAME_PER_SEC) #define KX_OB_DYNAMIC 1 diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index 0f9caa456d9..cf246342cf9 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -164,14 +164,14 @@ void KX_IpoActuator::SetStartTime(float curtime) curtime = curtime - KX_KetsjiEngine::GetSuspendedDelta(); if (m_direction > 0) - m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_FIXED_FRAME_PER_SEC; + m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate(); else - m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_FIXED_FRAME_PER_SEC; + m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate(); } void KX_IpoActuator::SetLocalTime(float curtime) { - float delta_time = ((curtime - m_starttime) - KX_KetsjiEngine::GetSuspendedDelta())*KX_FIXED_FRAME_PER_SEC; + float delta_time = ((curtime - m_starttime) - KX_KetsjiEngine::GetSuspendedDelta())*KX_KetsjiEngine::GetAnimFrameRate(); // negative delta_time is caused by floating point inaccuracy // perhaps the inaccuracy could be reduced a bit diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 1e3393d59a8..56a06786679 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -71,6 +71,7 @@ #include "KX_TimeCategoryLogger.h" #include "RAS_FramingManager.h" +#include "stdio.h" // If define: little test for Nzc: guarded drawing. If the canvas is // not valid, skip rendering this frame. @@ -91,7 +92,7 @@ const char KX_KetsjiEngine::m_profileLabels[tc_numCategories][15] = { }; double KX_KetsjiEngine::m_ticrate = DEFAULT_LOGIC_TIC_RATE; - +double KX_KetsjiEngine::m_anim_framerate = 25.0; double KX_KetsjiEngine::m_suspendedtime = 0.0; double KX_KetsjiEngine::m_suspendeddelta = 0.0; @@ -1383,6 +1384,16 @@ void KX_KetsjiEngine::SetTicRate(double ticrate) m_ticrate = ticrate; } +double KX_KetsjiEngine::GetAnimFrameRate() +{ + return m_anim_framerate; +} + +void KX_KetsjiEngine::SetAnimFrameRate(double framerate) +{ + m_anim_framerate = framerate; +} + void KX_KetsjiEngine::SetTimingDisplay(bool frameRate, bool profile, bool properties) { m_show_framerate = frameRate; diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index bc2e3864be8..4c09bc3fcd5 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -103,6 +103,7 @@ private: double m_remainingTime; static double m_ticrate; + static double m_anim_framerate; /* for animation playback only - ipo and action */ static double m_suspendedtime; static double m_suspendeddelta; @@ -261,6 +262,15 @@ public: static void SetTicRate(double ticrate); /** + * Gets the framerate for playing animations. (actions and ipos) + */ + static double GetAnimFrameRate(); + /** + * Sets the framerate for playing animations. (actions and ipos) + */ + static void SetAnimFrameRate(double framerate); + + /** * Activates or deactivates timing information display. * @param frameRate Display for frame rate on or off. * @param profile Display for individual components on or off. diff --git a/source/gameengine/Ketsji/KX_RayCast.cpp b/source/gameengine/Ketsji/KX_RayCast.cpp index b88741625b6..89e2d645d54 100644 --- a/source/gameengine/Ketsji/KX_RayCast.cpp +++ b/source/gameengine/Ketsji/KX_RayCast.cpp @@ -49,7 +49,7 @@ bool KX_RayCast::RayTest(KX_IPhysicsController* ignore_controller, PHY_IPhysicsE // // returns true if an object was found, false if not. MT_Point3 frompoint(_frompoint); - const MT_Vector3 todir( (topoint - frompoint).normalized() ); + const MT_Vector3 todir( (topoint - frompoint).safe_normalized() ); PHY_IPhysicsController* hit_controller; PHY__Vector3 phy_pos; |