Example #1
0
/// From http://www.ogre3d.org/forums/viewtopic.php?f=2&t=53647
inline void destroySceneNode(Ogre::SceneNode *node)
{
	if(!node) return;
	destroyAllAttachedMovableObjects(node);
	node->removeAndDestroyAllChildren();
	node->getCreator()->destroySceneNode(node);
}
Example #2
0
//!
//! Destructor of the Model2SceneNode class.
//!
Model2SceneNode::~Model2SceneNode ()
{
    destroyEntity();
	destroyAllAttachedMovableObjects(m_sceneNode);
    OgreTools::destroyResourceGroup(m_oldResourceGroupName);
    emit viewNodeUpdated();

    DEC_INSTANCE_COUNTER
}
Example #3
0
//!
//! Processes the node's input data to generate the node's output table.
//!
void Model2SceneNode::processScene()
{
	// load the input vtk parameter 
	VTKTableParameter * inputParameter = dynamic_cast<VTKTableParameter*>(getParameter(m_inputVTKTableParameterName));
	if (!inputParameter || !inputParameter->isConnected())
		return;

	// get the source parameter (output of source node) connected to the input parameter
	VTKTableParameter * sourceParameter = dynamic_cast<VTKTableParameter*>(inputParameter->getConnectedParameter());

	inputParameter->setVTKTable(sourceParameter->getVTKTable());

	vtkTable * xyzTable = inputParameter->getVTKTable();

	if (!m_sceneNode)
		createSceneNode();


	if (!m_entity || !xyzTable || !m_sceneNode)
		return;

	//Get columns named "NodeID", "X", "Y" and "Z"
	vtkIdTypeArray *colNodeId = dynamic_cast<vtkIdTypeArray*>(xyzTable->GetColumnByName("NodeId"));
	vtkDoubleArray *colX = dynamic_cast<vtkDoubleArray*>(xyzTable->GetColumnByName("X"));
	vtkDoubleArray *colY = dynamic_cast<vtkDoubleArray*>(xyzTable->GetColumnByName("Y"));
	vtkDoubleArray *colZ = dynamic_cast<vtkDoubleArray*>(xyzTable->GetColumnByName("Z"));

	destroyAllAttachedMovableObjects(m_sceneNode);
	destroyAllChildren(m_sceneNode);

	Ogre::String idPrefix(QString(m_name + ":").toStdString());

	Ogre::SceneManager *sceneManager = OgreManager::getSceneManager();

	for (int i=0; i<xyzTable->GetNumberOfRows(); i++)
	{
		int colIDValue = colNodeId->GetValue(i);
		Ogre::String nodeID(idPrefix + Ogre::StringConverter::toString(colIDValue));

		// create new scene node for each item
		Ogre::SceneNode *sceneItem = sceneManager->createSceneNode(nodeID);

		// create new entity for each item
		Ogre::Entity *entityItem = m_entity->clone(nodeID);
		
		sceneItem->attachObject(entityItem);

		double x = colX->GetValue(i);
		double y = colY->GetValue(i);
		double z = colZ->GetValue(i);
		sceneItem->setPosition(Ogre::Real(x), Ogre::Real(y), Ogre::Real(z));
		sceneItem->setScale(m_size);
		m_sceneNode->addChild(sceneItem);
		
	}
}
Example #4
0
  void SceneNodeWrapper::destroyAllAttachedMovableObjects( Ogre::SceneNode* node )
  {
    if(!node) return;

    // Destroy all the attached objects
    Ogre::SceneNode::ObjectIterator itObject = node->getAttachedObjectIterator();

    while ( itObject.hasMoreElements() )
      node->getCreator()->destroyMovableObject(itObject.getNext());

    // Recurse to child SceneNode
    auto itChild = node->getChildIterator();

    while ( itChild.hasMoreElements() )
    {
      Ogre::SceneNode* pChildNode = static_cast<Ogre::SceneNode*>(itChild.getNext());
      destroyAllAttachedMovableObjects(pChildNode);
    }
  }
Example #5
0
/// From http://www.ogre3d.org/forums/viewtopic.php?f=2&t=53647
inline void destroyAllAttachedMovableObjects(Ogre::SceneNode *node)
{
	if(!node) return;

	// Destroy all the attached objects
	Ogre::SceneNode::ObjectIterator itObject = node->getAttachedObjectIterator(); // FIXME segmentation fault

	while (itObject.hasMoreElements())
		node->getCreator()->destroyMovableObject(itObject.getNext());

	// Recurse to child SceneNodes
	Ogre::SceneNode::ChildNodeIterator itChild = node->getChildIterator();

	while ( itChild.hasMoreElements() )
	{
		Ogre::SceneNode* pChildNode = boost::polymorphic_cast<Ogre::SceneNode*>(itChild.getNext());
		destroyAllAttachedMovableObjects(pChildNode);
	}
}
Example #6
0
//!
//! Remove and destroy this scene children.
//! \param The scenenode to be destroyed
//!
void Model2SceneNode::destroyAllChildren( Ogre::SceneNode* i_pSceneNode )
{
	if ( !i_pSceneNode || i_pSceneNode->numChildren() == 0 )
      return;

   // Destroy all the attached objects
   Ogre::SceneNode::ObjectIterator itObject = i_pSceneNode->getAttachedObjectIterator();

   // Recurse to child SceneNodes
   Ogre::SceneNode::ChildNodeIterator itChild = i_pSceneNode->getChildIterator();

   while ( itChild.hasMoreElements() )
   {
      Ogre::SceneNode* pChildNode = static_cast<Ogre::SceneNode*>(itChild.getNext());
      destroyAllAttachedMovableObjects( pChildNode );
	  // obtain the OGRE scene manager
	  Ogre::SceneManager *sceneManager = OgreManager::getSceneManager();
	  if (pChildNode != m_sceneNode)
		  sceneManager->destroySceneNode( pChildNode->getName() );
   }
}
Example #7
0
  void SceneNodeWrapper::destroy()
  {
    removeEventListener(mObjectManager, OgreObjectManagerEvent::FACTORY_UNREGISTERED, &SceneNodeWrapper::onFactoryUnregister);
    for(auto& pair : mChildren)
    {
      for(auto& objectPair : pair.second)
      {
        objectPair.second->destroy();
      }
    }

    if(mParentNode != 0)
      mParentNode->removeChild(mNode);

    if(mNode != 0)
    {
      destroyAllAttachedMovableObjects(mNode);
      mNode->removeAndDestroyAllChildren();
      mSceneManager->destroySceneNode(mNode);
    }

  }
Example #8
0
//!
//! Remove and destroy all movable objects of this scene.
//! \param The scenenode to be destroyed
//!
void Model2SceneNode::destroyAllAttachedMovableObjects( Ogre::SceneNode* i_pSceneNode )
{
   if ( !i_pSceneNode )
      return;

   // Destroy all the attached objects
   Ogre::SceneNode::ObjectIterator itObject = i_pSceneNode->getAttachedObjectIterator();

   while ( itObject.hasMoreElements() )
   {
      Ogre::MovableObject* pObject = static_cast<Ogre::MovableObject*>(itObject.getNext());
      i_pSceneNode->getCreator()->destroyMovableObject( pObject );
   }

   // Recurse to child SceneNodes
   Ogre::SceneNode::ChildNodeIterator itChild = i_pSceneNode->getChildIterator();

   while ( itChild.hasMoreElements() )
   {
      Ogre::SceneNode* pChildNode = static_cast<Ogre::SceneNode*>(itChild.getNext());
      destroyAllAttachedMovableObjects( pChildNode );
   }
}
void ObjectNode::createEntities(Ogre::SceneNode *target_node, Ogre::SceneManager *scene_manager, LibGens::ModelLibrary *model_library, LibGens::MaterialLibrary *material_library, LibGens::ObjectProduction *object_production, string slot_id_name) {
	string model_name=object->queryEditorModel(slot_id_name, OBJECT_NODE_UNKNOWN_MESH);
	string skeleton_name=object->queryEditorSkeleton(slot_id_name, "");
	string animation_name=object->queryEditorAnimation(slot_id_name, "");

	string preview_box_x=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_X, "");
	string preview_box_y=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_Y, "");
	string preview_box_z=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_Z, "");

	string preview_box_x_scale=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_X_SCALE, "");
	string preview_box_y_scale=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_Y_SCALE, "");
	string preview_box_z_scale=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_Z_SCALE, "");

	if ((preview_box_x.size()) || (preview_box_y.size()) || (preview_box_z.size())) {
		LibGens::ObjectElementFloat *p_x = (LibGens::ObjectElementFloat *) object->getElement(preview_box_x);
		LibGens::ObjectElementFloat *p_y = (LibGens::ObjectElementFloat *) object->getElement(preview_box_y);
		LibGens::ObjectElementFloat *p_z = (LibGens::ObjectElementFloat *) object->getElement(preview_box_z);

		Ogre::Vector3 new_scale = preview_box_node->getScale();
		float scale_f=0.0f;

		float scale_x = 1.0f;
		float scale_y = 1.0f;
		float scale_z = 1.0f;

		if (preview_box_x_scale.size()) FromString<float>(scale_x, preview_box_x_scale, std::dec);
		if (preview_box_y_scale.size()) FromString<float>(scale_y, preview_box_y_scale, std::dec);
		if (preview_box_z_scale.size()) FromString<float>(scale_z, preview_box_z_scale, std::dec);

		// Check if elements were found. If not, try reading the float value from the string
		if (p_x) new_scale.x = p_x->value;
		else {
			FromString<float>(scale_f, preview_box_x, std::dec);
			new_scale.x = scale_f;
		}

		if (p_y) new_scale.y = p_y->value;
		else {
			FromString<float>(scale_f, preview_box_y, std::dec);
			new_scale.y = scale_f;
		}

		if (p_z) new_scale.z = p_z->value;
		else {
			FromString<float>(scale_f, preview_box_z, std::dec);
			new_scale.z = scale_f;
		}

		new_scale.x = new_scale.x * scale_x;
		new_scale.y = new_scale.y * scale_y;
		new_scale.z = new_scale.z * scale_z;

		// Check for valid scaling values
		if (new_scale.x <= 0.0) new_scale.x = 0.1;
		if (new_scale.y <= 0.0) new_scale.y = 0.1;
		if (new_scale.z <= 0.0) new_scale.z = 0.1;

		preview_box_node->setScale(new_scale);
	}

	if ((object->getName() == OBJECT_NODE_OBJECT_PHYSICS) && object_production) {
		bool found_model=false;

		LibGens::ObjectElement *element=object->getElement(OBJECT_NODE_OBJECT_PHYSICS_ELEMENT_TYPE);
		if (element) {
			string type_name=static_cast<LibGens::ObjectElementString *>(element)->value;

			if (type_name != current_type_name) {
				current_type_name = type_name;
				destroyAllAttachedMovableObjects(target_node);
			}
			else {
				return;
			}

			LibGens::ObjectPhysics *object_physics = object_production->getObjectPhysics(type_name);
			if (object_physics) {
				vector<string> models=object_physics->getModels();
				vector<string> motions=object_physics->getMotions();
				vector<string> motion_skeletons=object_physics->getMotionSkeletons();

				for (size_t i=0; i<models.size(); i++) {
					string model_id=models[i];
					string skeleton_id = "";
					string animation_id = "";

					LibGens::Model *model=model_library->getModel(model_id);
					if (i < motions.size()) {
						animation_id = motions[i];
					}

					if (i < motion_skeletons.size()) {
						skeleton_id = motion_skeletons[i];
					}

					if (model) {
						prepareSkeletonAndAnimation(skeleton_id, animation_id);
						buildModel(target_node, model, model->getName(), skeleton_id, scene_manager, material_library, EDITOR_NODE_QUERY_OBJECT, GENERAL_MESH_GROUP, false);
						createAnimationState(animation_id);
						found_model = true;
					}
				}
			}
		}

		if (found_model) {
			return;
		}
		else {
			current_model_name = "";
		}
	}

	if ((model_name != current_model_name) || (skeleton_name != current_skeleton_name) || (animation_name != current_animation_name)) {
		current_model_name = model_name;
		current_skeleton_name = skeleton_name;
		current_animation_name = animation_name;

		destroyAllAttachedMovableObjects(target_node);
	}
	else {
		return;
	}

	string model_id=model_name;
	model_id.resize(model_id.size() - ((string)OBJECT_NODE_MODEL_EXTENSION).size());

	string skeleton_id="";
	if (skeleton_name.size()) {
		skeleton_id=skeleton_name;
		skeleton_id.resize(skeleton_id.size() - ((string)OBJECT_NODE_SKELETON_EXTENSION).size());
	}

	string animation_id="";
	if (animation_name.size()) {
		animation_id=animation_name;
		animation_id.resize(animation_id.size() - ((string)OBJECT_NODE_ANIMATION_EXTENSION).size());
	}

	if (model_name.find(OBJECT_NODE_MODEL_EXTENSION) != string::npos) {
		LibGens::Model *model=model_library->getModel(model_id);

		if (model) {
			prepareSkeletonAndAnimation(skeleton_id, animation_id);
			buildModel(target_node, model, model->getName(), skeleton_id, scene_manager, material_library, EDITOR_NODE_QUERY_OBJECT, GENERAL_MESH_GROUP, false);
		}
		else {
			Ogre::Entity *entity = scene_manager->createEntity(OBJECT_NODE_UNKNOWN_MESH);
			entity->setQueryFlags(EDITOR_NODE_QUERY_OBJECT);
			target_node->attachObject(entity);
		}
	}
	else if (model_name.find(OBJECT_NODE_MESH_EXTENSION) != string::npos) {
		Ogre::Entity *entity = scene_manager->createEntity(model_name);
		entity->setQueryFlags(EDITOR_NODE_QUERY_OBJECT);
		target_node->attachObject(entity);
	}

	createAnimationState(animation_id);

	// Create PreviewBox if necessary
	if ((preview_box_x.size()) || (preview_box_y.size()) || (preview_box_z.size())) {
		preview_box_entity = scene_manager->createEntity("preview_box.mesh");
		preview_box_entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAX);
		preview_box_entity->setQueryFlags(EDITOR_NODE_QUERY_PREVIEW_BOX);
		preview_box_node->attachObject(preview_box_entity);
	}
}