SE_Spatial *SE_Geometry::clone(SE_SimObject *srcobj, int index) { #if 0 SE_Geometry * dest = new SE_Geometry(); SE_SimObject* destobj = srcobj->clone(index); std::string srcobjname = srcobj->getName(); //attach obj SE_SimObjectManager* simObjectManager = SE_Application::getInstance()->getSimObjectManager(); SE_SimObjectID id = SE_ID::createSimObjectID(); destobj->setID(id); simObjectManager->set(id, destobj); //set spatial property SE_Spatial *srcSpatial = srcobj->getSpatial(); SE_SpatialID destSpatialID = SE_ID::createSpatialID(); dest->setSpatialID(destSpatialID); dest->setBVType(srcSpatial->getBVType()); SE_Vector3f a = srcSpatial->getLocalTranslate(); dest->setLocalTranslate(a); dest->setLocalRotate(srcSpatial->getLocalRotate()); dest->setLocalScale(srcSpatial->getLocalScale()); dest->setPrevMatrix(srcSpatial->getPrevMatrix()); dest->setPostMatrix(srcSpatial->getPostMatrix()); dest->setParent(srcSpatial->getParent()); dest->setLocalLayer(srcSpatial->getLocalLayer()); //set render state dest->setRenderState(DEPTHTESTSTATE ,this->getRenderState(DEPTHTESTSTATE)); dest->attachSimObject(destobj); //SE_Application::getInstance()->getSceneManager()->updateSpatialIDMap(); SE_Scene* scene = srcSpatial->getScene(); scene->addSpatial(srcSpatial->getParent(), dest); srcSpatial->getParent()->updateWorldTransform(); srcSpatial->getParent()->updateBoundingVolume(); srcSpatial->getParent()->updateRenderState(); srcSpatial->getParent()->updateWorldLayer(); //return clone object return dest; #endif return NULL; }
static void se_inflateResource(JNIEnv* env, jobject obj, jint resource, jstring objName, jint objIndex, jstring nodeName, jint nodeIndex, jboolean removeTopNode) { //Invoke by gl thread jstring sceneName = (jstring)env->GetObjectField(obj, sceneNameID); const char* sceneName8 = env->GetStringUTFChars(sceneName, 0); const char* nodeName8 = env->GetStringUTFChars(nodeName, NULL); const char* objName8 = env->GetStringUTFChars(objName, NULL); SE_Scene* scene = SE_Application::getInstance()->getSceneManager()->getScene(SE_FRAMEBUFFER_SCENE, SE_StringID(sceneName8)); SE_Spatial* node = SE_Application::getInstance()->getSceneManager()->findSpatialByName(nodeName8, nodeIndex); SE_Spatial* s = (SE_Spatial*)resource; if (!node) { env->ReleaseStringUTFChars(sceneName, sceneName8); env->ReleaseStringUTFChars(nodeName, nodeName8); env->ReleaseStringUTFChars(objName, objName8); return; } if (s) { SE_ResourceManager* m = SE_Application::getInstance()->getResourceManager(); SE_ResourceManager* loader = s->getCBFLoader(); m->copy(loader); s->deleteCBFLoader(); if (removeTopNode) { s->getChildByIndex(0)->setSpatialName(objName8); s->getChildByIndex(0)->setCloneIndex(objIndex); s->replaceChildParent(node); node->setCloneIndex(objIndex); scene->inflate(); node->updateWorldTransform(); node->updateBoundingVolume(); node->updateWorldLayer(); delete s; } else { s->setSpatialName(objName8); s->setCloneIndex(objIndex); std::string modelName = objName8; modelName = modelName + "_model"; s->getChildByIndex(0)->setSpatialName(modelName.c_str()); s->getChildByIndex(0)->setCloneIndex(objIndex); scene->addSpatial(node, s); scene->inflate(); node = scene->getRoot(); node->updateWorldTransform(); node->updateBoundingVolume(); node->updateWorldLayer(); } } env->ReleaseStringUTFChars(sceneName, sceneName8); env->ReleaseStringUTFChars(nodeName, nodeName8); env->ReleaseStringUTFChars(objName, objName8); }
SE_Spatial *SE_Geometry::clone(SE_Spatial* parent, int index,bool createNewMesh,const char* statuslist) { if(!parent) { if(SE_Application::getInstance()->SEHomeDebug) LOGI("No parent,clone fail.!!!!"); return NULL; } SE_Geometry * dest = new SE_Geometry(); SE_SimObject* destobj = getCurrentAttachedSimObj()->clone(index,createNewMesh); dest->setSpatialName(this->getSpatialName()); dest->setCloneIndex(index); //attach obj dest->attachSimObject(destobj); //set spatial property dest->setBVType(getBVType()); SE_Vector3f a = getLocalTranslate(); dest->setLocalTranslate(a); dest->setLocalRotate(getLocalRotate()); dest->setLocalScale(getLocalScale()); dest->setPrevMatrix(getPrevMatrix()); dest->setPostMatrix(getPostMatrix()); dest->setParent(parent); SE_Layer* l = this->getWorldLayer(); SE_Layer* destL = dest->getWorldLayer(); destL->setLayer(l->getLayer()); //set render state dest->setRenderState(DEPTHTESTSTATE ,this->getRenderState(DEPTHTESTSTATE)); //SE_Application::getInstance()->getSceneManager()->updateSpatialIDMap(); SE_Scene* scene = getScene(); scene->addSpatial(parent, dest); parent->updateWorldTransform(); parent->updateBoundingVolume(); parent->updateRenderState(); //parent->updateWorldLayer(); //copy geometry para dest->setHasInflate(true); dest->setAlpha(this->getAlpha()); unsigned int status = 0; if(statuslist) { status = SE_Util::stringToInt(statuslist); } dest->setEffectState(status); dest->setSpatialState(this->getSpatialState()); dest->setSpatialEffectData(this->getSpatialEffectData()); std::vector<std::string> lights; this->getLightsNameList(lights); for(int i = 0; i < lights.size(); ++i) { dest->addLightNameToList(lights[i].c_str()); } scene->sceneApplyLight(); //return clone object return dest; }