How to split the scene in some parts?

Hello all,

I have a big collada files that contains meshs.
I’m trying to split it in some smaller parts, but there is a strange bug in final files.

This is my code:


	FCollada::Initialize();
	FCDocument*	document_loaded = FCollada::NewTopDocument();	
	FCollada::LoadDocumentFromFile(document_loaded, fullpath.c_str());	

	FUObjectRef<FCDocument> global_document = FCollada::NewTopDocument();	
	FCDSceneNode* global_top = global_document->AddVisualScene();
	FCDSceneNode* global_second = global_top->AddChildNode();
	
	int global_counter = -1;
	for (int i=0; i<(int)parser.meshs.size(); i++){
		if (parser.meshs[i].m_bneedtosave == true){
				string save_id = parser.meshs[i].meshDaeID;
				FCDGeometry* geometry = document_loaded->GetGeometryLibrary()->FindDaeId(save_id.c_str());
				if (!geometry) cout << " NULL " <<  save_id << endl;
				
				global_document->GetGeometryLibrary()->AddEntity(geometry);
				global_counter++;
				FCDEntity* global_entity = (FCDEntity*)global_document->GetGeometryLibrary()->GetEntity(global_counter);
				
				FCDSceneNode *node = global_second->AddChildNode();
				node->AddInstance(global_entity);
				global_document->GetVisualSceneLibrary()->AddEntity(node);
		}
	}
	global_top->AddInstance(global_second);
	if (!FCollada::SaveDocument(global_document, FC("./global.dae"))) cout << " fail to save global document"<< endl;
	else {
	}
	FCollada::Release();

Now I have the meshs that ‘need to save’
But in the global.dae, I have a stragne format, some things like this:


<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
  <asset>
    <created>2009-07-31T08:12:35Z</created>
    <modified>2009-07-31T08:14:58Z</modified>
  </asset>

  <library_geometries>
    <geometry id="geoid1007" name="geoid1007">
      <mesh>
      ... data ...
      </mesh>
    </geometry>
  </library_geometries>

  <library_visual_scenes>
    <visual_scene id="VisualSceneNode">
      <instance_node url="#VisualSceneNode1"/>
        <node id="VisualSceneNode1" type="NODE">

          <node id="VisualSceneNode2" type="NODE">
            <instance_geometry url="#geoid1007"/>
          </node>

          <node id="VisualSceneNode3" type="NODE">
            <instance_geometry url="#geoid1009"/>
          </node>

          ... data ...

      </node>
    </visual_scene>

    <node id="VisualSceneNode2" type="NODE">
      <instance_geometry url="#geoid1007"/>
    </node>

    <node id="VisualSceneNode3" type="NODE">
      <instance_geometry url="#geoid1009"/>
    </node>
    ... data ...
  </library_visual_scenes>
  <scene>
    <instance_visual_scene url="#VisualSceneNode"/>
  </scene>
</COLLADA>

Can some one tell me how to fix this bug?

I’m not sure which FCollada call you are making that is creating the <instance_node> there, but it’s not a valid child of <visual_scene>.

That’s probably your problem.

I’m using FCollada from feelingsoftware:
http://www.feelingsoftware.com/content/ … 6/lang,en/

Can someone shows me how to make in right fotmat?

My new code is:


	FCollada::Initialize();
	FCDocument*	document_loaded = FCollada::NewTopDocument();	
	FCollada::LoadDocumentFromFile(document_loaded, fullpath.c_str());	


	FUObjectRef<FCDocument> global_document = FCollada::NewTopDocument();	
	FCDSceneNode* global_top = global_document->AddVisualScene();
	
	int global_counter = -1;
	for (int i=0; i<(int)parser.meshs.size(); i++){
		if (parser.meshs[i].m_bneedtosave == true){
				string save_id = parser.meshs[i].meshDaeID;
				FCDGeometry* geometry = document_loaded->GetGeometryLibrary()->FindDaeId(save_id.c_str());
				if (!geometry) cout << " NULL " <<  save_id << endl;
				
				global_document->GetGeometryLibrary()->AddEntity(geometry);
				global_counter++;
				FCDEntity* global_entity = (FCDEntity*)global_document->GetGeometryLibrary()->GetEntity(global_counter);
				
				FCDSceneNode* global_second = global_top->AddChildNode();
				global_second->AddInstance(global_entity);
				global_top->AddInstance(global_second);
		}
	}
	if (!FCollada::SaveDocument(global_document, FC("./global.dae"))) cout << " fail to save global document"<< endl;
	FCollada::Release();

And I got a file like this:


........................................

      </mesh>
    </geometry>
  </library_geometries>
  <library_visual_scenes>
    <visual_scene id="VisualSceneNode">
      <instance_node url="#VisualSceneNode1"/>

........................................................

      <instance_node url="#VisualSceneNode1464"/>
      <instance_node url="#VisualSceneNode1465"/>
      <node id="VisualSceneNode1" type="NODE">
        <instance_geometry url="#geoid1007"/>
      </node>
      <node id="VisualSceneNode2" type="NODE">
        <instance_geometry url="#geoid1009"/>
      </node>

..................................

      <node id="VisualSceneNode1464" type="NODE">
        <instance_geometry url="#geoid979"/>
      </node>
      <node id="VisualSceneNode1465" type="NODE">
        <instance_geometry url="#geoid983"/>
      </node>
    </visual_scene>
  </library_visual_scenes>
  <scene>
    <instance_visual_scene url="#VisualSceneNode"/>
  </scene>
</COLLADA>

I don’t know if it was in right format, but at least the viewer (Deep Exploration 5.0.2) can show it

Thanks,

[quote=“marcus”]

I’m not sure which FCollada call you are making that is creating the <instance_node> there, but it’s not a valid child of <visual_scene>.

That’s probably your problem.[/quote]

Your output is still invalid because you can’t have <instance_node> as a child of <visual_scene>.

Try using the Coherency Checker that is part of the COLLADA Refinery project on sourceforge to test your output.

Now I have the same result on the screen of Deep Exploration, but my file format changed to:



...........................................

    </geometry>
  </library_geometries>
  <library_visual_scenes>
    <visual_scene id="VisualSceneNode">
      <node id="VisualSceneNode1" type="NODE">
        <instance_geometry url="#geoid1007"/>
      </node>
      <node id="VisualSceneNode2" type="NODE">
        <instance_geometry url="#geoid1009"/>
      </node>
      <node id="VisualSceneNode3" type="NODE">
        <instance_geometry url="#geoid1011"/>
      </node>

...........................................

    </visual_scene>
  </library_visual_scenes>
  <scene>
    <instance_visual_scene url="#VisualSceneNode"/>
  </scene>
</COLLADA>


Hope that it’s ok

Yes that looks valid.