10d5e65ed9f4d8762489e0455f9fed53f0374b5d
[blender.git] / source / gameengine / Converter / BL_BlenderDataConversion.cpp
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  * Convert blender data to ketsji
32  */
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 #ifdef WIN32
39 #pragma warning (disable : 4786)
40 #endif
41
42 #include <math.h>
43
44 #include "BL_BlenderDataConversion.h"
45 #include "KX_BlenderGL.h"
46 #include "KX_BlenderScalarInterpolator.h"
47
48 #include "RAS_IPolygonMaterial.h"
49 #include "KX_PolygonMaterial.h"
50
51 // Expressions
52 #include "ListValue.h"
53 #include "IntValue.h"
54 // Collision & Fuzzics LTD
55
56 #include "PHY_Pro.h"
57
58
59 #include "KX_Scene.h"
60 #include "KX_GameObject.h"
61 #include "RAS_FramingManager.h"
62 #include "RAS_MeshObject.h"
63
64 #include "KX_ConvertActuators.h"
65 #include "KX_ConvertControllers.h"
66 #include "KX_ConvertSensors.h"
67
68 #include "SCA_LogicManager.h"
69 #include "SCA_EventManager.h"
70 #include "SCA_TimeEventManager.h"
71 #include "KX_Light.h"
72 #include "KX_Camera.h"
73 #include "KX_EmptyObject.h"
74 #include "MT_Point3.h"
75 #include "MT_Transform.h"
76 #include "MT_MinMax.h"
77 #include "SCA_IInputDevice.h"
78 #include "RAS_TexMatrix.h"
79 #include "RAS_ICanvas.h"
80 #include "RAS_MaterialBucket.h"
81 //#include "KX_BlenderPolyMaterial.h"
82 #include "RAS_Polygon.h"
83 #include "RAS_TexVert.h"
84 #include "RAS_BucketManager.h"
85 #include "RAS_IRenderTools.h"
86 #include "BL_Material.h"
87 #include "KX_BlenderMaterial.h"
88 #include "BL_Texture.h"
89
90 #include "DNA_action_types.h"
91 #include "BKE_main.h"
92 #include "BKE_global.h"
93 #include "BL_SkinMeshObject.h"
94 #include "BL_SkinDeformer.h"
95 #include "BL_MeshDeformer.h"
96 //#include "BL_ArmatureController.h"
97
98 #include "BlenderWorldInfo.h"
99
100 #include "KX_KetsjiEngine.h"
101 #include "KX_BlenderSceneConverter.h"
102
103 #include"SND_Scene.h"
104 #include "SND_SoundListener.h"
105
106 /* This little block needed for linking to Blender... */
107 #ifdef WIN32
108 #include "BLI_winstuff.h"
109 #endif
110
111 /* This list includes only data type definitions */
112 #include "DNA_object_types.h"
113 #include "DNA_material_types.h"
114 #include "DNA_texture_types.h"
115 #include "DNA_image_types.h"
116 #include "DNA_lamp_types.h"
117 #include "DNA_group_types.h"
118 #include "DNA_scene_types.h"
119 #include "DNA_camera_types.h"
120 #include "DNA_property_types.h"
121 #include "DNA_text_types.h"
122 #include "DNA_sensor_types.h"
123 #include "DNA_controller_types.h"
124 #include "DNA_actuator_types.h"
125 #include "DNA_mesh_types.h"
126 #include "DNA_meshdata_types.h"
127 #include "DNA_view3d_types.h"
128 #include "DNA_world_types.h"
129 #include "DNA_sound_types.h"
130 #include "DNA_key_types.h"
131 #include "DNA_armature_types.h"
132
133 #include "MEM_guardedalloc.h"
134 #include "BKE_utildefines.h"
135 #include "BKE_key.h"
136 #include "BKE_mesh.h"
137 #include "MT_Point3.h"
138
139
140 #include "BKE_material.h" /* give_current_material */
141 /* end of blender include block */
142
143 #include "KX_BlenderInputDevice.h"
144 #include "KX_ConvertProperties.h"
145 #include "KX_HashedPtr.h"
146
147
148 #include "KX_ScalarInterpolator.h"
149
150 #include "KX_IpoConvert.h"
151 #include "SYS_System.h"
152
153 #include "SG_Node.h"
154 #include "SG_BBox.h"
155 #include "SG_Tree.h"
156
157 // defines USE_ODE to choose physics engine
158 #include "KX_ConvertPhysicsObject.h"
159
160
161 // This file defines relationships between parents and children
162 // in the game engine.
163
164 #include "KX_SG_NodeRelationships.h"
165 #include "KX_SG_BoneParentNodeRelationship.h"
166
167 #include "BL_ArmatureObject.h"
168 #include "BL_DeformableGameObject.h"
169
170 static int default_face_mode = TF_DYNAMIC;
171
172 static unsigned int KX_rgbaint2uint_new(unsigned int icol)
173 {
174         union
175         {
176                 unsigned int integer;
177                 unsigned char cp[4];
178         } out_colour, in_colour;
179         
180         in_colour.integer = icol;
181         out_colour.cp[0] = in_colour.cp[3]; // red
182         out_colour.cp[1] = in_colour.cp[2]; // green
183         out_colour.cp[2] = in_colour.cp[1]; // blue
184         out_colour.cp[3] = in_colour.cp[0]; // alpha
185         
186         return out_colour.integer;
187 }
188
189 /* Now the real converting starts... */
190 static unsigned int KX_Mcol2uint_new(MCol col)
191 {
192         /* color has to be converted without endian sensitivity. So no shifting! */
193         union
194         {
195                 MCol col;
196                 unsigned int integer;
197                 unsigned char cp[4];
198         } out_colour, in_colour;
199
200         in_colour.col = col;
201         out_colour.cp[0] = in_colour.cp[3]; // red
202         out_colour.cp[1] = in_colour.cp[2]; // green
203         out_colour.cp[2] = in_colour.cp[1]; // blue
204         out_colour.cp[3] = in_colour.cp[0]; // alpha
205         
206         return out_colour.integer;
207 }
208
209 static void SetDefaultFaceType(Scene* scene)
210 {
211         default_face_mode = TF_DYNAMIC;
212         Base *base = static_cast<Base*>(scene->base.first);
213         while(base)
214         {
215                 if (base->object->type == OB_LAMP)
216                 {
217                         default_face_mode = TF_DYNAMIC|TF_LIGHT;
218                         return;
219                 }
220                 base = base->next;
221         }
222 }
223
224
225 // --
226 static void GetRGB(short type,
227         MFace* mface,
228         MCol* mmcol,
229         Material *mat,
230         TFace *tface,
231         unsigned int &c0, 
232         unsigned int &c1, 
233         unsigned int &c2, 
234         unsigned int &c3)
235 {
236         unsigned int colour = 0xFFFFFFFFL;
237         switch(type)
238         {
239                 case 0: // vertex colors?
240                 {
241                         if(mmcol) {
242                                 c0 = KX_Mcol2uint_new(mmcol[0]);
243                                 c1 = KX_Mcol2uint_new(mmcol[1]);
244                                 c2 = KX_Mcol2uint_new(mmcol[2]);
245                                 if (mface->v4)
246                                         c3 = KX_Mcol2uint_new(mmcol[3]);
247                                 mmcol += 4;
248                         }else // backup white
249                         {
250                                 c0 = KX_rgbaint2uint_new(colour);
251                                 c1 = KX_rgbaint2uint_new(colour);
252                                 c2 = KX_rgbaint2uint_new(colour);       
253                                 if (mface->v4)
254                                         c3 = KX_rgbaint2uint_new( colour );
255                         }
256                 } break;
257                 
258         
259                 case 1: // material rgba
260                 {
261                         if (mat) {
262                                 union {
263                                         unsigned char cp[4];
264                                         unsigned int integer;
265                                 } col_converter;
266                                 col_converter.cp[3] = (unsigned char) (mat->r*255.0);
267                                 col_converter.cp[2] = (unsigned char) (mat->g*255.0);
268                                 col_converter.cp[1] = (unsigned char) (mat->b*255.0);
269                                 col_converter.cp[0] = (unsigned char) (mat->alpha*255.0);
270                                 colour = col_converter.integer;
271                         }
272                         c0 = KX_rgbaint2uint_new(colour);
273                         c1 = KX_rgbaint2uint_new(colour);
274                         c2 = KX_rgbaint2uint_new(colour);       
275                         if (mface->v4)
276                                 c3 = KX_rgbaint2uint_new(colour);
277                 } break;
278                 
279                 case 2: // vertex colors
280                 {
281                         if(tface ) {
282                                 c0 = KX_rgbaint2uint_new(tface->col[0]);
283                                 c1 = KX_rgbaint2uint_new(tface->col[1]);
284                                 c2 = KX_rgbaint2uint_new(tface->col[2]);
285                         
286                                 if (mface->v4) {
287                                         c3 = KX_rgbaint2uint_new(tface->col[3]);
288                                 }
289                         }else {
290                                 c0 = KX_rgbaint2uint_new(colour);
291                                 c1 = KX_rgbaint2uint_new(colour);
292                                 c2 = KX_rgbaint2uint_new(colour);       
293                                 if (mface->v4)
294                                         c3 = KX_rgbaint2uint_new( colour );
295                         }
296                 } break;
297                 
298                 case 3: // white
299                 {
300                         c0 = KX_rgbaint2uint_new(colour);
301                         c1 = KX_rgbaint2uint_new(colour);
302                         c2 = KX_rgbaint2uint_new(colour);       
303                         if (mface->v4)
304                                 c3 = KX_rgbaint2uint_new(colour);
305                 } break;
306         }
307 }
308
309 // ------------------------------------
310 BL_Material* ConvertMaterial(  Mesh* mesh, Material *mat, TFace* tface,  MFace* mface, MCol* mmcol, int lightlayer, Object* blenderobj )
311 {
312         BL_Material *material = new BL_Material();
313         //initBL_Material(material);
314         int numchan =   -1;
315         bool validmat   = (mat!=0);
316         bool using_facetexture = false;
317
318         short type = 0;
319         if( validmat )
320                 type = 1; // material color 
321         else if(mesh->tface && tface)
322                 type = 2; // vertex colors
323         
324         material->IdMode = DEFAULT_BLENDER;
325
326         // --------------------------------
327         if(validmat) {
328
329                 // use vertex colors by explicitly setting
330                 if(mat->mode &MA_VERTEXCOLP) 
331                         type = 2;
332
333                 // use lighting?
334                 material->ras_mode |= ( mat->mode & MA_SHLESS )?0:USE_LIGHT;
335                 MTex *mttmp = 0;
336                 numchan = getNumTexChannels(mat);
337                 int valid_index = 0;
338                 
339                 bool facetex = ((mat->mode & MA_FACETEXTURE) &&  (mesh->tface && tface) );
340                 
341                 numchan = numchan>MAXTEX?MAXTEX:(numchan>=0&& facetex)?numchan+1:numchan;
342                 
343                 // foreach MTex
344                 for(int i=0; i<numchan; i++) {
345                         // use face tex
346                         if(i==0 && facetex ) {
347                                 Image*tmp = (Image*)(tface->tpage);
348                                 if(tmp) {
349                                         material->img[i] = tmp;
350                                         material->texname[i] = material->img[i]->id.name;
351                                         material->flag[i] |= ( tface->transp  &TF_ALPHA )?USEALPHA:0;
352                                         material->flag[i] |= ( tface->transp  &TF_ADD   )?CALCALPHA:0;
353                                         material->ras_mode|= ( tface->transp  &(TF_ADD | TF_ALPHA))?TRANSP:0;
354                                         material->mapping[i].mapping |= ( (material->img[i]->flag & IMA_REFLECT)!=0 )?USEREFL:0;
355                                         //material->blend_mode[i] = BLEND_MUL;
356                                         i++;// skip to the next image
357                                         valid_index++;
358                                 }
359                         }
360
361                         mttmp = getImageFromMaterial( mat, i );
362                         if( mttmp ) {
363                                 if( mttmp->tex ) {
364                                         if( mttmp->tex->type == TEX_IMAGE ) {
365                                                 material->mtexname[i] = mttmp->tex->id.name;
366                                                 material->img[i] = mttmp->tex->ima;
367                                                 if( material->img[i] ) {
368
369                                                         material->texname[i] = material->img[i]->id.name;
370                                                         material->flag[i] |= ( mttmp->tex->imaflag &TEX_MIPMAP )?MIPMAP:0;
371                                                         // -----------------------
372                                                         if( mttmp->tex->imaflag &TEX_USEALPHA ) {
373                                                                 material->flag[i]       |= USEALPHA;
374                                                         }
375                                                         // -----------------------
376                                                         else if( mttmp->tex->imaflag &TEX_CALCALPHA ) {
377                                                                 material->flag[i]       |= CALCALPHA;
378                                                         }
379                                                         else if(mttmp->tex->flag &TEX_NEGALPHA) {
380                                                                 material->flag[i]       |= USENEGALPHA;
381                                                         }
382
383                                                         material->color_blend[i] = mttmp->colfac;
384                                                         material->flag[i] |= ( mttmp->mapto  & MAP_ALPHA                )?TEXALPHA:0;
385                                                         material->flag[i] |= ( mttmp->texflag& MTEX_NEGATIVE    )?TEXNEG:0;
386
387                                                 }
388                                         }
389                                         else if(mttmp->tex->type == TEX_ENVMAP) {
390                                                 if( mttmp->tex->env->stype == ENV_LOAD ) {
391                                         
392                                                         material->mtexname[i]= mttmp->tex->id.name;
393                                                         material->cubemap[i] = mttmp->tex->env;
394                                                         if(material->cubemap[i]->ima) {
395                                                                 material->texname[i] = material->cubemap[i]->ima->id.name;
396                                                                 material->mapping[i].mapping |= USEENV;
397                                                         }
398                                                         else {
399                                                                 // in the player, we need to split it our self
400                                                                 material->cubemap[i]->ima = mttmp->tex->ima;
401                                                                 if(material->cubemap[i]->ima) {
402                                                                         material->texname[i] = material->cubemap[i]->ima->id.name;
403                                                                         material->mapping[i].mapping |= USEENV;
404                                                                 }
405                                                                 //
406                                                         }
407                                                 }
408                                         }
409                                         material->flag[i] |= (mat->ipo!=0)?HASIPO:0;
410                                         /// --------------------------------
411                                         // mapping methods
412                                         material->mapping[i].mapping |= ( mttmp->texco  & TEXCO_REFL    )?USEREFL:0;
413                                         
414                                         if(mttmp->texco & TEXCO_OBJECT) {
415                                                 material->mapping[i].mapping |= USEOBJ;
416                                                 if(mttmp->object)
417                                                         material->mapping[i].objconame = mttmp->object->id.name;
418                                         }
419                                         
420                                         material->mapping[i].scale[0] = mttmp->size[0];
421                                         material->mapping[i].scale[1] = mttmp->size[1];
422                                         material->mapping[i].scale[2] = mttmp->size[2];
423                                         material->mapping[i].offsets[0] = mttmp->ofs[0];
424                                         material->mapping[i].offsets[1] = mttmp->ofs[1];
425                                         material->mapping[i].offsets[2] = mttmp->ofs[2];
426
427                                         material->mapping[i].projplane[0] = mttmp->projx;
428                                         material->mapping[i].projplane[1] = mttmp->projy;
429                                         material->mapping[i].projplane[2] = mttmp->projz;
430                                         /// --------------------------------
431                                         
432                                         switch( mttmp->blendtype ) {
433                                         case MTEX_BLEND:
434                                                 material->blend_mode[i] = BLEND_MIX;
435                                                 break;
436                                         case MTEX_MUL:
437                                                 material->blend_mode[i] = BLEND_MUL;
438                                                 break;
439                                         case MTEX_ADD:
440                                                 material->blend_mode[i] = BLEND_ADD;
441                                                 break;
442                                         case MTEX_SUB:
443                                                 material->blend_mode[i] = BLEND_SUB;
444                                                 break;
445                                         case MTEX_SCREEN:
446                                                 material->blend_mode[i] = BLEND_SCR;
447                                                 break;
448                                         }
449                                         valid_index++;
450                                 }
451                         }
452                 }
453                 // above one tex the switches here
454                 // are not used
455                 switch(valid_index) {
456                 case 0:
457                         material->IdMode = DEFAULT_BLENDER;
458                         break;
459                 case 1:
460                         material->IdMode = ONETEX;
461                         break;
462                 default:
463                         material->IdMode = GREATERTHAN2;
464                         break;
465                 }
466
467                 material->num_enabled = valid_index;
468
469                 material->speccolor[0]  = mat->specr;
470                 material->speccolor[1]  = mat->specg;
471                 material->speccolor[2]  = mat->specb;
472                 material->hard                  = (float)mat->har/4.0f;
473                 material->matcolor[0]   = mat->r;
474                 material->matcolor[1]   = mat->g;
475                 material->matcolor[2]   = mat->b;
476                 material->matcolor[3]   = mat->alpha;
477                 material->alpha                 = mat->alpha;
478                 material->emit                  = mat->emit;
479                 material->spec_f                = mat->spec;
480                 material->ref                   = mat->ref;
481                 material->amb                   = mat->amb;
482                 material->ras_mode |= ((mat->mode & MA_ZTRA) != 0)?ZSORT:0;
483                 material->ras_mode |= ((mat->mode & MA_WIRE) != 0)?WIRE:0;
484         }
485         else {
486                 int valid = 0;
487                 // check for tface tex to fallback on
488                 if( mesh->tface && tface ){
489                         material->img[0] = (Image*)(tface->tpage);
490                         // ------------------------
491                         if(material->img[0]) {
492                                 material->texname[0] = material->img[0]->id.name;
493                                 material->mapping[0].mapping |= ( (material->img[0]->flag & IMA_REFLECT)!=0 )?USEREFL:0;
494                                 material->flag[0] |= ( tface->transp  &TF_ALPHA )?USEALPHA:0;
495                                 material->flag[0] |= ( tface->transp  &TF_ADD   )?CALCALPHA:0;
496                                 material->ras_mode|= ( tface->transp  & (TF_ADD|TF_ALPHA))?TRANSP:0;
497                                 valid++;
498                         }
499                 }
500                 material->num_enabled   = valid;
501                 material->IdMode                = TEXFACE;
502                 material->speccolor[0]  = 1.f;
503                 material->speccolor[1]  = 1.f;
504                 material->speccolor[2]  = 1.f;
505                 material->hard                  = 35.f;
506                 material->matcolor[0]   = 0.5f;
507                 material->matcolor[1]   = 0.5f;
508                 material->matcolor[2]   = 0.5f;
509                 material->spec_f                = 0.5f;
510                 material->ref                   = 0.8f;
511         }
512         MT_Point2 uv[4];
513
514         if( mesh->tface &&  tface ) {
515
516                 material->ras_mode |= !( 
517                         (tface->flag & TF_HIDE) ||
518                         (tface->mode & TF_INVISIBLE)
519                         )?POLY_VIS:0;
520
521                 material->ras_mode |= ( (tface->mode & TF_DYNAMIC)!= 0 )?COLLIDER:0;
522                 material->transp = tface->transp;
523                 
524                 if(tface->transp)
525                         material->ras_mode |= TRANSP;
526
527                 material->tile  = tface->tile;
528                 material->mode  = tface->mode;
529                         
530                 uv[0]   = MT_Point2(tface->uv[0]);
531                 uv[1]   = MT_Point2(tface->uv[1]);
532                 uv[2]   = MT_Point2(tface->uv[2]);
533
534                 if (mface->v4) 
535                         uv[3]   = MT_Point2(tface->uv[3]);
536         } 
537         else {
538                 // nothing at all
539                 material->ras_mode |= (COLLIDER|POLY_VIS| (validmat?0:USE_LIGHT));
540                 material->mode          = default_face_mode;    
541                 material->transp        = TF_SOLID;
542                 material->tile          = 0;
543         }
544         unsigned int rgb[4];
545         GetRGB(type,mface,mmcol,mat,tface,rgb[0],rgb[1],rgb[2], rgb[3]);
546         material->SetConversionRGB(rgb);
547         material->SetConversionUV(uv);
548
549         material->ras_mode |= (mface->v4==0)?TRIANGLE:0;
550         if(validmat)
551                 material->matname       =(mat->id.name);
552
553         material->tface         = tface;
554         material->material      = mat;
555         return material;
556 }
557
558
559 RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* rendertools, KX_Scene* scene, KX_BlenderSceneConverter *converter)
560 {
561         RAS_MeshObject *meshobj;
562         bool    skinMesh = false;
563         
564         int lightlayer = blenderobj->lay;
565         
566         MFace* mface = static_cast<MFace*>(mesh->mface);
567         TFace* tface = static_cast<TFace*>(mesh->tface);
568         MCol* mmcol = mesh->mcol;
569         MT_assert(mface || mesh->totface == 0);
570         
571         // Determine if we need to make a skinned mesh
572         if (mesh->dvert){
573                 meshobj = new BL_SkinMeshObject(lightlayer);
574                 skinMesh = true;
575         }
576         else {
577                 meshobj = new RAS_MeshObject(lightlayer);
578         }
579         
580         meshobj->SetName(mesh->id.name);
581         
582         meshobj->m_xyz_index_to_vertex_index_mapping.resize(mesh->totvert);
583         
584         for (int f=0;f<mesh->totface;f++,mface++)
585         {
586                 
587                 bool collider = true;
588                 
589                 // only add valid polygons
590                 if (mface->v3)
591                 {
592                         MT_Point2 uv0(0.0,0.0),uv1(0.0,0.0),uv2(0.0,0.0),uv3(0.0,0.0);
593                         // rgb3 is set from the adjoint face in a square
594                         unsigned int rgb0,rgb1,rgb2,rgb3 = 0;
595                         MT_Vector3      no0(mesh->mvert[mface->v1].no[0], mesh->mvert[mface->v1].no[1], mesh->mvert[mface->v1].no[2]),
596                                         no1(mesh->mvert[mface->v2].no[0], mesh->mvert[mface->v2].no[1], mesh->mvert[mface->v2].no[2]),
597                                         no2(mesh->mvert[mface->v3].no[0], mesh->mvert[mface->v3].no[1], mesh->mvert[mface->v3].no[2]),
598                                         no3(0.0, 0.0, 0.0);
599                         MT_Point3       pt0(mesh->mvert[mface->v1].co),
600                                         pt1(mesh->mvert[mface->v2].co),
601                                         pt2(mesh->mvert[mface->v3].co),
602                                         pt3(0.0, 0.0, 0.0);
603                         
604                         no0 /= 32767.0;
605                         no1 /= 32767.0;
606                         no2 /= 32767.0;
607                         if (mface->v4)
608                         {
609                                 pt3 = MT_Point3(mesh->mvert[mface->v4].co);
610                                 no3 = MT_Vector3(mesh->mvert[mface->v4].no[0], mesh->mvert[mface->v4].no[1], mesh->mvert[mface->v4].no[2]);
611                                 no3 /= 32767.0;
612                         }
613         
614                         if(!(mface->flag & ME_SMOOTH))
615                         {
616                                 MT_Vector3 norm = ((pt1-pt0).cross(pt2-pt0)).safe_normalized();
617                                 norm[0] = ((int) (10*norm[0]))/10.0;
618                                 norm[1] = ((int) (10*norm[1]))/10.0;
619                                 norm[2] = ((int) (10*norm[2]))/10.0;
620                                 no0=no1=no2=no3= norm;
621         
622                         }
623                 
624                         {
625                                 Material* ma = 0;
626                                 bool polyvisible = true;
627                                 RAS_IPolyMaterial* polymat = NULL;
628
629                                 if(converter->GetMaterials()) 
630                                 {       
631                                         if(mesh->totcol > 1)
632                                                 ma = mesh->mat[mface->mat_nr];
633                                         else 
634                                                 ma = give_current_material(blenderobj, 1);
635
636                                         BL_Material *bl_mat = ConvertMaterial(mesh, ma, tface, mface, mmcol, lightlayer, blenderobj);
637                                         // set the index were dealing with
638                                         bl_mat->material_index =  (int)mface->mat_nr;
639
640                                         polyvisible = ((bl_mat->ras_mode & POLY_VIS)!=0);
641                                         collider = ((bl_mat->ras_mode & COLLIDER)!=0);
642                                         
643                                         polymat = new KX_BlenderMaterial(scene, bl_mat, skinMesh, lightlayer, blenderobj );
644                                         converter->RegisterBlenderMaterial(bl_mat);
645                                         
646                                         unsigned int rgb[4];
647                                         bl_mat->GetConversionRGB(rgb);
648                                         rgb0 = rgb[0];
649                                         rgb1 = rgb[1];
650                                         rgb2 = rgb[2];
651                                         rgb3 = rgb[3];
652                                         MT_Point2 uv[4];
653                                         bl_mat->GetConversionUV(uv);
654                                         uv0 = uv[0];
655                                         uv1 = uv[1];
656                                         uv2 = uv[2];
657                                         uv3 = uv[3];
658                                         // this is needed to free up memory afterwards
659                                         converter->RegisterPolyMaterial(polymat);
660                                 }
661                                 else
662                                 {
663                                         ma = give_current_material(blenderobj, 1);
664
665                                         Image* bima = ((mesh->tface && tface) ? (Image*) tface->tpage : NULL);
666                 
667                                         STR_String imastr = 
668                                                 ((mesh->tface && tface) ? 
669                                                 (bima? (bima)->id.name : "" ) : "" );
670                         
671                                         char transp=0;
672                                         short mode=0, tile=0;
673                                         int     tilexrep=4,tileyrep = 4;
674                                         
675                                         if (bima)
676                                         {
677                                                 tilexrep = bima->xrep;
678                                                 tileyrep = bima->yrep;
679                                 
680                                         }
681
682                                         if (mesh->tface && tface)
683                                         {
684                                                 // Use texface colors if available
685                                                 //TF_DYNAMIC means the polygon is a collision face
686                                                 collider = ((tface->mode & TF_DYNAMIC) != 0);
687                                                 transp = tface->transp;
688                                                 tile = tface->tile;
689                                                 mode = tface->mode;
690                                                 
691                                                 polyvisible = !((tface->flag & TF_HIDE)||(tface->mode & TF_INVISIBLE));
692                                                 
693                                                 uv0 = MT_Point2(tface->uv[0]);
694                                                 uv1 = MT_Point2(tface->uv[1]);
695                                                 uv2 = MT_Point2(tface->uv[2]);
696                                                 rgb0 = KX_rgbaint2uint_new(tface->col[0]);
697                                                 rgb1 = KX_rgbaint2uint_new(tface->col[1]);
698                                                 rgb2 = KX_rgbaint2uint_new(tface->col[2]);
699                 
700                                                 if (mface->v4)
701                                                 {
702                                                         uv3 = MT_Point2(tface->uv[3]);
703                                                         rgb3 = KX_rgbaint2uint_new(tface->col[3]);
704                                                 } 
705                                         } 
706                                         else
707                                         {
708                                                 //
709                                                 if (mmcol)
710                                                 {
711                                                         // Use vertex colours
712                                                         rgb0 = KX_Mcol2uint_new(mmcol[0]);
713                                                         rgb1 = KX_Mcol2uint_new(mmcol[1]);
714                                                         rgb2 = KX_Mcol2uint_new(mmcol[2]);
715                                                         
716                                                         
717                                                         if (mface->v4)
718                                                         {
719                                                                 rgb3 = KX_Mcol2uint_new(mmcol[3]);
720                                                                 
721                                                         }
722                                                 
723                                                         mmcol += 4;
724                                                 }
725                                                 else
726                                                 {
727                                                         // If there are no vertex colors OR texfaces,
728                                                         // Initialize face to white and set COLLSION true and everything else FALSE
729                                                         unsigned int colour = 0xFFFFFFFFL;
730                                                         mode = default_face_mode;       
731                                                         transp = TF_SOLID;
732                                                         tile = 0;
733                                                         if (ma)
734                                                         {
735                                                                 // If we have a material, take the default colour from the material.
736                                                                 union
737                                                                 {
738                                                                         unsigned char cp[4];
739                                                                         unsigned int integer;
740                                                                 } col_converter;
741                                                                 
742                                                                 col_converter.cp[3] = (unsigned char) (ma->r*255.0);
743                                                                 col_converter.cp[2] = (unsigned char) (ma->g*255.0);
744                                                                 col_converter.cp[1] = (unsigned char) (ma->b*255.0);
745                                                                 col_converter.cp[0] = (unsigned char) (ma->alpha*255.0);
746                                                                 
747                                                                 colour = col_converter.integer;
748                                                         }
749                                                         
750                                                         rgb0 = KX_rgbaint2uint_new(colour);
751                                                         rgb1 = KX_rgbaint2uint_new(colour);
752                                                         rgb2 = KX_rgbaint2uint_new(colour);     
753                                                         
754                                                         if (mface->v4)
755                                                                 rgb3 = KX_rgbaint2uint_new(colour);
756                                                 }
757                                         }
758                                                 
759                                         
760                                         bool istriangle = (mface->v4==0);
761                                         bool zsort = ma?(ma->mode & MA_ZTRA) != 0:false;
762                                         
763                                         polymat = new KX_PolygonMaterial(imastr, ma,
764                                                 tile, tilexrep, tileyrep, 
765                                                 mode, transp, zsort, lightlayer, istriangle, blenderobj, tface);
766                 
767                                         if (ma)
768                                         {
769                                                 polymat->m_specular = MT_Vector3(ma->specr, ma->specg, ma->specb)*ma->spec;
770                                                 polymat->m_shininess = (float)ma->har/4.0; // 0 < ma->har <= 512
771                                                 polymat->m_diffuse = MT_Vector3(ma->r, ma->g, ma->b)*(ma->emit + ma->ref);
772
773                                         } else
774                                         {
775                                                 polymat->m_specular = MT_Vector3(0.0f,0.0f,0.0f);
776                                                 polymat->m_shininess = 35.0;
777                                         }
778                                         // this is needed to free up memory afterwards
779                                         converter->RegisterPolyMaterial(polymat);
780
781                                 }
782         
783                                 RAS_MaterialBucket* bucket = scene->FindBucket(polymat);
784                                                          
785                                 int nverts = mface->v4?4:3;
786                                 int vtxarray = meshobj->FindVertexArray(nverts,polymat);
787                                 RAS_Polygon* poly = new RAS_Polygon(bucket,polyvisible,nverts,vtxarray);
788                                 if (skinMesh) {
789                                         int d1, d2, d3, d4=0;
790                                         bool flat;
791
792                                         /* If the face is set to solid, all fnors are the same */
793                                         if (mface->flag & ME_SMOOTH)
794                                                 flat = false;
795                                         else
796                                                 flat = true;
797                                         
798                                         d1=((BL_SkinMeshObject*)meshobj)->FindOrAddDeform(vtxarray, mface->v1, &mesh->dvert[mface->v1], polymat);
799                                         d2=((BL_SkinMeshObject*)meshobj)->FindOrAddDeform(vtxarray, mface->v2, &mesh->dvert[mface->v2], polymat);
800                                         d3=((BL_SkinMeshObject*)meshobj)->FindOrAddDeform(vtxarray, mface->v3, &mesh->dvert[mface->v3], polymat);
801                                         if (nverts==4)
802                                                 d4=((BL_SkinMeshObject*)meshobj)->FindOrAddDeform(vtxarray, mface->v4, &mesh->dvert[mface->v4], polymat);
803                                         poly->SetVertex(0,((BL_SkinMeshObject*)meshobj)->FindOrAddVertex(vtxarray,pt0,uv0,rgb0,no0,d1,flat, polymat));
804                                         poly->SetVertex(1,((BL_SkinMeshObject*)meshobj)->FindOrAddVertex(vtxarray,pt1,uv1,rgb1,no1,d2,flat, polymat));
805                                         poly->SetVertex(2,((BL_SkinMeshObject*)meshobj)->FindOrAddVertex(vtxarray,pt2,uv2,rgb2,no2,d3,flat, polymat));
806                                         if (nverts==4)
807                                                 poly->SetVertex(3,((BL_SkinMeshObject*)meshobj)->FindOrAddVertex(vtxarray,pt3,uv3,rgb3,no3,d4, flat,polymat));
808                                 }
809                                 else
810                                 {
811                                         poly->SetVertex(0,meshobj->FindOrAddVertex(vtxarray,pt0,uv0,rgb0,no0,polymat,mface->v1));
812                                         poly->SetVertex(1,meshobj->FindOrAddVertex(vtxarray,pt1,uv1,rgb1,no1,polymat,mface->v2));
813                                         poly->SetVertex(2,meshobj->FindOrAddVertex(vtxarray,pt2,uv2,rgb2,no2,polymat,mface->v3));
814                                         if (nverts==4)
815                                                 poly->SetVertex(3,meshobj->FindOrAddVertex(vtxarray,pt3,uv3,rgb3,no3,polymat,mface->v4));
816                                 }
817                                 meshobj->AddPolygon(poly);
818                                 if (poly->IsCollider())
819                                 {
820                                         RAS_TriangleIndex idx;
821                                         idx.m_index[0] = mface->v1;
822                                         idx.m_index[1] = mface->v2;
823                                         idx.m_index[2] = mface->v3;
824                                         idx.m_collider = collider;
825                                         meshobj->m_triangle_indices.push_back(idx);
826                                         if (nverts==4)
827                                         {
828                                         idx.m_index[0] = mface->v1;
829                                         idx.m_index[1] = mface->v3;
830                                         idx.m_index[2] = mface->v4;
831                                         idx.m_collider = collider;
832                                         meshobj->m_triangle_indices.push_back(idx);
833                                         }
834                                 }
835                                 
836 //                              poly->SetVisibleWireframeEdges(mface->edcode);
837                                 poly->SetCollider(collider);
838                         }
839                 }
840                 if (tface) 
841                         tface++;
842         }
843         meshobj->UpdateMaterialList();
844
845
846
847         // -----------------------------------
848         // pre calculate texture generation
849         for(RAS_MaterialBucket::Set::iterator mit = meshobj->GetFirstMaterial();
850                 mit != meshobj->GetLastMaterial(); ++ mit) {
851                 (*mit)->GetPolyMaterial()->OnConstruction();
852         }
853         // -----------------------------------
854
855
856         return meshobj;
857 }
858
859 static PHY_MaterialProps g_materialProps = {
860         1.0,    // restitution
861         2.0,    // friction 
862         0.0,    // fh spring constant
863         0.0,    // fh damping
864         0.0,    // fh distance
865         false   // sliding material?
866 };
867
868         
869         
870 static PHY_MaterialProps *CreateMaterialFromBlenderObject(struct Object* blenderobject,
871                                                                                                   KX_Scene *kxscene)
872 {
873         PHY_MaterialProps *materialProps = new PHY_MaterialProps;
874         
875         MT_assert(materialProps && "Create physics material properties failed");
876                 
877         Material* blendermat = give_current_material(blenderobject, 0);
878                 
879         if (blendermat)
880         {
881                 MT_assert(0.0f <= blendermat->reflect && blendermat->reflect <= 1.0f);
882         
883                 materialProps->m_restitution = blendermat->reflect;
884                 materialProps->m_friction = blendermat->friction;
885                 materialProps->m_fh_spring = blendermat->fh;
886                 materialProps->m_fh_damping = blendermat->xyfrict;
887                 materialProps->m_fh_distance = blendermat->fhdist;
888                 materialProps->m_fh_normal = (blendermat->dynamode & MA_FH_NOR) != 0;
889         }
890         else {
891                 *materialProps = g_materialProps;
892         }
893         
894         return materialProps;
895 }
896
897 static PHY_ShapeProps *CreateShapePropsFromBlenderObject(struct Object* blenderobject,
898                                                                                                  KX_Scene *kxscene)
899 {
900         PHY_ShapeProps *shapeProps = new PHY_ShapeProps;
901         
902         MT_assert(shapeProps);
903                 
904         shapeProps->m_mass = blenderobject->mass;
905         
906 //  This needs to be fixed in blender. For now, we use:
907         
908 // in Blender, inertia stands for the size value which is equivalent to
909 // the sphere radius
910         shapeProps->m_inertia = blenderobject->formfactor;
911         
912         MT_assert(0.0f <= blenderobject->damping && blenderobject->damping <= 1.0f);
913         MT_assert(0.0f <= blenderobject->rdamping && blenderobject->rdamping <= 1.0f);
914         
915         shapeProps->m_lin_drag = 1.0 - blenderobject->damping;
916         shapeProps->m_ang_drag = 1.0 - blenderobject->rdamping;
917         
918         shapeProps->m_friction_scaling[0] = blenderobject->anisotropicFriction[0]; 
919         shapeProps->m_friction_scaling[1] = blenderobject->anisotropicFriction[1];
920         shapeProps->m_friction_scaling[2] = blenderobject->anisotropicFriction[2];
921         shapeProps->m_do_anisotropic = ((blenderobject->gameflag & OB_ANISOTROPIC_FRICTION) != 0);
922         
923         shapeProps->m_do_fh     = (blenderobject->gameflag & OB_DO_FH) != 0; 
924         shapeProps->m_do_rot_fh = (blenderobject->gameflag & OB_ROT_FH) != 0;
925         
926         return shapeProps;
927 }
928
929         
930         
931         
932                 
933 //////////////////////////////////////////////////////////
934         
935
936
937 static float my_boundbox_mesh(Mesh *me, float *loc, float *size)
938 {
939         MVert *mvert;
940         BoundBox *bb;
941         MT_Point3 min, max;
942         float mloc[3], msize[3];
943         int a;
944         
945         if(me->bb==0) me->bb= (struct BoundBox *)MEM_callocN(sizeof(BoundBox), "boundbox");
946         bb= me->bb;
947         
948         INIT_MINMAX(min, max);
949
950         if (!loc) loc= mloc;
951         if (!size) size= msize;
952         
953         mvert= me->mvert;
954         for(a=0; a<me->totvert; a++, mvert++) {
955                 DO_MINMAX(mvert->co, min, max);
956         }
957                 
958         if(me->totvert) {
959                 loc[0]= (min[0]+max[0])/2.0;
960                 loc[1]= (min[1]+max[1])/2.0;
961                 loc[2]= (min[2]+max[2])/2.0;
962                 
963                 size[0]= (max[0]-min[0])/2.0;
964                 size[1]= (max[1]-min[1])/2.0;
965                 size[2]= (max[2]-min[2])/2.0;
966         }
967         else {
968                 loc[0]= loc[1]= loc[2]= 0.0;
969                 size[0]= size[1]= size[2]= 0.0;
970         }
971                 
972         bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= loc[0]-size[0];
973         bb->vec[4][0]=bb->vec[5][0]=bb->vec[6][0]=bb->vec[7][0]= loc[0]+size[0];
974                 
975         bb->vec[0][1]=bb->vec[1][1]=bb->vec[4][1]=bb->vec[5][1]= loc[1]-size[1];
976         bb->vec[2][1]=bb->vec[3][1]=bb->vec[6][1]=bb->vec[7][1]= loc[1]+size[1];
977
978         bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= loc[2]-size[2];
979         bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= loc[2]+size[2];
980
981         float radius = 0;
982         for (a=0, mvert = me->mvert; a < me->totvert; a++, mvert++)
983         {
984                 float vert_radius = MT_Vector3(mvert->co).length2();
985                 if (vert_radius > radius)
986                         radius = vert_radius;
987         } 
988         return sqrt(radius);
989 }
990                 
991
992
993
994 static void my_tex_space_mesh(Mesh *me)
995                 {
996         KeyBlock *kb;
997         float *fp, loc[3], size[3], min[3], max[3];
998         int a;
999
1000         my_boundbox_mesh(me, loc, size);
1001         
1002         if(me->texflag & AUTOSPACE) {
1003                 if(me->key) {
1004                         kb= me->key->refkey;
1005                         if (kb) {
1006         
1007                                 INIT_MINMAX(min, max);
1008                 
1009                                 fp= (float *)kb->data;
1010                                 for(a=0; a<kb->totelem; a++, fp+=3) {   
1011                                         DO_MINMAX(fp, min, max);
1012                                 }
1013                                 if(kb->totelem) {
1014                                         loc[0]= (min[0]+max[0])/2.0; loc[1]= (min[1]+max[1])/2.0; loc[2]= (min[2]+max[2])/2.0;
1015                                         size[0]= (max[0]-min[0])/2.0; size[1]= (max[1]-min[1])/2.0; size[2]= (max[2]-min[2])/2.0;
1016         } 
1017         else {
1018                                         loc[0]= loc[1]= loc[2]= 0.0;
1019                                         size[0]= size[1]= size[2]= 0.0;
1020                                 }
1021                                 
1022                         }
1023                                 }
1024         
1025                 VECCOPY(me->loc, loc);
1026                 VECCOPY(me->size, size);
1027                 me->rot[0]= me->rot[1]= me->rot[2]= 0.0;
1028         
1029                 if(me->size[0]==0.0) me->size[0]= 1.0;
1030                 else if(me->size[0]>0.0 && me->size[0]<0.00001) me->size[0]= 0.00001;
1031                 else if(me->size[0]<0.0 && me->size[0]> -0.00001) me->size[0]= -0.00001;
1032         
1033                 if(me->size[1]==0.0) me->size[1]= 1.0;
1034                 else if(me->size[1]>0.0 && me->size[1]<0.00001) me->size[1]= 0.00001;
1035                 else if(me->size[1]<0.0 && me->size[1]> -0.00001) me->size[1]= -0.00001;
1036                                                 
1037                 if(me->size[2]==0.0) me->size[2]= 1.0;
1038                 else if(me->size[2]>0.0 && me->size[2]<0.00001) me->size[2]= 0.00001;
1039                 else if(me->size[2]<0.0 && me->size[2]> -0.00001) me->size[2]= -0.00001;
1040         }
1041         
1042 }
1043
1044 static void my_get_local_bounds(Object *ob, float *centre, float *size)
1045 {
1046         BoundBox *bb= NULL;
1047         /* uses boundbox, function used by Ketsji */
1048         switch (ob->type)
1049         {
1050                 case OB_MESH:
1051                         bb= ( (Mesh *)ob->data )->bb;
1052                         if(bb==0) 
1053                         {
1054                                 my_tex_space_mesh((struct Mesh *)ob->data);
1055                                 bb= ( (Mesh *)ob->data )->bb;
1056                         }
1057                         break;
1058                 case OB_CURVE:
1059                 case OB_SURF:
1060                 case OB_FONT:
1061                         centre[0]= centre[1]= centre[2]= 0.0;
1062                         size[0]  = size[1]=size[2]=0.0;
1063                         break;
1064                 case OB_MBALL:
1065                         bb= ob->bb;
1066                         break;
1067         }
1068         
1069         if(bb==NULL) 
1070         {
1071                 centre[0]= centre[1]= centre[2]= 0.0;
1072                 size[0] = size[1]=size[2]=1.0;
1073         }
1074         else 
1075         {
1076                 size[0]= 0.5*fabs(bb->vec[0][0] - bb->vec[4][0]);
1077                 size[1]= 0.5*fabs(bb->vec[0][1] - bb->vec[2][1]);
1078                 size[2]= 0.5*fabs(bb->vec[0][2] - bb->vec[1][2]);
1079                                         
1080                 centre[0]= 0.5*(bb->vec[0][0] + bb->vec[4][0]);
1081                 centre[1]= 0.5*(bb->vec[0][1] + bb->vec[2][1]);
1082                 centre[2]= 0.5*(bb->vec[0][2] + bb->vec[1][2]);
1083         }
1084 }
1085         
1086
1087
1088
1089 //////////////////////////////////////////////////////
1090
1091
1092
1093
1094
1095 void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
1096                                                  struct Object* blenderobject,
1097                                                  RAS_MeshObject* meshobj,
1098                                                  KX_Scene* kxscene,
1099                                                  int activeLayerBitInfo,
1100                                                  e_PhysicsEngine        physics_engine,
1101                                                  KX_BlenderSceneConverter *converter
1102                                                  )
1103                                         
1104 {
1105         //SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/
1106         //int userigidbody = SYS_GetCommandLineInt(syshandle,"norigidbody",0);
1107         //bool bRigidBody = (userigidbody == 0);
1108
1109         PHY_ShapeProps* shapeprops =
1110                         CreateShapePropsFromBlenderObject(blenderobject, 
1111                         kxscene);
1112
1113         
1114         PHY_MaterialProps* smmaterial = 
1115                 CreateMaterialFromBlenderObject(blenderobject, kxscene);
1116                                         
1117         KX_ObjectProperties objprop;
1118         if ((objprop.m_isactor = (blenderobject->gameflag & OB_ACTOR)!=0))
1119         {
1120                 objprop.m_dyna = (blenderobject->gameflag & OB_DYNAMIC) != 0;
1121                 objprop.m_angular_rigidbody = (blenderobject->gameflag & OB_RIGID_BODY) != 0;
1122                 objprop.m_ghost = (blenderobject->gameflag & OB_GHOST) != 0;
1123         } else {
1124                 objprop.m_dyna = false;
1125                 objprop.m_angular_rigidbody = false;
1126                 objprop.m_ghost = false;
1127         }
1128         //mmm, for now, taks this for the size of the dynamicobject
1129         // Blender uses inertia for radius of dynamic object
1130         objprop.m_radius = blenderobject->inertia;
1131         objprop.m_in_active_layer = (blenderobject->lay & activeLayerBitInfo) != 0;
1132         objprop.m_dynamic_parent=NULL;
1133         objprop.m_isdeformable = ((blenderobject->gameflag2 & 2)) != 0;
1134         objprop.m_boundclass = objprop.m_dyna?KX_BOUNDSPHERE:KX_BOUNDMESH;
1135         
1136         KX_BoxBounds bb;
1137         my_get_local_bounds(blenderobject,objprop.m_boundobject.box.m_center,bb.m_extends);
1138         if (blenderobject->gameflag & OB_BOUNDS)
1139         {
1140                 switch (blenderobject->boundtype)
1141                 {
1142                         case OB_BOUND_BOX:
1143                                 objprop.m_boundclass = KX_BOUNDBOX;
1144                                 //mmm, has to be divided by 2 to be proper extends
1145                                 objprop.m_boundobject.box.m_extends[0]=2.f*bb.m_extends[0];
1146                                 objprop.m_boundobject.box.m_extends[1]=2.f*bb.m_extends[1];
1147                                 objprop.m_boundobject.box.m_extends[2]=2.f*bb.m_extends[2];
1148                                 break;
1149                         case OB_BOUND_POLYT:
1150                                 if (blenderobject->type == OB_MESH)
1151                                 {
1152                                         objprop.m_boundclass = KX_BOUNDPOLYTOPE;
1153                                         break;
1154                                 }
1155                                 // Object is not a mesh... fall through OB_BOUND_POLYH to 
1156                                 // OB_BOUND_SPHERE
1157                         case OB_BOUND_POLYH:
1158                                 if (blenderobject->type == OB_MESH)
1159                                 {
1160                                         objprop.m_boundclass = KX_BOUNDMESH;
1161                                         break;
1162                                 }
1163                                 // Object is not a mesh... can't use polyheder. 
1164                                 // Fall through and become a sphere.
1165                         case OB_BOUND_SPHERE:
1166                         {
1167                                 objprop.m_boundclass = KX_BOUNDSPHERE;
1168                                 objprop.m_boundobject.c.m_radius = MT_max(bb.m_extends[0], MT_max(bb.m_extends[1], bb.m_extends[2]));
1169                                 break;
1170                         }
1171                         case OB_BOUND_CYLINDER:
1172                         {
1173                                 objprop.m_boundclass = KX_BOUNDCYLINDER;
1174                                 objprop.m_boundobject.c.m_radius = MT_max(bb.m_extends[0], bb.m_extends[1]);
1175                                 objprop.m_boundobject.c.m_height = 2.f*bb.m_extends[2];
1176                                 break;
1177                         }
1178                         case OB_BOUND_CONE:
1179                         {
1180                                 objprop.m_boundclass = KX_BOUNDCONE;
1181                                 objprop.m_boundobject.c.m_radius = MT_max(bb.m_extends[0], bb.m_extends[1]);
1182                                 objprop.m_boundobject.c.m_height = 2.f*bb.m_extends[2];
1183                                 break;
1184                         }
1185                 }
1186         }
1187
1188         // get Root Parent of blenderobject
1189         struct Object* parent= blenderobject->parent;
1190         while(parent && parent->parent) {
1191                 parent= parent->parent;
1192         }
1193
1194         if (parent && (parent->gameflag & OB_DYNAMIC)) {
1195                 
1196                 KX_GameObject *parentgameobject = converter->FindGameObject(parent);
1197                 objprop.m_dynamic_parent = parentgameobject;
1198
1199         }
1200
1201         objprop.m_concave = (blenderobject->boundtype & 4) != 0;
1202         
1203         switch (physics_engine)
1204         {
1205 #ifdef USE_BULLET
1206                 case UseBullet:
1207                         KX_ConvertBulletObject(gameobj, meshobj, kxscene, shapeprops, smmaterial, &objprop);
1208                         break;
1209
1210 #endif
1211 #ifdef USE_SUMO_SOLID
1212                 case UseSumo:
1213                         KX_ConvertSumoObject(gameobj, meshobj, kxscene, shapeprops, smmaterial, &objprop);
1214                         break;
1215 #endif
1216                         
1217 #ifdef USE_ODE
1218                 case UseODE:
1219                         KX_ConvertODEEngineObject(gameobj, meshobj, kxscene, shapeprops, smmaterial, &objprop);
1220                         break;
1221 #endif //USE_ODE
1222
1223                 case UseDynamo:
1224                         //KX_ConvertDynamoObject(gameobj,meshobj,kxscene,shapeprops,    smmaterial,     &objprop);
1225                         break;
1226                         
1227                 case UseNone:
1228                 default:
1229                         break;
1230         }
1231
1232 }
1233
1234
1235
1236
1237
1238 static KX_LightObject *gamelight_from_blamp(Lamp *la, unsigned int layerflag, KX_Scene *kxscene, RAS_IRenderTools *rendertools, KX_BlenderSceneConverter *converter) {
1239         RAS_LightObject lightobj;
1240         KX_LightObject *gamelight;
1241         
1242         lightobj.m_att1 = la->att1;
1243         lightobj.m_att2 = (la->mode & LA_QUAD)?la->att2:0.0;
1244         lightobj.m_red = la->r;
1245         lightobj.m_green = la->g;
1246         lightobj.m_blue = la->b;
1247         lightobj.m_distance = la->dist;
1248         lightobj.m_energy = la->energy;
1249         lightobj.m_layer = layerflag;
1250         lightobj.m_spotblend = la->spotblend;
1251         lightobj.m_spotsize = la->spotsize;
1252         
1253         lightobj.m_nodiffuse = (la->mode & LA_NO_DIFF) != 0;
1254         lightobj.m_nospecular = (la->mode & LA_NO_SPEC) != 0;
1255         
1256         if (la->mode & LA_NEG)
1257         {
1258                 lightobj.m_red = -lightobj.m_red;
1259                 lightobj.m_green = -lightobj.m_green;
1260                 lightobj.m_blue = -lightobj.m_blue;
1261         }
1262                 
1263         if (la->type==LA_SUN) {
1264                 lightobj.m_type = RAS_LightObject::LIGHT_SUN;
1265         } else if (la->type==LA_SPOT) {
1266                 lightobj.m_type = RAS_LightObject::LIGHT_SPOT;
1267         } else {
1268                 lightobj.m_type = RAS_LightObject::LIGHT_NORMAL;
1269         }
1270         
1271         gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rendertools, lightobj);
1272         BL_ConvertLampIpos(la, gamelight, converter);
1273         
1274         return gamelight;
1275 }
1276
1277 static KX_Camera *gamecamera_from_bcamera(Camera *ca, KX_Scene *kxscene, KX_BlenderSceneConverter *converter) {
1278         RAS_CameraData camdata(ca->lens, ca->clipsta, ca->clipend, ca->type == CAM_PERSP);
1279         KX_Camera *gamecamera;
1280         
1281         gamecamera= new KX_Camera(kxscene, KX_Scene::m_callbacks, camdata);
1282         gamecamera->SetName(ca->id.name + 2);
1283         
1284         BL_ConvertCameraIpos(ca, gamecamera, converter);
1285         
1286         return gamecamera;
1287 }
1288
1289 static KX_GameObject *gameobject_from_blenderobject(
1290                                                                 Object *ob, 
1291                                                                 KX_Scene *kxscene, 
1292                                                                 RAS_IRenderTools *rendertools, 
1293                                                                 KX_BlenderSceneConverter *converter,
1294                                                                 Scene *blenderscene) 
1295 {
1296         KX_GameObject *gameobj = NULL;
1297         
1298         switch(ob->type)
1299         {
1300         case OB_LAMP:
1301         {
1302                 KX_LightObject* gamelight= gamelight_from_blamp(static_cast<Lamp*>(ob->data), ob->lay, kxscene, rendertools, converter);
1303                 gameobj = gamelight;
1304                 
1305                 gamelight->AddRef();
1306                 kxscene->GetLightList()->Add(gamelight);
1307                 
1308                 break;
1309         }
1310         
1311         case OB_CAMERA:
1312         {
1313                 KX_Camera* gamecamera = gamecamera_from_bcamera(static_cast<Camera*>(ob->data), kxscene, converter);
1314                 gameobj = gamecamera;
1315                 
1316                 gamecamera->AddRef();
1317                 kxscene->AddCamera(gamecamera);
1318                 
1319                 break;
1320         }
1321         
1322         case OB_MESH:
1323         {
1324                 Mesh* mesh = static_cast<Mesh*>(ob->data);
1325                 RAS_MeshObject* meshobj = converter->FindGameMesh(mesh, ob->lay);
1326                 float centre[3], extents[3];
1327                 float radius = my_boundbox_mesh((Mesh*) ob->data, centre, extents);
1328                 
1329                 if (!meshobj) {
1330                         meshobj = BL_ConvertMesh(mesh,ob,rendertools,kxscene,converter);
1331                         converter->RegisterGameMesh(meshobj, mesh);
1332                 }
1333                 
1334                 // needed for python scripting
1335                 kxscene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj);
1336         
1337                 gameobj = new BL_DeformableGameObject(kxscene,KX_Scene::m_callbacks);
1338         
1339                 // set transformation
1340                 gameobj->AddMesh(meshobj);
1341         
1342                 // for all objects: check whether they want to
1343                 // respond to updates
1344                 bool ignoreActivityCulling =  
1345                         ((ob->gameflag2 & OB_NEVER_DO_ACTIVITY_CULLING)!=0);
1346                 gameobj->SetIgnoreActivityCulling(ignoreActivityCulling);
1347         
1348                 //      If this is a skin object, make Skin Controller
1349                 if (ob->parent && ob->parent->type == OB_ARMATURE && ob->partype==PARSKEL && ((Mesh*)ob->data)->dvert){
1350                         BL_SkinDeformer *dcont = new BL_SkinDeformer(ob, (BL_SkinMeshObject*)meshobj );                         
1351                         ((BL_DeformableGameObject*)gameobj)->m_pDeformer = dcont;
1352                 }
1353                 else if (((Mesh*)ob->data)->dvert){
1354                         BL_MeshDeformer *dcont = new BL_MeshDeformer(ob, (BL_SkinMeshObject*)meshobj );
1355                         ((BL_DeformableGameObject*)gameobj)->m_pDeformer = dcont;
1356                 }
1357                 
1358                 MT_Point3 min = MT_Point3(centre) - MT_Vector3(extents);
1359                 MT_Point3 max = MT_Point3(centre) + MT_Vector3(extents);
1360                 SG_BBox bbox = SG_BBox(min, max);
1361                 gameobj->GetSGNode()->SetBBox(bbox);
1362                 gameobj->GetSGNode()->SetRadius(radius);
1363         
1364                 break;
1365         }
1366         
1367         case OB_ARMATURE:
1368         {
1369                 gameobj = new BL_ArmatureObject(
1370                         kxscene,
1371                         KX_Scene::m_callbacks,
1372                         ob // handle
1373                 );
1374                 /* Get the current pose from the armature object and apply it as the rest pose */
1375                 break;
1376         }
1377         
1378         case OB_EMPTY:
1379         {
1380                 gameobj = new KX_EmptyObject(kxscene,KX_Scene::m_callbacks);
1381                 // set transformation
1382                 break;
1383         }
1384         }
1385         
1386         return gameobj;
1387 }
1388
1389 struct parentChildLink {
1390         struct Object* m_blenderchild;
1391         SG_Node* m_gamechildnode;
1392 };
1393
1394         /**
1395          * Find the specified scene by name, or the first
1396          * scene if nothing matches (shouldn't happen).
1397          */
1398 static struct Scene *GetSceneForName(struct Main *maggie, const STR_String& scenename) {
1399         Scene *sce;
1400
1401         for (sce= (Scene*) maggie->scene.first; sce; sce= (Scene*) sce->id.next)
1402                 if (scenename == (sce->id.name+2))
1403                         return sce;
1404
1405         return (Scene*) maggie->scene.first;
1406 }
1407
1408
1409 // convert blender objects into ketsji gameobjects
1410 void BL_ConvertBlenderObjects(struct Main* maggie,
1411                                                           const STR_String& scenename,
1412                                                           KX_Scene* kxscene,
1413                                                           KX_KetsjiEngine* ketsjiEngine,
1414                                                           e_PhysicsEngine       physics_engine,
1415                                                           PyObject* pythondictionary,
1416                                                           SCA_IInputDevice* keydev,
1417                                                           RAS_IRenderTools* rendertools,
1418                                                           RAS_ICanvas* canvas,
1419                                                           KX_BlenderSceneConverter* converter,
1420                                                           bool alwaysUseExpandFraming
1421                                                           )
1422 {       
1423
1424         Scene *blenderscene = GetSceneForName(maggie, scenename);
1425
1426         // Get the frame settings of the canvas.
1427         // Get the aspect ratio of the canvas as designed by the user.
1428
1429         RAS_FrameSettings::RAS_FrameType frame_type;
1430         int aspect_width;
1431         int aspect_height;
1432         
1433         if (alwaysUseExpandFraming) {
1434                 frame_type = RAS_FrameSettings::e_frame_extend;
1435                 aspect_width = canvas->GetWidth();
1436                 aspect_height = canvas->GetHeight();
1437         } else {
1438                 if (blenderscene->framing.type == SCE_GAMEFRAMING_BARS) {
1439                         frame_type = RAS_FrameSettings::e_frame_bars;
1440                 } else if (blenderscene->framing.type == SCE_GAMEFRAMING_EXTEND) {
1441                         frame_type = RAS_FrameSettings::e_frame_extend;
1442                 } else {
1443                         frame_type = RAS_FrameSettings::e_frame_scale;
1444                 }
1445                 
1446                 aspect_width = blenderscene->r.xsch;
1447                 aspect_height = blenderscene->r.ysch;
1448         }
1449         
1450         RAS_FrameSettings frame_settings(
1451                 frame_type,
1452                 blenderscene->framing.col[0],
1453                 blenderscene->framing.col[1],
1454                 blenderscene->framing.col[2],
1455                 aspect_width,
1456                 aspect_height
1457         );
1458         kxscene->SetFramingType(frame_settings);
1459
1460         kxscene->SetGravity(MT_Vector3(0,0,(blenderscene->world != NULL) ? -blenderscene->world->gravity : -9.8));
1461         
1462         /* set activity culling parameters */
1463         if (blenderscene->world) {
1464                 kxscene->SetActivityCulling( (blenderscene->world->mode & WO_ACTIVITY_CULLING) != 0);
1465                 kxscene->SetActivityCullingRadius(blenderscene->world->activityBoxRadius);
1466         } else {
1467                 kxscene->SetActivityCulling(false);
1468         }
1469         
1470         int activeLayerBitInfo = blenderscene->lay;
1471         
1472         // templist to find Root Parents (object with no parents)
1473         CListValue* templist = new CListValue();
1474         CListValue*     sumolist = new CListValue();
1475         
1476         vector<parentChildLink> vec_parent_child;
1477         
1478         CListValue* objectlist = kxscene->GetObjectList();
1479         CListValue* parentlist = kxscene->GetRootParentList();
1480         
1481         SCA_LogicManager* logicmgr = kxscene->GetLogicManager();
1482         SCA_TimeEventManager* timemgr = kxscene->GetTimeEventManager();
1483         
1484         CListValue* logicbrick_conversionlist = new CListValue();
1485         
1486         SG_TreeFactory tf;
1487         
1488         // Convert actions to actionmap
1489         bAction *curAct;
1490         for (curAct = (bAction*)maggie->action.first; curAct; curAct=(bAction*)curAct->id.next)
1491         {
1492                 logicmgr->RegisterActionName(curAct->id.name, curAct);
1493         }
1494
1495         SetDefaultFaceType(blenderscene);
1496         
1497         Base *base = static_cast<Base*>(blenderscene->base.first);
1498         while(base)
1499         {
1500                 Object* blenderobject = base->object;
1501                 KX_GameObject* gameobj = gameobject_from_blenderobject(
1502                                                                                 base->object, 
1503                                                                                 kxscene, 
1504                                                                                 rendertools, 
1505                                                                                 converter,
1506                                                                                 blenderscene);
1507                                                                                         
1508                 if (gameobj)
1509                 {
1510                         MT_Point3 pos = MT_Point3(
1511                                 blenderobject->loc[0]+blenderobject->dloc[0],
1512                                 blenderobject->loc[1]+blenderobject->dloc[1],
1513                                 blenderobject->loc[2]+blenderobject->dloc[2]
1514                         );
1515                         MT_Vector3 eulxyz = MT_Vector3(
1516                                 blenderobject->rot[0],
1517                                 blenderobject->rot[1],
1518                                 blenderobject->rot[2]
1519                         );
1520                         MT_Vector3 scale = MT_Vector3(
1521                                 blenderobject->size[0],
1522                                 blenderobject->size[1],
1523                                 blenderobject->size[2]
1524                         );
1525                         
1526                         gameobj->NodeSetLocalPosition(pos);
1527                         gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz));
1528                         gameobj->NodeSetLocalScale(scale);
1529                         gameobj->NodeUpdateGS(0,true);
1530                         
1531                         BL_ConvertIpos(blenderobject,gameobj,converter);
1532                         // TODO: expand to multiple ipos per mesh
1533                         Material *mat = give_current_material(blenderobject, 1);
1534                         if(mat) BL_ConvertMaterialIpos(mat, gameobj, converter);        
1535         
1536                         bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) !=0;
1537         
1538                         sumolist->Add(gameobj->AddRef());
1539                         
1540                         BL_ConvertProperties(blenderobject,gameobj,timemgr,kxscene,isInActiveLayer);
1541                         
1542         
1543                         gameobj->SetName(blenderobject->id.name);
1544         
1545                         // templist to find Root Parents (object with no parents)
1546                         templist->Add(gameobj->AddRef());
1547                         
1548                         // update children/parent hierarchy
1549                         if (blenderobject->parent != 0)
1550                         {
1551                                 // blender has an additional 'parentinverse' offset in each object
1552                                 SG_Node* parentinversenode = new SG_Node(NULL,NULL,SG_Callbacks());
1553                         
1554                                 // define a normal parent relationship for this node.
1555                                 KX_NormalParentRelation * parent_relation = KX_NormalParentRelation::New();
1556                                 parentinversenode->SetParentRelation(parent_relation);
1557         
1558                                 parentChildLink pclink;
1559                                 pclink.m_blenderchild = blenderobject;
1560                                 pclink.m_gamechildnode = parentinversenode;
1561                                 vec_parent_child.push_back(pclink);
1562
1563                                 float* fl = (float*) blenderobject->parentinv;
1564                                 MT_Transform parinvtrans(fl);
1565                                 parentinversenode->SetLocalPosition(parinvtrans.getOrigin());
1566                                 parentinversenode->SetLocalOrientation(parinvtrans.getBasis());
1567                                 
1568                                 parentinversenode->AddChild(gameobj->GetSGNode());
1569                         }
1570                         
1571                         // needed for python scripting
1572                         logicmgr->RegisterGameObjectName(gameobj->GetName(),gameobj);
1573
1574                         // needed for dynamic object morphing
1575                         logicmgr->RegisterGameObj(gameobj, blenderobject);
1576                         for (int i = 0; i < gameobj->GetMeshCount(); i++)
1577                                 logicmgr->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), blenderobject);
1578         
1579                         converter->RegisterGameObject(gameobj, blenderobject);  
1580                         
1581                         // this was put in rapidly, needs to be looked at more closely
1582                         // only draw/use objects in active 'blender' layers
1583         
1584                         logicbrick_conversionlist->Add(gameobj->AddRef());
1585                         
1586                         if (isInActiveLayer)
1587                         {
1588                                 objectlist->Add(gameobj->AddRef());
1589                                 tf.Add(gameobj->GetSGNode());
1590                                 
1591                                 gameobj->NodeUpdateGS(0,true);
1592                                 gameobj->Bucketize();
1593                                 
1594                         }
1595                         
1596                 }
1597                         
1598                 base = base->next;
1599         }
1600
1601         if (blenderscene->camera) {
1602                 KX_Camera *gamecamera= (KX_Camera*) converter->FindGameObject(blenderscene->camera);
1603                 
1604                 kxscene->SetActiveCamera(gamecamera);
1605         }
1606
1607         //      Set up armatures
1608         for (base = static_cast<Base*>(blenderscene->base.first); base; base=base->next){
1609                 if (base->object->type==OB_MESH){
1610                         Mesh *me = (Mesh*)base->object->data;
1611         
1612                         if (me->dvert){
1613                                 KX_GameObject *obj = converter->FindGameObject(base->object);
1614         
1615                                 if (base->object->parent && base->object->parent->type==OB_ARMATURE && base->object->partype==PARSKEL){
1616                                         KX_GameObject *par = converter->FindGameObject(base->object->parent);
1617                                         if (par)
1618                                                 ((BL_SkinDeformer*)(((BL_DeformableGameObject*)obj)->m_pDeformer))->SetArmature((BL_ArmatureObject*) par);
1619                                 }
1620                         }
1621                 }
1622         }
1623         
1624         // create hierarchy information
1625         int i;
1626         vector<parentChildLink>::iterator pcit;
1627         
1628         for (pcit = vec_parent_child.begin();!(pcit==vec_parent_child.end());++pcit)
1629         {
1630         
1631                 struct Object* blenderchild = pcit->m_blenderchild;
1632                 switch (blenderchild->partype)
1633                 {
1634                         case PARVERT1:
1635                         {
1636                                 // creat a new vertex parent relationship for this node.
1637                                 KX_VertexParentRelation * vertex_parent_relation = KX_VertexParentRelation::New();
1638                                 pcit->m_gamechildnode->SetParentRelation(vertex_parent_relation);
1639                                 break;
1640                         }
1641                         case PARSLOW:
1642                         {
1643                                 // creat a new slow parent relationship for this node.
1644                                 KX_SlowParentRelation * slow_parent_relation = KX_SlowParentRelation::New(blenderchild->sf);
1645                                 pcit->m_gamechildnode->SetParentRelation(slow_parent_relation);
1646                                 break;
1647                         }       
1648                         case PARBONE:
1649                         {
1650                                 // parent this to a bone
1651                                 Bone *parent_bone = get_named_bone(get_armature(blenderchild->parent), blenderchild->parsubstr);
1652                                 KX_BoneParentRelation *bone_parent_relation = KX_BoneParentRelation::New(parent_bone);
1653                                 pcit->m_gamechildnode->SetParentRelation(bone_parent_relation);
1654                         
1655                                 break;
1656                         }
1657                         case PARSKEL: // skinned - ignore
1658                                 break;
1659                         case PAROBJECT:
1660                         case PARCURVE:
1661                         case PARKEY:
1662                         case PARVERT3:
1663                         default:
1664                                 // unhandled
1665                                 break;
1666                 }
1667         
1668                 struct Object* blenderparent = blenderchild->parent;
1669                 KX_GameObject* parentobj = converter->FindGameObject(blenderparent);
1670                 if (parentobj)
1671                 {
1672                         parentobj->     GetSGNode()->AddChild(pcit->m_gamechildnode);
1673                 }
1674         }
1675         vec_parent_child.clear();
1676         
1677         // find 'root' parents (object that has not parents in SceneGraph)
1678         for (i=0;i<templist->GetCount();++i)
1679         {
1680                 KX_GameObject* gameobj = (KX_GameObject*) templist->GetValue(i);
1681                 if (gameobj->GetSGNode()->GetSGParent() == 0)
1682                 {
1683                         parentlist->Add(gameobj->AddRef());
1684                         gameobj->NodeUpdateGS(0,true);
1685                 }
1686         }
1687         
1688         // create physics information
1689         for (i=0;i<sumolist->GetCount();i++)
1690         {
1691                 KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
1692                 struct Object* blenderobject = converter->FindBlenderObject(gameobj);
1693                 int nummeshes = gameobj->GetMeshCount();
1694                 RAS_MeshObject* meshobj = 0;
1695
1696                 if (nummeshes > 0)
1697                 {
1698                         meshobj = gameobj->GetMesh(0);
1699                 }
1700
1701                 BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,activeLayerBitInfo,physics_engine,converter);
1702
1703         }
1704         
1705         templist->Release();
1706         sumolist->Release();    
1707
1708
1709         int executePriority=0; /* incremented by converter routines */
1710         
1711         // convert global sound stuff
1712
1713         /* XXX, glob is the very very wrong place for this
1714          * to be, re-enable once the listener has been moved into
1715          * the scene. */
1716 #if 1
1717         SND_Scene* soundscene = kxscene->GetSoundScene();
1718         SND_SoundListener* listener = soundscene->GetListener();
1719         if (listener && G.listener)
1720         {
1721                 listener->SetDopplerFactor(G.listener->dopplerfactor);
1722                 listener->SetDopplerVelocity(G.listener->dopplervelocity);
1723                 listener->SetGain(G.listener->gain);
1724         }
1725 #endif
1726
1727         // convert world
1728         KX_WorldInfo* worldinfo = new BlenderWorldInfo(blenderscene->world);
1729         converter->RegisterWorldInfo(worldinfo);
1730         kxscene->SetWorldInfo(worldinfo);
1731
1732 #define CONVERT_LOGIC
1733 #ifdef CONVERT_LOGIC
1734         // convert logic bricks, sensors, controllers and actuators
1735         for (i=0;i<logicbrick_conversionlist->GetCount();i++)
1736         {
1737                 KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
1738                 struct Object* blenderobj = converter->FindBlenderObject(gameobj);
1739                 bool isInActiveLayer = (blenderobj->lay & activeLayerBitInfo)!=0;
1740                 BL_ConvertActuators(maggie->name, blenderobj,gameobj,logicmgr,kxscene,ketsjiEngine,executePriority, activeLayerBitInfo,isInActiveLayer,rendertools,converter);
1741         }
1742         for ( i=0;i<logicbrick_conversionlist->GetCount();i++)
1743         {
1744                 KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
1745                 struct Object* blenderobj = converter->FindBlenderObject(gameobj);
1746                 bool isInActiveLayer = (blenderobj->lay & activeLayerBitInfo)!=0;
1747                 BL_ConvertControllers(blenderobj,gameobj,logicmgr,pythondictionary,executePriority,activeLayerBitInfo,isInActiveLayer,converter);
1748         }
1749         for ( i=0;i<logicbrick_conversionlist->GetCount();i++)
1750         {
1751                 KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
1752                 struct Object* blenderobj = converter->FindBlenderObject(gameobj);
1753                 bool isInActiveLayer = (blenderobj->lay & activeLayerBitInfo)!=0;
1754                 BL_ConvertSensors(blenderobj,gameobj,logicmgr,kxscene,keydev,executePriority,activeLayerBitInfo,isInActiveLayer,canvas,converter);
1755         }
1756 #endif //CONVERT_LOGIC
1757
1758         logicbrick_conversionlist->Release();
1759         
1760         // Calculate the scene btree -
1761         // too slow - commented out.
1762         //kxscene->SetNodeTree(tf.MakeTree());
1763 }
1764