Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Tools/3dsmaxExport/MaxscriptExport/scripts/ogre/lib/OgreSkeletonLib_usefulfns.ms @ 6

Last change on this file since 6 was 6, checked in by anonymous, 17 years ago

=…

File size: 7.5 KB
Line 
1----------------------------------------------------------------------------------------
2-- ------------------------------ SOME USEFUL FUNCTIONS ----------------------------- --
3----------------------------------------------------------------------------------------
4
5-- global variables
6global g_MAX = false;
7global g_MAX_use_listener = false;
8
9-- global structures
10struct exportOptions (sampleRate, ikSampleRate, scale, flipyz, flipNormal, exportColours, exportUV, UVchannels, exportHelpers);
11struct exportAnims (names, startframes, endframes, lengths) ;
12
13global Anims;
14global Options;
15
16global OgreExportFloater;
17global OgreExportOptions, OgreExportObject, OgreExportMesh, OgreExportAnimation, OgreExportMaterial, OgreExportAbout;
18
19--------------------------------------------------------------------
20-- compute the transform, if you want to flip Y and Z axis,
21-- because the axis which 'defines height' in OGRE is the Y axis,
22-- whereas 3dsmax uses the Z one.
23--------------------------------------------------------------------
24function flipYZTransform Tform = (
25        local axis1,axis2,axis3,t,m
26       
27        -- computes the matrix
28        axis1 = point3 1 0 0 ;
29        axis2 = point3 0 0 1 ;
30        axis3 = point3 0 -1 0 ;
31        t = point3 0 0 0 ;
32        m=matrix3 axis1 axis2 axis3 t ;
33       
34        -- multiplies by the inverse
35        Tform = Tform*inverse(m) ;
36
37        return Tform ;
38)
39
40-----------------------------------------------------------------------------
41-- check if the bone is the root object of the biped
42-----------------------------------------------------------------------------
43function isPelvis bipObj =
44(
45        if (bipObj == undefined) then return false ;
46        if (classof bipObj != Biped_Object) then return false;
47        return ((biped.getNode bipObj 13) == bipObj) ;
48)
49
50
51-----------------------------------------------------------------------------
52-- check if the bone is the footstep object of the biped
53-----------------------------------------------------------------------------
54function isFootStep bipObj =
55(
56        if (bipObj == undefined) then return false ;
57        if (classof bipObj != Biped_Object) then return false;
58        return ((biped.getNode bipObj 16) == bipObj) ;
59)
60
61
62--------------------------------------------------------------------
63-- returns if the bone is the root or not,
64-- ia if its parent is undefined or is not a bone.
65--------------------------------------------------------------------
66function isRoot b = (
67        if (b.parent==undefined or not (iskindof b.parent BoneGeometry or iskindOf b.parent Biped_Object) ) then
68                return true ;
69        else
70                return false ;
71       
72)
73
74--------------------------------------------------------------------
75-- returns if the bone is the root or not,
76-- handles standard bones as well as biped
77--------------------------------------------------------------------
78function isRootUniversal b = (
79        if (isRoot b) then
80                return true;
81        else if (isPelvis b) then
82                return true;
83        else
84                return false;
85)
86
87--------------------------------------------------------------------
88-- returns if the object is a root or not,
89-- handles any kind oj object
90--------------------------------------------------------------------
91function isRootUniversal2 b = (
92        bname = replaceSpaces b.name;
93        ind = (findItem RootsList bname);
94        if (ind == 0) then
95                return false;
96        else
97                return true;
98)
99
100--------------------------------------------------------------------
101-- returns if the object is part of the skin (or physique modifier)
102--------------------------------------------------------------------
103function isPartOfModifier b sk phy = (
104        name = replaceSpaces b.name ;
105        if (sk!=undefined) then
106        (
107                for i=1 to (skinOps.GetNumberBones sk) do
108                (
109                        bname = skinOps.GetBoneName sk i 1 ;
110                        replaceSpaces bname ;
111                        if (name == bname) then
112                                return true;
113                )
114        )
115        else if (phy!=undefined) then
116        (
117                for i=1 to (physiqueOps.GetBoneCount $) do
118                (
119                        bname = (physiqueOps.GetBones $)[i].name;
120                        replaceSpaces bname ;
121                        if (name == bname) then
122                                return true;
123                )
124        )
125        return false;
126)
127
128--------------------------------------------------------------------
129-- creates a new array (which must be set up as an array before
130-- calling this function) in which there isn't the same element.
131-- Moreover, the array is sorted.
132--------------------------------------------------------------------
133
134function keepLoneValues a b= (
135        local e, last_e ;
136        sort a ;
137        last_e = undefined ;
138        for e in a do (
139                if (e!=last_e) then
140                        append b e ;
141                last_e = e ;
142        )
143)
144
145---------------------------------------------------------------------
146-- replaces " " by "_" in a string.
147-- when a name is for example Left Biceps max knows it at Left_Biceps
148-- and execute function will not work if you don't use this function
149---------------------------------------------------------------------
150function replaceSpaces s =
151(
152        for i=1 to s.count do
153        (
154                if (s[i] == " ") then
155                        s[i] = "_" ;
156        )
157        s ;
158)
159
160--------------------------------
161-- return the length of an array
162--------------------------------
163function arrayLength a =
164(
165        local i ;
166        i = 1 ;
167        while (a[i] != undefined) do
168                i = i + 1 ;     
169        i-1 ;
170)
171
172-----------------------------------------------------------------------------
173-- return the skin modifier or undefined if object don't have a skin modifier
174-----------------------------------------------------------------------------
175function getSkin obj =
176(
177        local s,i ;
178        s = undefined ;
179        if obj != undefined then
180                for i in obj.modifiers do
181                (
182                        if iskindof i Skin do
183                                s = i ;
184                )
185        s ;
186)
187
188
189-----------------------------------------------------------------------------
190-- return the physique modifier or undefined if object don't have it
191-----------------------------------------------------------------------------
192function getPhysique obj =
193(
194        local s,i ;
195        s = undefined ;
196        if obj != undefined then
197                for i in obj.modifiers do
198                (
199                        if iskindof i Physique do
200                                s = i ;
201                )
202        s ;
203)
204
205-----------------------------------------------------------------------------
206-- return the OctopusExport modifier or undefined if object don't have it
207-----------------------------------------------------------------------------
208function getOctopusExport obj =
209(
210        local s,i ;
211        s = undefined ;
212        if obj != undefined then
213                for i in obj.modifiers do
214                (
215                        if iskindof i OctopusMeshModifier do
216                                s = i ;
217                )
218        s ;
219)
220
221--------------------------------------------------
222-- return an Array with the root bones of the skin
223--------------------------------------------------
224
225function getRoots skin =
226(
227        local rootstab,n,i,c,d ;
228        rootstab = #() ;
229        n = skinOps.GetNumberBones skin ;
230        for i = 1 to n do
231        (
232                c= skinOps.GetBoneName skin i 1 ;
233                replaceSpaces c ;
234                d = getNodeByName c ;
235                if (isRoot d) then
236                        append rootstab d ;
237        )
238        rootstab ;
239)
240
241--------------------------------------------------------
242-- return an Array with the ID of root bones of the skin
243--------------------------------------------------------
244
245function getRootsId skin =
246(
247        local rootstab,n,i,c,d ;
248        rootstab = #() ;
249        n = skinOps.GetNumberBones skin ;
250        for i = 1 to n do
251        (
252                c= skinOps.GetBoneName skin i 1 ;
253                replaceSpaces c ;
254                d = getNodeByName c ;
255                if (isRoot d) then
256                        append rootstab i ;
257        )
258        rootstab ;
259)
260
261-------------------------------------------------------
262-- return a angleAxis given a Quaternion
263-------------------------------------------------------
264
265function toAngleAxis q =
266(
267        local angle, axis;
268        local result;
269       
270        fSqrLength = q.x*q.x+q.y*q.y+q.z*q.z ;
271        if (fSqrLength > 0.0) then
272        (
273                angle = ((acos q.w) * pi / 90);
274                fInvLength = 1.0 / (sqrt fSqrLength);
275                axis = [q.x*fInvLength, q.y*fInvLength, q.z*fInvLength];
276                result = angleAxis angle axis;
277        )
278        else
279        (
280                angle = 0;
281                axis = [1,0,0];
282                result = angleAxis angle axis;
283        )
284       
285        return result;
286)
Note: See TracBrowser for help on using the repository browser.