Exemplo n.º 1
0
void DocumentImporter::report_unknown_reference(const COLLADAFW::Node &node, const std::string object_type)
{
	std::string id = node.getOriginalId();
	std::string name = node.getName();
	fprintf(stderr,
		"error: node id=\"%s\", name=\"%s\" refers to an undefined %s.\n",
		id.c_str(),
		name.c_str(),
		object_type.c_str());
}
    //------------------------------
	bool NodeLoader::begin__instance_light( const instance_light__AttributeData& attributeData )
	{
		COLLADAFW::Node* currentNode = mNodeStack.top();
		COLLADAFW::UniqueId instantiatedLightUniqueId = getHandlingFilePartLoader()->createUniqueIdFromUrl( attributeData.url, COLLADAFW::Light::ID() );

        COLLADAFW::UniqueId instanceLightUniqueId = getHandlingFilePartLoader()->createUniqueId( COLLADAFW::InstanceLight::ID() );
		COLLADAFW::InstanceLight* instanceLight = FW_NEW COLLADAFW::InstanceLight(instanceLightUniqueId, instantiatedLightUniqueId);
		currentNode->getInstanceLights().append(instanceLight);

		return true;
	}
    //------------------------------
	bool NodeLoader::begin__instance_camera( const instance_camera__AttributeData& attributeData )
	{
        COLLADAFW::Node* currentNode = mNodeStack.top();
		COLLADAFW::UniqueId instantiatedCameraUniqueId = getHandlingFilePartLoader()->createUniqueIdFromUrl( attributeData.url, COLLADAFW::Camera::ID() );

        COLLADAFW::UniqueId instanceCameraUniqueId = getHandlingFilePartLoader()->createUniqueId( COLLADAFW::InstanceCamera::ID() );
		COLLADAFW::InstanceCamera* instanceCamera = FW_NEW COLLADAFW::InstanceCamera(instanceCameraUniqueId, instantiatedCameraUniqueId);
		currentNode->getInstanceCameras().append(instanceCamera);

		return true;
	}
	//------------------------------
	bool NodeLoader::begin__instance_node( const instance_node__AttributeData& attributeData )
	{
		COLLADAFW::Node* currentNode = mNodeStack.top();
		COLLADAFW::UniqueId instantiatedNodeUniqueId = getHandlingFilePartLoader()->createUniqueIdFromUrl( attributeData.url, COLLADAFW::Node::ID() );

        COLLADAFW::UniqueId instanceNodeUniqueId = getHandlingFilePartLoader()->createUniqueId( COLLADAFW::InstanceNode::ID() );
		COLLADAFW::InstanceNode* instanceNode = FW_NEW COLLADAFW::InstanceNode(instanceNodeUniqueId,instantiatedNodeUniqueId);
		if( attributeData.name )
			instanceNode->setName( attributeData.name );
		currentNode->getInstanceNodes().append(instanceNode);

		return true;
	}
    //------------------------------
	bool NodeLoader::begin__instance_geometry( const instance_geometry__AttributeData& attributeData )
	{
		COLLADAFW::Node* currentNode = mNodeStack.top();

		COLLADAFW::UniqueId instantiatedGeometryUniqueId = getHandlingFilePartLoader()->createUniqueIdFromUrl( attributeData.url, COLLADAFW::Geometry::ID());
		mCurrentMaterialInfo = &getHandlingFilePartLoader()->getMeshMaterialIdInfo();

        COLLADAFW::UniqueId uniqueId = getHandlingFilePartLoader()->createUniqueId ( COLLADAFW::InstanceGeometry::ID() );
		COLLADAFW::InstanceGeometry* instanceGeometry = FW_NEW COLLADAFW::InstanceGeometry ( uniqueId, instantiatedGeometryUniqueId );
		mCurrentInstanceGeometry = instanceGeometry;
		instanceGeometry->setName(currentNode->getName());
		currentNode->getInstanceGeometries().append(instanceGeometry);

		return true;
	}
Exemplo n.º 6
0
	//------------------------------
	bool NodeLoader::beginNode( const node__AttributeData& attributeData )
	{
		COLLADAFW::Node* newNode = new COLLADAFW::Node( getHandlingFilePartLoader()->createUniqueIdFromId(attributeData.id, COLLADAFW::Node::ID()));

		if ( attributeData.name )
			newNode->setName ( (const char*)attributeData.name );
		else if ( attributeData.id )
			newNode->setName ( (const char*)attributeData.id );

        if ( attributeData.id )
            newNode->setOriginalId ( (const char*)attributeData.id );

        if ( attributeData.type == ENUM__NodeType__JOINT )
            newNode->setType ( COLLADAFW::Node::JOINT );

		getHandlingFilePartLoader()->addToSidTree(attributeData.id, attributeData.sid, newNode);

		if ( mNodeStack.empty() )
		{
			// we are a direct child of a container
			handleRootNode(newNode);
		}
		else
		{
			//we are a child of another node
			COLLADAFW::Node* parentNode = mNodeStack.top();
			parentNode->getChildNodes().append(newNode);
		}
		mNodeStack.push(newNode);
		return true;
	}
	//------------------------------
	bool NodeLoader::begin__instance_controller( const instance_controller__AttributeData& attributeData )
	{
		COLLADAFW::Node* currentNode = mNodeStack.top();
		COLLADAFW::UniqueId instantiatedControllerUniqueId = getHandlingFilePartLoader()->createUniqueIdFromUrl( attributeData.url, COLLADAFW::SkinControllerData::ID() );
		mCurrentMaterialInfo = &getHandlingFilePartLoader()->getMeshMaterialIdInfo();

        COLLADAFW::UniqueId uniqueId = getHandlingFilePartLoader()->createUniqueId ( COLLADAFW::InstanceController::ID() );
		COLLADAFW::InstanceController* instanceController = FW_NEW COLLADAFW::InstanceController( uniqueId, instantiatedControllerUniqueId);
		mCurrentInstanceController = instanceController;
		currentNode->getInstanceControllers().append(instanceController);

		Loader::InstanceControllerData instanceControllerData;
		instanceControllerData.instanceController = instanceController;
		Loader::InstanceControllerDataList& instanceControllerDataList = getHandlingFilePartLoader()->getInstanceControllerDataListByControllerUniqueId(instantiatedControllerUniqueId);
		instanceControllerDataList.push_back(instanceControllerData);
		mCurrentInstanceControllerData = &instanceControllerDataList.back();

		return true;
	}
	//--------------------------------------------------------------------
	bool Nebula3Writer::importNode ( const COLLADAFW::Node* node,const COLLADAFW::Node* parentNode)
	{
		const COLLADAFW::UniqueId& uniqueId = node->getUniqueId ();			
		this->mNodeMaps.Add(uniqueId,NodeData());
		NodeData& nodeData = this->mNodeMaps[uniqueId];
		nodeData.nodeName = this->generaterNodeName(node);
		nodeData.nodeUniqueId = uniqueId;
		if( node->getType() == COLLADAFW::Node::JOINT ) nodeData.nodeType = NodeData::JOINT;
		this->importTransformations(node,nodeData);
		//n_printf("importNode [%s] ......\n",nodeData.nodeName.AsCharPtr());
		
		/// ¸¸×Ó¹Øϵ
		if( parentNode!=NULL ) 
		{
			nodeData.parentUniqueId = parentNode->getUniqueId();			
		}	

		if( node->getType() == COLLADAFW::Node::JOINT )
		{
			const Util::Array<COLLADAFW::UniqueId>& keys = this->mCharacterDatas.KeysAsArray();
			for (int i=0; i< keys.Size();i++)
			{
				const COLLADAFW::UniqueId& jointId = keys[i];
				CharacterData& characterData = this->mCharacterDatas[jointId];
				if( characterData.rootUniqueId.isValid()) continue;
				characterData.rootUniqueId = uniqueId;
			}///end for
		}	

		// Go through the controller instances and save the ids to the current node.
		const COLLADAFW::InstanceControllerArray& controllerInstances = node->getInstanceControllers ();
		size_t numInstances = controllerInstances.getCount ();
		for ( size_t i=0; i<numInstances; ++i )
		{
			const COLLADAFW::InstanceController* instanceController = controllerInstances [i];
			const COLLADAFW::UniqueId& controllerId = instanceController->getInstanciatedObjectId ();
			mControllerNodeMaps.Add(controllerId,uniqueId);
			mInstanceNodeMaps.Add(controllerId,uniqueId);
			nodeData.controllerUniqueIds.Append(controllerId);

			const MaterialBindingArray& materialArray = instanceController->getMaterialBindings();
			this->getMaterialBinding(nodeData,materialArray);
		}

		// Go through the geometry instances and save the ids to the current node.
		const COLLADAFW::InstanceGeometryPointerArray& geometryInstances = node->getInstanceGeometries ();
		numInstances = geometryInstances.getCount ();
		for ( size_t i=0; i<numInstances; ++i )
		{
			const COLLADAFW::InstanceGeometry* instanceGeometry = geometryInstances [i];
			const COLLADAFW::UniqueId& geometryId = instanceGeometry->getInstanciatedObjectId ();
			mGeometryNodeMaps.Add(geometryId,uniqueId);
			mInstanceNodeMaps.Add(geometryId,uniqueId);
			nodeData.geometryUniqueIds.Append(geometryId);

			const MaterialBindingArray& materialArray = instanceGeometry->getMaterialBindings();
			this->getMaterialBinding(nodeData,materialArray);
			
		}///end for

		// Recursive call for all child elements.
		const COLLADAFW::NodeArray& childNodes = node->getChildNodes ();
		size_t numChildNodes = childNodes.getCount ();
		for ( size_t i=0; i<numChildNodes; ++i )
		{
			COLLADAFW::Node* childNode = childNodes [i];
			nodeData.childUniqueIds.Append(childNode->getUniqueId());
		}

		for ( size_t i=0; i<numChildNodes; ++i )
		{
			COLLADAFW::Node* childNode = childNodes [i];		
			importNode ( childNode, node);
		}
		return true;
	}