// this have to be called after all scenes created their groups void gkBlenderSceneConverter::convertGroupInstances() { m_gscene = static_cast<gkScene*>(gkSceneManager::getSingleton().getByName(gkResourceName(GKB_IDNAME(m_bscene), m_groupName))); if (m_gscene) { gkGroupManager* mgr = gkGroupManager::getSingletonPtr(); utArray<Blender::Object*> groups; for (Blender::Base* base = (Blender::Base*)m_bscene->base.first; base; base = base->next) { if (!base->object) continue; Blender::Object* bobj = base->object; // non - conversion object if (!validObject(bobj)) continue; // only concentrate on the group-instances if ( (bobj->transflag & OB_DUPLIGROUP) && bobj->dup_group != 0) groups.push_back(bobj); } // Process user created groups. utArray<Blender::Object*>::Iterator it = groups.iterator(); while (it.hasMoreElements()) { Blender::Object* bobj = it.getNext(); // Should not fail GK_ASSERT((bobj->transflag& OB_DUPLIGROUP && bobj->dup_group != 0)); // Owning group Blender::Group* bgobj = bobj->dup_group; const gkResourceName groupName(GKB_IDNAME(bgobj), m_groupName); if (mgr->exists(groupName)) { gkGameObjectGroup* ggobj = (gkGameObjectGroup*)mgr->getByName(groupName); gkGameObjectInstance* inst = ggobj->createGroupInstance(m_gscene, gkResourceName(GKB_IDNAME(bobj), m_groupName),0,bobj->lay); inst->getRoot()->_makeGroup(ggobj); inst->getRoot()->_makeGroupInstance(inst); if (inst) convertObject(bobj, inst->getRoot()); } } } else { gkLogger::write("CAUTION:Calling gkBlenderSceneConverter::convertGroupInstance() without calling convert(false) before doesn't work! No group-instances created!",true); } }
void gkAnimationSequence::addItem(const gkHashedString &animation, const akScalar& start, const akScalar& end, const akScalar& blendin, const akScalar& blendout) { gkAnimation* anim = gkAnimationManager::getSingleton().getAnimation(gkResourceName(animation, getGroupName())); if (anim) addItem(anim->getInternal(), start, end, blendin, blendout); }
void gkAnimationLoader::convertAction24(Blender::bAction* action, gkScalar animfps) { // 2.4x actions are always Pose actions gkKeyedAnimation* act = gkAnimationManager::getSingleton().createKeyedAnimation(gkResourceName(GKB_IDNAME(action), m_groupName)); if(!act) return; // min/max gkScalar start, end; get24ActionStartEnd(action, start, end); Blender::bActionChannel* bac = (Blender::bActionChannel*)action->chanbase.first; while (bac) { gkBoneChannel* chan = new gkBoneChannel(bac->name, act); act->addChannel(chan); if (bac->ipo) convertActionIpo(bac->ipo, chan, start, animfps); bac = bac->next; } // apply time range act->setLength( (end-start)/animfps); }
void gkActionActuator::doInit(void) { m_action = m_object->getAnimationPlayer(m_startAct); if (!m_action) { gkAnimation* res = gkAnimationManager::getSingleton().getAnimation(gkResourceName(m_startAct, getObjectGroupName())); if(res) m_action = m_object->addAnimation(res, m_startAct); } if (m_action) { if (m_start > m_end) { m_start = 0; m_end = m_action->getLength(); } //if (m_mode == AA_PLAY) m_action->setMode(AK_ACT_END); //else // m_action->setMode(AK_ACT_LOOP); } resetAction(); }
void gkParticleConverter::convertParticle(Blender::ParticleSettings* pt) { if (!pt || !pt->effector_weights) return; if (pt->ren_as == PART_DRAW_NOT) return; Blender::EffectorWeights* wt = pt->effector_weights; gkParticleSettingsProperties pp; pp.m_phyType = pt->phystype; pp.m_name = GKB_IDNAME(pt); pp.m_emitfrom = pt->from; pp.m_amount = pt->totpart; pp.m_lifetime = pt->lifetime/m_fps; pp.m_start = pt->sta/m_fps; pp.m_end = pt->end/m_fps; pp.m_random = pt->randlife; pp.m_jitter = pt->jitfac; pp.m_velocity = gkVector3(pt->ob_vel[0], pt->ob_vel[1], pt->ob_vel[2])*10; pp.m_velNormal = pt->normfac; pp.m_velTanget = pt->tanfac; pp.m_size = pt->size*10; pp.m_mass = pt->mass; pp.m_sizeRandom = pt->randsize; pp.m_gravity = wt->global_gravity; pp.m_trailCount = pt->trail_count; pp.m_drawEmitter = (pt->draw & 0x8) != 0; pp.m_material = pt->omat - 1; if (pt->ren_as == PART_DRAW_HALO) pp.m_render = gkParticleSettingsProperties::R_HALO; else if (pt->ren_as == PART_DRAW_BB) pp.m_render = gkParticleSettingsProperties::R_BILLBOARD; else if (pt->ren_as == PART_DRAW_OB) pp.m_render = gkParticleSettingsProperties::R_OBJECT; else if (pt->ren_as == PART_DRAW_GR) pp.m_render = gkParticleSettingsProperties::R_GROUP; else if (pt->ren_as == PART_DRAW_LINE) pp.m_render = gkParticleSettingsProperties::R_LINE; else if (pt->ren_as == PART_DRAW_PATH) pp.m_render = gkParticleSettingsProperties::R_PATH; //else if (pt->ren_as == PART_DRAW_NOT) // pp.m_render = gkParticleSettingsProperties::R_NONE; gkParticleManager::getSingleton().createParticle(gkResourceName(pp.m_name, m_groupName), pp); }
void gkScene::postCreateInstanceImpl(void) { #ifdef OGREKIT_USE_LUA gkLuaScript* script = gkLuaManager::getSingleton().getByName<gkLuaScript>(gkResourceName(DEFAULT_STARTUP_LUA_FILE, getGroupName())); if (script) script->execute(); #endif }
void gkExpressionController::setExpression(const gkString& str) { gkString expr = "return " + str + "\n"; gkLuaScript* scrpt = gkLuaManager::getSingleton().createFromText( gkResourceName(gkUtils::getUniqueName(m_name), getObjectGroupName()), expr); if (scrpt) m_script = scrpt; }
gkParticleObject* gkScene::createParticleObject(const gkHashedString& name) { if (m_objects.find(name) != GK_NPOS) { gkPrintf("Scene: Duplicate object '%s' found\n", name.str().c_str()); return 0; } gkParticleObject* gobj = gkGameObjectManager::getSingleton().createParticleObject(gkResourceName(name, getGroupName())); addObject(gobj); return gobj; }
void gkOgreParticleObject::createInstanceImpl() { gkParticleObject::createInstanceImpl(); GK_ASSERT(!m_psys); try { Ogre::SceneManager* manager = m_scene->getManager(); const gkString& pname = m_particleProps.m_settings; m_psys = manager->createParticleSystem(getName(), m_particleProps.m_settings); if (m_psys) { m_psys->setUserAny(Ogre::Any(this)); m_node->attachObject(m_psys); gkOgreParticleResource* resource = gkParticleManager::getSingleton().getByName<gkOgreParticleResource>( gkResourceName(pname, getGroupName())); if (resource && resource->isTemplateOwner()) { m_psys->setRenderer(gkOgreParticleRenderer::NAME); if (resource->getParticleProperties().m_render == gkParticleSettingsProperties::R_HALO) m_psys->setMaterialName(gkParticleManager::getSingleton().createOrRetrieveHaloMaterial(m_particleProps.m_material)); else m_psys->setMaterialName(m_particleProps.m_material); } //else create by .particle script } } catch (Ogre::Exception& e) { gkLogMessage("gkOgreParticleObject: " << e.getDescription()); } }
void gkAnimationLoader::convertAction25(Blender::bAction* action, gkScalar animfps) { gkKeyedAnimation* act = gkAnimationManager::getSingleton().createKeyedAnimation(gkResourceName(GKB_IDNAME(action), m_groupName)); if(!act) return; // min/max gkScalar start, end; get25ActionStartEnd(action, start, end); Blender::FCurve* bfc = (Blender::FCurve*)action->curves.first; while (bfc) { utString rnap (bfc->rna_path); utString chan_name; utString transform_name; printf("rnap = %s \n",rnap.c_str()); akAnimationChannel* chan; // Pose action if (rnap.substr(0, 10) == "pose.bones") { // TODO use regex? size_t i = rnap.rfind('\"'); chan_name = rnap.substr(12, i - 12); transform_name = rnap.substr(i + 3, rnap.length() - i + 3); chan = act->getChannel(chan_name); if(!chan) { chan = new gkBoneChannel(chan_name, act); act->addChannel(chan); } } // Object action else { transform_name = rnap; chan_name = "GKMainObjectChannel"; chan = act->getChannel(chan_name); if(!chan) { gkObjectChannel* ochan = new gkObjectChannel(chan_name, act); ochan->setEulerRotation(true); chan = static_cast<akAnimationChannel*>(ochan); act->addChannel(chan); } } if (bfc->bezt) { int code = -1; if (transform_name == "rotation_quaternion") { if (bfc->array_index == 0) code = gkTransformChannel::SC_ROT_QUAT_W; else if (bfc->array_index == 1) code = gkTransformChannel::SC_ROT_QUAT_X; else if (bfc->array_index == 2) code = gkTransformChannel::SC_ROT_QUAT_Y; else if (bfc->array_index == 3) code = gkTransformChannel::SC_ROT_QUAT_Z; } else if (transform_name == "rotation_euler") { if (bfc->array_index == 0) code = gkTransformChannel::SC_ROT_EULER_X; else if (bfc->array_index == 1) code = gkTransformChannel::SC_ROT_EULER_Y; else if (bfc->array_index == 2) code = gkTransformChannel::SC_ROT_EULER_Z; } else if (transform_name == "location") { if (bfc->array_index == 0) code = gkTransformChannel::SC_LOC_X; else if (bfc->array_index == 1) code = gkTransformChannel::SC_LOC_Y; else if (bfc->array_index == 2) code = gkTransformChannel::SC_LOC_Z; } else if (transform_name == "scale") { if (bfc->array_index == 0) code = gkTransformChannel::SC_SCL_X; else if (bfc->array_index == 1) code = gkTransformChannel::SC_SCL_Y; else if (bfc->array_index == 2) code = gkTransformChannel::SC_SCL_Z; } //add channel zy else if (transform_name == "alpha") { code = gkTransformChannel::SC_ALPHA; }else if(transform_name == "diffuse_color") { if (bfc->array_index == 0) code = gkTransformChannel::SC_DIFFUSE_COLOR_R; else if (bfc->array_index == 1) code = gkTransformChannel::SC_DIFFUSE_COLOR_G; else if (bfc->array_index == 2) code = gkTransformChannel::SC_DIFFUSE_COLOR_B; }else if(transform_name == "texture_slots[0].offset") { if (bfc->array_index == 0) code = gkTransformChannel::SC_TEXTURE0_OFFSET_X; else if (bfc->array_index == 1) code = gkTransformChannel::SC_TEXTURE0_OFFSET_Y; else if (bfc->array_index == 2) code = gkTransformChannel::SC_TEXTURE0_OFFSET_Z; } else if(transform_name == "texture_slots[1].offset") { if (bfc->array_index == 0) code = gkTransformChannel::SC_TEXTURE1_OFFSET_X; else if (bfc->array_index == 1) code = gkTransformChannel::SC_TEXTURE1_OFFSET_Y; else if (bfc->array_index == 2) code = gkTransformChannel::SC_TEXTURE1_OFFSET_Z; } else if(transform_name == "image_user.frame_duration") { code = gkTransformChannel::SC_IMAGE_FRAME; }else if(transform_name == "texture_slots[0].alpha_factor") { code = gkTransformChannel::SC_TEXTURE0_ALPHA_FACTOR; }else if(transform_name == "texture_slots[1].alpha_factor") { code = gkTransformChannel::SC_TEXTURE1_ALPHA_FACTOR; }else if(transform_name == "texture_slots[0].diffuse_color_factor") { code = gkTransformChannel::SC_TEXTURE0_DIFFUSE_COLOR_FACTOR; } else if(transform_name == "texture_slots[1].diffuse_color_factor") { code = gkTransformChannel::SC_TEXTURE1_DIFFUSE_COLOR_FACTOR; } else { gkPrintf("Not supported animation format"); } // ignore any other codes if (code != -1 && bfc->totvert > 0) ConvertSpline(bfc->bezt, chan, code, bfc->bezt->ipo, bfc->totvert, -start, 1.0f/animfps, 0, 1); } if (bfc->next == 0 || bfc->next->prev != bfc) break; //FIX: Momo_WalkBack fcurve is broken in uncompressed 256a. bfc = bfc->next; } // apply time range act->setLength( (end-start)/animfps); act->setStartFrame(start); act->setEndFrame(end); }
gkMesh* gkScene::createMesh(const gkHashedString& name) { GK_ASSERT(m_meshManager); return (gkMesh*)m_meshManager->create(gkResourceName(name, getGroupName())); }
void gkAnimationLoader::convertAction25(Blender::bAction* action, gkScalar animfps) { gkKeyedAnimation* act = gkAnimationManager::getSingleton().createKeyedAnimation(gkResourceName(GKB_IDNAME(action), m_groupName)); if(!act) return; // min/max gkScalar start, end; get25ActionStartEnd(action, start, end); Blender::FCurve* bfc = (Blender::FCurve*)action->curves.first; while (bfc) { utString rnap (bfc->rna_path); utString chan_name; utString transform_name; akAnimationChannel* chan; // Pose action if (rnap.substr(0, 10) == "pose.bones") { // TODO use regex? size_t i = rnap.rfind('\"'); chan_name = rnap.substr(12, i - 12); transform_name = rnap.substr(i + 3, rnap.length() - i + 3); chan = act->getChannel(chan_name); if(!chan) { chan = new gkBoneChannel(chan_name, act); act->addChannel(chan); } } // Object action else { transform_name = rnap; chan_name = "GKMainObjectChannel"; chan = act->getChannel(chan_name); if(!chan) { gkObjectChannel* ochan = new gkObjectChannel(chan_name, act); ochan->setEulerRotation(true); chan = static_cast<akAnimationChannel*>(ochan); act->addChannel(chan); } } if (bfc->bezt) { int code = -1; if (transform_name == "rotation_quaternion") { if (bfc->array_index == 0) code = gkTransformChannel::SC_ROT_QUAT_W; else if (bfc->array_index == 1) code = gkTransformChannel::SC_ROT_QUAT_X; else if (bfc->array_index == 2) code = gkTransformChannel::SC_ROT_QUAT_Y; else if (bfc->array_index == 3) code = gkTransformChannel::SC_ROT_QUAT_Z; } else if (transform_name == "rotation_euler") { if (bfc->array_index == 0) code = gkTransformChannel::SC_ROT_EULER_X; else if (bfc->array_index == 1) code = gkTransformChannel::SC_ROT_EULER_Y; else if (bfc->array_index == 2) code = gkTransformChannel::SC_ROT_EULER_Z; } else if (transform_name == "location") { if (bfc->array_index == 0) code = gkTransformChannel::SC_LOC_X; else if (bfc->array_index == 1) code = gkTransformChannel::SC_LOC_Y; else if (bfc->array_index == 2) code = gkTransformChannel::SC_LOC_Z; } else if (transform_name == "scale") { if (bfc->array_index == 0) code = gkTransformChannel::SC_SCL_X; else if (bfc->array_index == 1) code = gkTransformChannel::SC_SCL_Y; else if (bfc->array_index == 2) code = gkTransformChannel::SC_SCL_Z; } // ignore any other codes if (code != -1 && bfc->totvert > 0) ConvertSpline(bfc->bezt, chan, code, bfc->bezt->ipo, bfc->totvert, -start, 1.0f/animfps, 0, 1); } if (bfc->next == 0 || bfc->next->prev != bfc) break; //FIX: Momo_WalkBack fcurve is broken in uncompressed 256a. bfc = bfc->next; } // apply time range act->setLength( (end-start)/animfps); }
void gkAnimationLoader::convertObject(gkGameObject* obj, Blender::Object* bobj, bool pre25compat, gkScalar animfps) { // 2.4x if(pre25compat) { if(bobj && bobj->ipo) { gkAnimation* act = dynamic_cast<gkAnimation*>(gkAnimationManager::getSingleton().getByName(gkResourceName(GKB_IDNAME(bobj->ipo), m_groupName))); if(!act) act = convertObjectIpoToAnimation(bobj->ipo, animfps); if(act) obj->addAnimation(act, GKB_IDNAME(bobj->ipo)); } if(bobj && bobj->action) { gkResourceName name(GKB_IDNAME(bobj->action), m_groupName); gkAnimation* act = dynamic_cast<gkAnimation*>(gkAnimationManager::getSingleton().getByName(name)); if(!act) { convertAction(bobj->action, pre25compat, animfps); act = dynamic_cast<gkAnimation*>(gkAnimationManager::getSingleton().getByName(name)); } if(act) obj->addAnimation(act, GKB_IDNAME(bobj->action)); } // TODO 2.4 NLA } // 2.5x else if (bobj->adt) { convert25AnimData(obj, bobj->adt, animfps); } // object data switch (bobj->type) { case OB_LAMP: convertLamp(obj, bobj, pre25compat, animfps); break; case OB_CAMERA: convertCamera(obj, bobj, pre25compat, animfps); break; case OB_MESH: convertMesh(obj, bobj, pre25compat, animfps); break; case OB_ARMATURE: convertArmature(obj, bobj, pre25compat, animfps); break; } }
void gkTextManager::parseScripts(const gkString& group) { gkResourceManager::ResourceIterator iter = getResourceIterator(); while (iter.hasMoreElements()) { gkTextFile* tf = static_cast<gkTextFile*>(iter.getNext().second); if (!group.empty() && tf->getGroupName() != group) continue; const gkString& buf = tf->getText(); const int type = tf->getType(); #ifdef OGREKIT_COMPILE_OGRE_SCRIPTS try { if (type == TT_MATERIAL) { Ogre::DataStreamPtr memStream( OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size())); Ogre::MaterialManager::getSingleton().parseScript(memStream, group); } else if (type == TT_PARTICLE) { Ogre::DataStreamPtr memStream( OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size())); Ogre::ParticleSystemManager::getSingleton().parseScript(memStream, group); } else if (type == TT_FONT) { // Note: font must be an external file (.ttf anyway (texture fonts are not tested) ) Ogre::DataStreamPtr memStream( OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size())); Ogre::FontManager::getSingleton().parseScript(memStream, group); } else if (type == TT_COMPOSIT) { Ogre::DataStreamPtr memStream( OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size())); Ogre::CompositorManager::getSingleton().parseScript(memStream, group); } } catch (Ogre::Exception& e) { gkLogMessage("TextManager: " << e.getDescription()); continue; } if (type == TT_BFONT) { utMemoryStream stream; stream.open(buf.c_str(), buf.size(), utStream::SM_READ); gkFontManager::getSingleton().parseScript(&stream); } #endif #ifdef OGREKIT_USE_LUA if (type == TT_LUA) gkLuaManager::getSingleton().createFromText(gkResourceName(tf->getResourceName().getName(), group), buf); #endif } #ifdef OGREKIT_COMPILE_OGRE_SCRIPTS // Overlays are a dependant script. (.material .font) try { TextArray overlays; getTextFiles(overlays, TT_OVERLAY); TextArray::Iterator it = overlays.iterator(); while (it.hasMoreElements()) { gkTextFile* tf = (gkTextFile*)it.getNext(); const gkString& buf = tf->getText(); const int type = tf->getType(); Ogre::DataStreamPtr memStream( OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size())); Ogre::OverlayManager::getSingleton().parseScript(memStream, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); } } catch (Ogre::Exception& e) { gkLogMessage("TextManager: " << e.getDescription()); } #endif }
void gkBlenderSceneConverter::convert(bool createGroupInstances) { if (m_gscene) return; m_gscene = (gkScene*)gkSceneManager::getSingleton().create(gkResourceName(GKB_IDNAME(m_bscene), m_groupName)); if (!m_gscene) { gkPrintf("SceneConverter: duplicate scene '%s'\n", (m_bscene->id.name + 2)); return; } m_gscene->setLoadBlendFile(m_file); if (m_bscene->world) convertWorld(); convertSoundScene(); m_gscene->setLayer((UTuint32)m_bscene->lay); utArray<Blender::Object*> groups, armatureLinker; for (Blender::Base* base = (Blender::Base*)m_bscene->base.first; base; base = base->next) { if (!base->object) continue; Blender::Object* bobj = base->object; // non - conversion object if (!validObject(bobj)) continue; if ((bobj->transflag& OB_DUPLIGROUP) && bobj->dup_group != 0) groups.push_back(bobj); else convertObject(bobj); if (bobj->type == OB_MESH && bobj->parent != 0 && bobj->parent->type == OB_ARMATURE) armatureLinker.push_back(bobj); #if 0 if (bobj->parent) { short parentType = bobj->parent->type; short parentParType = bobj->parent->partype; } short parType = bobj->partype; int i=0; #endif } // build group instances convertGroups(); if (createGroupInstances) convertGroupInstances(); if (!armatureLinker.empty()) { gkMeshManager& memgr = gkMeshManager::getSingleton(); gkSkeletonManager& skmgr = gkSkeletonManager::getSingleton(); gkGameObjectManager& gomgr = gkGameObjectManager::getSingleton(); UTsize i; for (i = 0; i < armatureLinker.size(); ++i) { Blender::Object* obMe = armatureLinker[i]; Blender::Object* obAr = obMe->parent; gkEntity* gobjEn = gomgr.getEntity(GKB_IDNAME(obMe)); gkSkeleton* gobjSk = gomgr.getSkeleton(GKB_IDNAME(obAr)); if (gobjEn && gobjSk && !gobjEn->getProperties().hasBoneParent()) { gobjEn->setSkeleton(gobjSk); // Link data Blender::Mesh* me = static_cast<Blender::Mesh*>(obMe->data); Blender::bArmature* ar = static_cast<Blender::bArmature*>(obAr->data); if (memgr.exists(GKB_IDNAME(me)) && skmgr.exists(GKB_IDNAME(obAr))) { gkSkeletonResource* skel = skmgr.getByName<gkSkeletonResource>(GKB_IDNAME(obAr)); memgr.getByName<gkMesh>(GKB_IDNAME(me))->_setSkeleton(skel); gkBone::BoneList::Iterator roots = skel->getRootBoneList().iterator(); while (roots.hasMoreElements()) { gkBone* bone = roots.getNext(); gkMatrix4 eobmat = gkMathUtils::getFromFloat(obMe->obmat); gkMatrix4 sobmat = gkMathUtils::getFromFloat(obAr->obmat); gkTransformState trans(eobmat.inverse() * sobmat); if (!trans.isNaN()) bone->applyRootTransform(trans); else gkPrintf("Warning: Invalid bone transform."); } } } } } m_logic->resolveLinks(); }
void gkBlenderSceneConverter::convertObjectParticles(gkGameObject* gobj, Blender::Object* bobj) { #ifdef OGREKIT_USE_PARTICLE for (Blender::ParticleSystem* ps = (Blender::ParticleSystem*)bobj->particlesystem.first; ps; ps = ps->next) { gkString name = ps->name; gkString pname = GKB_IDNAME(ps->part); gkParticleResource* resource = gkParticleManager::getSingleton().getByName<gkParticleResource>(gkResourceName(pname, m_groupName)); if (!resource) continue; gkGameObjectProperties& gprops = gobj->getProperties(); gkParticleObject* pobj = m_gscene->createParticleObject(gkUtils::getUniqueName(name)); if (pobj) { pobj->setActiveLayer(gobj->isInActiveLayer()); pobj->setLayer(gobj->getLayer()); gkParticleSettingsProperties& sprops = resource->getParticleProperties(); gkParticleSystemProperties& props = pobj->getParticleProperties(); gprops.m_particleObjs.push_back(pobj->getName()); props.m_name = name; props.m_seed = ps->seed; props.m_settings = pname; gkGameObjectProperties& gparticleprops = pobj->getProperties(); gparticleprops.m_parent = gobj->getName(); gparticleprops.m_transform = gobj->getProperties().m_transform; props.m_material = "<gkBuiltin/Halo>"; if (!sprops.m_drawEmitter) gobj->getProperties().m_mode |= GK_INVISIBLE; Blender::Material* ma = BlenderMaterial(bobj, sprops.m_material); if (ma) { props.m_material = GKB_IDNAME(ma); } gkEntity* entity = gobj->getEntity(); if (entity) { props.m_mesh = entity->getMesh(); //pobj->setMaterialName(entity->getMesh()->getFirstMaterial().m_name); } } } #endif }
void gkBlenderSceneConverter::convertGroups(utArray<Blender::Object*> &groups) { gkGroupManager* mgr = gkGroupManager::getSingletonPtr(); // This is a complete list of groups & containing objects. // The gkGameObjectGroup is a containter, the gkGameObjectGroupInstance // is where the object should be added / removed from the scene. // for (Blender::Group* bgrp = (Blender::Group*)m_file->_getInternalFile()->m_group.first; bgrp != 0; // bgrp = (Blender::Group*)bgrp->id.next) gkBlendListIterator iter = m_file->_getInternalFile()->getGroupList(); while (iter.hasMoreElements()) { Blender::Group* bgrp = (Blender::Group*)iter.getNext(); const gkResourceName groupName(GKB_IDNAME(bgrp), m_groupName); if (mgr->exists(groupName)) { // Can most likely assert here continue; } gkGameObjectGroup* group = (gkGameObjectGroup*)mgr->create(groupName); for (Blender::GroupObject* bgobj = (Blender::GroupObject*)bgrp->gobject.first; bgobj; bgobj = bgobj->next) { if (bgobj->ob) { Blender::Object* bobj = bgobj->ob; if (!validObject(bobj)) continue; gkGameObject* gobj = m_gscene->getObject(GKB_IDNAME(bobj)); // add it to the list if (gobj) group->addObject(gobj); } } // Destroy if empty if (group->isEmpty()) mgr->destroy(group); else mgr->attachGroupToScene(m_gscene, group); } // Process user created groups. utArray<Blender::Object*>::Iterator it = groups.iterator(); while (it.hasMoreElements()) { Blender::Object* bobj = it.getNext(); // Should not fail GK_ASSERT((bobj->transflag& OB_DUPLIGROUP && bobj->dup_group != 0)); // Owning group Blender::Group* bgobj = bobj->dup_group; const gkResourceName groupName(GKB_IDNAME(bgobj), m_groupName); if (mgr->exists(groupName)) { gkGameObjectGroup* ggobj = (gkGameObjectGroup*)mgr->getByName(groupName); gkGameObjectInstance* inst = ggobj->createGroupInstance(m_gscene, gkResourceName(GKB_IDNAME(bobj), m_groupName)); if (inst) convertObject(bobj, inst->getRoot()); } } }