G
Garlfin
Guest
I have the code below to write a simple collada dae for a project I am working on. The code works but not in the way i need it to.
It outputs this: <COLLADA xmlns="COLLADA 1.4 Schema" version="1.4.1">
<stuffinside xmlns=" "></stuffinside>
</COLLADA>
Instead of this: <COLLADA xmlns="COLLADA 1.4 Schema" version="1.4.1">
<stuffinside></stuffinside>
</COLLADA>
Here is my code:
XNamespace xNamespace = "COLLADA 1.4 Schema";
XDocument doc =
new XDocument(
new XElement(xNamespace + "COLLADA",new XAttribute("xmlns", "COLLADA 1.4 Schema"),new XAttribute("version", "1.4.1"),
new XElement("asset", new XElement("contributor", new XElement("authoring_tool", "sc3dparser")), new XElement("created", DateTime.Now),
new XElement("unit", new XAttribute("name", "meter"), new XAttribute("meter", "1")), new XElement("up_axis", "Y_UP")),
new XElement("library_geometries", new XElement("geometry", new XAttribute("id", "cube-mesh"), new XAttribute("name", "Cube"), new XElement("mesh",
new XElement("source", new XAttribute("id", "cube-mesh-positions"), new XElement("float_array", new XAttribute("id", "cube-mesh-positions-array"),
new XAttribute("count", "24"), "-1 -1 -1 -1 -1 1 -1 1 -1 -1 1 1 1 -1 -1 1 -1 1 1 1 -1 1 1 1"
), new XElement("technique_common", new XElement("accessor", new XAttribute("source", "#cube-mesh-positions-array"), new XAttribute("count", "8"), new XAttribute("stride", "3"),
list.Select(x => new XElement("param", new XAttribute("name", x), new XAttribute("type", "float"))
)))
), new XElement("source", new XAttribute("id", "cube-mesh-normals"), new XElement("float_array", new XAttribute("id", "cube-mesh-normals-array")
, new XAttribute("count", "18"), "-1 0 0 0 1 0 1 0 0 0 -1 0 0 0 -1 0 0 1"), new XElement("technique_common", new XElement("accessor", new XAttribute(
"source", "#cube-mesh-normals-array"), new XAttribute("count", "6"), new XAttribute("stride", "3"), list.Select(x => new XElement("param", new XAttribute("name", x), new XAttribute("type", "float")))))
),new XElement("source",new XAttribute("id","cube-mesh-map-0"),new XElement("float_array",new XAttribute("id","cube-mesh-map-0-array"),new XAttribute("count","72"), "0.625 0 0.375 0.25 0.375 0 0.625 0.25 0.375 0.5 0.375 0.25 0.625 0.5 0.375 0.75 0.375 0.5 0.625 0.75 0.375 1 0.375 0.75 0.375 0.5 0.125 0.75 0.125 0.5 0.875 0.5 0.625 0.75 0.625 0.5 0.625 0 0.625 0.25 0.375 0.25 0.625 0.25 0.625 0.5 0.375 0.5 0.625 0.5 0.625 0.75 0.375 0.75 0.625 0.75 0.625 1 0.375 1 0.375 0.5 0.375 0.75 0.125 0.75 0.875 0.5 0.875 0.75 0.625 0.75")
,new XElement("technique_common",new XElement("accessor",new XAttribute("source","#cube-mesh-map-0-array"),new XAttribute("count","36")
,new XAttribute("stride","2"), list2.Select(x => new XElement("param", new XAttribute("name", x), new XAttribute("type", "float"))))
)),new XElement("vertices",new XAttribute("id","cube-mesh-vertices"),new XElement("input", new XAttribute("semantic","POSITION")
,new XAttribute("source","#cube-mesh-positions"))),new XElement("triangles",new XAttribute("count","12"), new XElement("input",new XAttribute
("semantic","VERTEX"), new XAttribute
("source", "#cube-mesh-vertices"), new XAttribute
("offset", "0")), new XElement("input", new XAttribute
("semantic", "NORMAL"), new XAttribute
("source", "#cube-mesh-normals"), new XAttribute
("offset", "1")), new XElement("input", new XAttribute
("semantic", "TEXCOORD"), new XAttribute
("source", "#cube-mesh-map-0"), new XAttribute
("offset", "2")), new XElement("p", "1 0 0 2 0 1 0 0 2 3 1 3 6 1 4 2 1 5 7 2 6 4 2 7 6 2 8 5 3 9 0 3 10 4 3 11 6 4 12 0 4 13 2 4 14 3 5 15 5 5 16 7 5 17 1 0 18 3 0 19 2 0 20 3 1 21 7 1 22 6 1 23 7 2 24 5 2 25 4 2 26 5 3 27 1 3 28 0 3 29 6 4 30 4 4 31 0 4 32 3 5 33 1 5 34 5 5 35")
)))
),new XElement("library_visual_scenes",new XElement("visual_scene",new XAttribute("id","scene"),new XAttribute("name","Scene"),new XElement
("node",new XAttribute("id","cube"),new XAttribute("name","Cube"),new XAttribute("type","NODE"),new XElement("matrix",new XAttribute("sid","transform")
, "1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1"),new XElement("instance_geometry",new XAttribute("url","#cube-mesh"),new XAttribute("name","Cube"))))), new XElement("scene", new XElement("instance_visual_scene", new XAttribute("url", "#scene")))
));
doc.Save(@"C:\Users\scion\Desktop\test.dae");
Griffin
Continue reading...
It outputs this: <COLLADA xmlns="COLLADA 1.4 Schema" version="1.4.1">
<stuffinside xmlns=" "></stuffinside>
</COLLADA>
Instead of this: <COLLADA xmlns="COLLADA 1.4 Schema" version="1.4.1">
<stuffinside></stuffinside>
</COLLADA>
Here is my code:
XNamespace xNamespace = "COLLADA 1.4 Schema";
XDocument doc =
new XDocument(
new XElement(xNamespace + "COLLADA",new XAttribute("xmlns", "COLLADA 1.4 Schema"),new XAttribute("version", "1.4.1"),
new XElement("asset", new XElement("contributor", new XElement("authoring_tool", "sc3dparser")), new XElement("created", DateTime.Now),
new XElement("unit", new XAttribute("name", "meter"), new XAttribute("meter", "1")), new XElement("up_axis", "Y_UP")),
new XElement("library_geometries", new XElement("geometry", new XAttribute("id", "cube-mesh"), new XAttribute("name", "Cube"), new XElement("mesh",
new XElement("source", new XAttribute("id", "cube-mesh-positions"), new XElement("float_array", new XAttribute("id", "cube-mesh-positions-array"),
new XAttribute("count", "24"), "-1 -1 -1 -1 -1 1 -1 1 -1 -1 1 1 1 -1 -1 1 -1 1 1 1 -1 1 1 1"
), new XElement("technique_common", new XElement("accessor", new XAttribute("source", "#cube-mesh-positions-array"), new XAttribute("count", "8"), new XAttribute("stride", "3"),
list.Select(x => new XElement("param", new XAttribute("name", x), new XAttribute("type", "float"))
)))
), new XElement("source", new XAttribute("id", "cube-mesh-normals"), new XElement("float_array", new XAttribute("id", "cube-mesh-normals-array")
, new XAttribute("count", "18"), "-1 0 0 0 1 0 1 0 0 0 -1 0 0 0 -1 0 0 1"), new XElement("technique_common", new XElement("accessor", new XAttribute(
"source", "#cube-mesh-normals-array"), new XAttribute("count", "6"), new XAttribute("stride", "3"), list.Select(x => new XElement("param", new XAttribute("name", x), new XAttribute("type", "float")))))
),new XElement("source",new XAttribute("id","cube-mesh-map-0"),new XElement("float_array",new XAttribute("id","cube-mesh-map-0-array"),new XAttribute("count","72"), "0.625 0 0.375 0.25 0.375 0 0.625 0.25 0.375 0.5 0.375 0.25 0.625 0.5 0.375 0.75 0.375 0.5 0.625 0.75 0.375 1 0.375 0.75 0.375 0.5 0.125 0.75 0.125 0.5 0.875 0.5 0.625 0.75 0.625 0.5 0.625 0 0.625 0.25 0.375 0.25 0.625 0.25 0.625 0.5 0.375 0.5 0.625 0.5 0.625 0.75 0.375 0.75 0.625 0.75 0.625 1 0.375 1 0.375 0.5 0.375 0.75 0.125 0.75 0.875 0.5 0.875 0.75 0.625 0.75")
,new XElement("technique_common",new XElement("accessor",new XAttribute("source","#cube-mesh-map-0-array"),new XAttribute("count","36")
,new XAttribute("stride","2"), list2.Select(x => new XElement("param", new XAttribute("name", x), new XAttribute("type", "float"))))
)),new XElement("vertices",new XAttribute("id","cube-mesh-vertices"),new XElement("input", new XAttribute("semantic","POSITION")
,new XAttribute("source","#cube-mesh-positions"))),new XElement("triangles",new XAttribute("count","12"), new XElement("input",new XAttribute
("semantic","VERTEX"), new XAttribute
("source", "#cube-mesh-vertices"), new XAttribute
("offset", "0")), new XElement("input", new XAttribute
("semantic", "NORMAL"), new XAttribute
("source", "#cube-mesh-normals"), new XAttribute
("offset", "1")), new XElement("input", new XAttribute
("semantic", "TEXCOORD"), new XAttribute
("source", "#cube-mesh-map-0"), new XAttribute
("offset", "2")), new XElement("p", "1 0 0 2 0 1 0 0 2 3 1 3 6 1 4 2 1 5 7 2 6 4 2 7 6 2 8 5 3 9 0 3 10 4 3 11 6 4 12 0 4 13 2 4 14 3 5 15 5 5 16 7 5 17 1 0 18 3 0 19 2 0 20 3 1 21 7 1 22 6 1 23 7 2 24 5 2 25 4 2 26 5 3 27 1 3 28 0 3 29 6 4 30 4 4 31 0 4 32 3 5 33 1 5 34 5 5 35")
)))
),new XElement("library_visual_scenes",new XElement("visual_scene",new XAttribute("id","scene"),new XAttribute("name","Scene"),new XElement
("node",new XAttribute("id","cube"),new XAttribute("name","Cube"),new XAttribute("type","NODE"),new XElement("matrix",new XAttribute("sid","transform")
, "1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1"),new XElement("instance_geometry",new XAttribute("url","#cube-mesh"),new XAttribute("name","Cube"))))), new XElement("scene", new XElement("instance_visual_scene", new XAttribute("url", "#scene")))
));
doc.Save(@"C:\Users\scion\Desktop\test.dae");
Griffin
Continue reading...