void SE_CommonNode::updateBoundingVolume() { std::vector<SE_Spatial*> children; std::vector<SE_Spatial*>::iterator it; for(it = children.begin() ; it != children.end() ; it++) { SE_Spatial* s = *it; s->updateBoundingVolume(); } if(mWorldBoundingVolume) { delete mWorldBoundingVolume; mWorldBoundingVolume = NULL; } switch(getBVType()) { case SE_BoundingVolume::AABB: mWorldBoundingVolume = new SE_AABBBV; break; case SE_BoundingVolume::OBB: mWorldBoundingVolume = new SE_OBBBV; break; case SE_BoundingVolume::SPHERE: mWorldBoundingVolume = new SE_SphereBV; break; } if(mWorldBoundingVolume) { for(it = children.begin() ; it != children.end() ; it++) { SE_Spatial* s = *it; mWorldBoundingVolume->merge(s->getWorldBoundingVolume()); } } }
void SE_NewGeometry::updateBoundingVolume() { if(mWorldBoundingVolume) { delete mWorldBoundingVolume; mWorldBoundingVolume = NULL; } switch(getBVType()) { case SE_BoundingVolume::AABB: mWorldBoundingVolume = new SE_AABBBV; break; case SE_BoundingVolume::OBB: mWorldBoundingVolume = new SE_OBBBV; break; case SE_BoundingVolume::SPHERE: mWorldBoundingVolume = new SE_SphereBV; break; } if(mWorldBoundingVolume) { SE_NewGeometry::_Impl::SimObjectList::iterator it; for(it = mImpl->attachObject.begin() ; it != mImpl->attachObject.end() ; it++) { //(*it)->doTransform(getWorldTransform()); SE_Vector3f* points = (*it)->getVertexArray(); int num = (*it)->getVertexNum(); mWorldBoundingVolume->createFromPoints(points, num); } } }
void SE_Geometry::forceUpdateBoundingVolume() { if(mWorldBoundingVolume) { delete mWorldBoundingVolume; mWorldBoundingVolume = NULL; } switch(getBVType()) { case AABB: mWorldBoundingVolume = new SE_AABBBV; break; case OBB: mWorldBoundingVolume = new SE_OBBBV; break; case SPHERE: mWorldBoundingVolume = new SE_SphereBV; break; } if(mWorldBoundingVolume) { SE_Geometry::_Impl::SimObjectList::iterator it; for(it = mImpl->attachObject.begin() ; it != mImpl->attachObject.end() ; it++) { //generate world geometry data SE_GeometryData data; SE_Matrix4f m2w = this->getWorldTransform(); SE_GeometryData::transform((*it)->getMesh()->getGeometryData(),m2w,&data); //(*it)->doTransform(getWorldTransform()); SE_Vector3f* points = data.getVertexArray(); if(!points) { continue; } int num = data.getVertexNum(); mWorldBoundingVolume->createFromPoints(points, num); (*it)->setCenter(mWorldBoundingVolume->getCenter()); } } //if this is a shadow creator,tell render to update shadow map if(this->isSpatialEffectHasAttribute(SE_SpatialAttribute::SHADOWGENERATOR)) { //SE_Application::getInstance()->getSpatialManager()->shadowCreatorTransformed(); SE_Application::getInstance()->getRenderManager()->shadowCreatorTransformed(); } if(this->isSpatialEffectHasAttribute(SE_SpatialAttribute::MIRRORGENERATOR)) { //SE_Application::getInstance()->getSpatialManager()->mirrorCreatorTransformed(); SE_Application::getInstance()->getRenderManager()->mirrorCreatorTransformed(); } }
void SE_Geometry::updateBoundingVolume() { this->forceUpdateBoundingVolume(); /*if((!this->isChangedTransform()) && mWorldBoundingVolume && (!this->getParent()->isChangedTransform())) { return; }*/ //LOGI("Geometry[%s] update bounding volume!!\n\n",this->getSpatialName()); #if 0 if(mWorldBoundingVolume) { delete mWorldBoundingVolume; mWorldBoundingVolume = NULL; } switch(getBVType()) { case AABB: mWorldBoundingVolume = new SE_AABBBV; break; case OBB: mWorldBoundingVolume = new SE_OBBBV; break; case SPHERE: mWorldBoundingVolume = new SE_SphereBV; break; } if(mWorldBoundingVolume) { SE_Geometry::_Impl::SimObjectList::iterator it; for(it = mImpl->attachObject.begin() ; it != mImpl->attachObject.end() ; it++) { //(*it)->doTransform(getWorldTransform()); SE_Vector3f* points = (*it)->getVertexArray(); if(!points) { continue; } int num = (*it)->getVertexNum(); mWorldBoundingVolume->createFromPoints(points, num); (*it)->setCenter(mWorldBoundingVolume->getCenter()); } } if (this->getScene()->getSceneManagerType() == SE_Scene::OCTREESCENEMANAGER) { this->getScene()->getOctreeSceneManager()->updateBounds(this->getSpatialName()); } //mBoundingHasChanged = false; #endif }
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; }