private static void ReadHierarchy(HierarchyNode node, List <Light_> lights, List <string> text, int pointer) { string objNumLabel = File.GetAttribute(text[pointer], 0); if (objNumLabel != "node_count") { node = null; } uint objNum = uint.Parse(File.GetAttribute(text[pointer++], 1)); for (int i = 0; i < objNum; ++i) { HierarchyObject newObject = null; string objStrLabel = File.GetAttribute(text[pointer], 0); if (objStrLabel != "hier_type") { node = null; } string objStr = File.GetAttribute(text[pointer++], 1); string objNameLabel = File.GetAttribute(text[pointer], 0); if (objNameLabel != "hier_name") { node = null; } string objName = File.GetAttribute(text[pointer++], 1); switch (objStr) { case "Mesh": newObject = new HierarchyMesh(objName); node.hObjects.Add(newObject); string triangleNumLabel = File.GetAttribute(text[pointer], 0); if (triangleNumLabel != "triangle_count") { node = null; } uint triangleNum = uint.Parse(File.GetAttribute(text[pointer++], 1)); List <uint> triangles = new List <uint>(); string[] triangs = File.GetAttributes(text[pointer]); for (int j = 0; j < triangleNum; ++j) { triangles.Add(uint.Parse(triangs[j])); } ++pointer; ((HierarchyMesh)newObject).triangles = triangles; break; case "Light": newObject = new HierarchyLight(GetLightByName(lights, objName)); node.hObjects.Add(newObject); break; case "Node": newObject = new HierarchyNode(objName); node.hObjects.Add(newObject); ReadHierarchy((HierarchyNode)newObject, lights, text, pointer); break; } } }
//warto dodać listę wszystkich meshy i świateł żeby ich nie szukać za każdym razem //private void selectingFromHierarchy(TreeViewItem node, bool selAll) //warto dodać listę wszystkich meshy i świateł żeby ich nie szukać za każdym razem //{ // if (node.HasItems && !node.IsSelected && !selAll) // jesteśmy w węźle, przechodzimy w głąb bez zaznaczania // { // //Console.WriteLine("wchodzimy głębiej, zaznaczenia nie znaleziono"); // foreach (TreeViewItem tvi in node.Items) // { // selectingFromHierarchy(tvi, false); // } // } // else if (node.HasItems && !node.IsSelected && selAll || node.HasItems && node.IsSelected) // jesteśmy w węźle, przechodzimy w głąb i zaznaczamy wszystko // { // //Console.WriteLine("wchodzimy głebiej zaznaczając wszystkie meshe, bo: jesteśmy w zaznaczonym/ weszliśmy już"); // foreach (TreeViewItem tvi in node.Items) // { // selectingFromHierarchy(tvi, true); // } // } // else if (!node.IsSelected && selAll || node.IsSelected) //mesh(lub light), którego dodajemy do zaznaczonych // { // char[] delimiterChars = { '_' }; // string[] words = node.Name.Split(delimiterChars); // if (words[0].Equals("mesh")) // selectMesh(Convert.ToInt32(words[1]), currScene.hierarchy.objects); // else // { // Console.WriteLine("zaznaczamy swiatlo " + words[0].ToString() + " " + words[1].ToString()); // //selectLight(node.Name, lights); // currScene.selLights.Add(Convert.ToInt32(words[1])); // } // } //} private void selectingFromHierarchy(TreeViewItem node, HierarchyObject ho, bool selAll, bool found) { if (node.HasItems && !node.IsSelected && !selAll) // jesteśmy w węźle, przechodzimy w głąb bez zaznaczania { if (ho is HierarchyNode) { //HierarchyNode hn = new HierarchyNode(ho.name); HierarchyNode hn = (HierarchyNode)ho; //Console.WriteLine("ho "+hn.hObjects.Count + " tvi " + node.Items.Count); //Console.WriteLine("wchodzimy głębiej, zaznaczenia nie znaleziono"); //foreach (TreeViewItem tvi in node.Items) for (int i = 0; i < node.Items.Count; i++) { selectingFromHierarchy((TreeViewItem)node.Items.GetItemAt(i), (HierarchyObject)(hn.hObjects.ElementAt(i)), false, found); } } //else //Console.WriteLine("hierarchie sie nie pokrywaja1"); } else if (node.HasItems && !node.IsSelected && selAll)// || node.HasItems && node.IsSelected) // jesteśmy w węźle, przechodzimy w głąb i zaznaczamy wszystko { if (ho is HierarchyNode) { //Console.WriteLine("asdaasfa"); //HierarchyNode hn = new HierarchyNode(ho.name); HierarchyNode hn = (HierarchyNode)ho; //Console.WriteLine("wchodzimy głebiej zaznaczając wszystkie meshe, bo: jesteśmy w zaznaczonym/ weszliśmy już"); for (int i = 0; i < node.Items.Count; i++) { selectingFromHierarchy((TreeViewItem) node.Items.GetItemAt(i), (HierarchyObject) (hn.hObjects.ElementAt(i)), true, found); } } //else //Console.WriteLine("hierarchie sie nie pokrywaja2"); } else if (node.HasItems && node.HasItems && node.IsSelected) // jesteśmy w węźle zaznaczonym, przechodzimy w głąb i zaznaczamy wszystko { if (ho is HierarchyNode) { //Console.WriteLine("asdasfdqwfdq"); //HierarchyNode hn = new HierarchyNode(ho.name); HierarchyNode hn = (HierarchyNode)ho; if (!found) { currScene.selectedHierObj = (HierarchyNode) ho; found = true; } //currScene.addWithHierarchy = true; for (int i = 0; i < node.Items.Count; i++) { selectingFromHierarchy((TreeViewItem)node.Items.GetItemAt(i), (HierarchyObject)(hn.hObjects.ElementAt(i)), true, found); } } //else //Console.WriteLine("hierarchie sie nie pokrywaja3"); } else if (!node.IsSelected && selAll || node.IsSelected) //mesh(lub light), którego dodajemy do zaznaczonych { char[] delimiterChars = { '_' }; string[] words = node.Name.Split(delimiterChars); if (words[0].Equals("mesh")) selectMesh(Convert.ToInt32(words[1]), currScene.hierarchy.objects); else { //Console.WriteLine("zaznaczamy swiatlo " + words[0].ToString() + " " + words[1].ToString()); //selectLight(node.Name, lights); currScene.selLights.Add(Convert.ToInt32(words[1])); } } }
private static void ReadHierarchy(HierarchyNode node, List <Light_> lights, List <string> text, ref int pointer) { string objNumLabel = File.GetAttribute(text[pointer], 0); if (objNumLabel != "node_count") { throw new Exception(); } uint objNum = uint.Parse(File.GetAttribute(text[pointer++], 1)); for (int i = 0; i < objNum; ++i) { HierarchyObject newObject = null; string objStrLabel = File.GetAttribute(text[pointer], 0); if (objStrLabel != "hier_type") { throw new Exception(); } string objStr = File.GetAttribute(text[pointer++], 1); string[] objNameAtts = File.GetAttributes(text[pointer]); if (objNameAtts[0] != "hier_name") { throw new Exception(); } string objName = objName = File.CutFirstString(text[pointer]); ++pointer; switch (objStr) { case "Mesh": newObject = new HierarchyMesh(objName); node.hObjects.Add(newObject); string triangleNumLabel = File.GetAttribute(text[pointer], 0); if (triangleNumLabel != "triangle_count") { new Exception(); } uint triangleNum = uint.Parse(File.GetAttribute(text[pointer++], 1)); List <uint> triangles = new List <uint>(); string[] triangs = File.GetAttributes(text[pointer]); for (int j = 0; j < triangleNum; ++j) { triangles.Add(uint.Parse(triangs[j])); } ++pointer; ((HierarchyMesh)newObject).triangles = triangles; break; case "Light": string lightIdxLabel = File.GetAttribute(text[pointer], 0); if (lightIdxLabel != "light_index") { new Exception(); } int lightIdx = int.Parse(File.GetAttribute(text[pointer++], 1)); newObject = new HierarchyLight(objName, lightIdx); node.hObjects.Add(newObject); break; case "Node": newObject = new HierarchyNode(objName); node.hObjects.Add(newObject); ReadHierarchy((HierarchyNode)newObject, lights, text, ref pointer); break; } } }