private void UpdateHierarchyImpl(Scene scene) { Nodes.Clear(); //set up scene nodes TreeNode node = new SceneNodeWrapper(scene.RootNode, Img_Node); CreateNodes(node, scene.RootNode); Nodes.Add(node); }
private void CreateTextureNode(SceneNodeWrapper parent, Material mat, String texName) { var tex = mat.GetTexture(texName); if (tex == null) { return; } var texNode = new SceneNodeWrapper(tex, Img_Material); parent.Nodes.Add(texNode); }
private void CreateNodes(TreeNode node, Node sceneNode) { foreach (Node childNode in sceneNode.ChildNodes) { if (ABUtils.IsHidden(childNode)) { continue; } TreeNode childTree = new SceneNodeWrapper(childNode, Img_Node); CreateNodes(childTree, childNode); node.Nodes.Add(childTree); } //create entity nodes foreach (Entity entity in sceneNode.Entities) { if (ABUtils.IsHidden(entity)) { continue; } int img = Img_Geometry; if (entity is Camera) { img = Img_Camera; } else if (entity is Light) { img = Img_Light; } node.Nodes.Add(new SceneNodeWrapper(entity, img)); } //create material nodes foreach (Material mat in sceneNode.Materials) { if (mat == null) { continue; } var matNode = new SceneNodeWrapper(mat, Img_Material); CreateTextureNode(matNode, mat, Material.MapDiffuse); CreateTextureNode(matNode, mat, Material.MapAmbient); CreateTextureNode(matNode, mat, Material.MapEmissive); CreateTextureNode(matNode, mat, Material.MapNormal); CreateTextureNode(matNode, mat, "Occlusion"); CreateTextureNode(matNode, mat, "MetallicRoughness"); node.Nodes.Add(matNode); } }
private void CreateNodes(TreeNode node, Node sceneNode) { foreach (Node childNode in sceneNode.ChildNodes) { if (ABUtils.IsHidden(childNode)) { continue; } TreeNode childTree = new SceneNodeWrapper(childNode, Img_Node); CreateNodes(childTree, childNode); node.Nodes.Add(childTree); } //create entity nodes foreach (Entity entity in sceneNode.Entities) { if (ABUtils.IsHidden(entity)) { continue; } int img = Img_Geometry; if (entity is Camera) { img = Img_Camera; } else if (entity is Light) { img = Img_Light; } node.Nodes.Add(new SceneNodeWrapper(entity, img)); } //create material nodes foreach (Material mat in sceneNode.Materials) { node.Nodes.Add(new SceneNodeWrapper(mat, Img_Material)); } }
/** * Parses the mesh component into a mass-spring system */ private void parseMesh() { def = transform.Find("default"); MeshFilter mf = def.GetComponent <MeshFilter> (); Mesh mesh = mf.mesh; int[] triangles = mesh.triangles; Vector3[] vertices = mesh.vertices; List <SceneNode> nodes = new List <SceneNode> (); SceneNode[] arrayNode = new SceneNode[vertices.Length]; GameObject nodesParent = new GameObject(); nodesParent.name = "Nodes"; nodesParent.transform.parent = def; nodesParent.transform.localPosition = Vector3.zero; GameObject topLeftCorner = null; GameObject topRightCorner = null; float lowerY = float.PositiveInfinity; float higherY = float.NegativeInfinity; float rightMostX = float.NegativeInfinity; for (int i = 0; i < vertices.Length; i++) { Vector3 v = vertices [i]; // Create new scene node GameObject empty = new GameObject(); empty.transform.parent = nodesParent.transform; empty.name = "Node_" + i; empty.transform.localPosition = v; #if C_DEBUG GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.parent = empty.transform; sphere.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); sphere.transform.localPosition = Vector3.zero; #endif SceneNode sn = empty.AddComponent <SceneNode> (); sn.Mass = NodeMass; sn.IsFixed = false; SceneNodeWrapper snw = empty.AddComponent <SceneNodeWrapper> (); snw.gObject = def; snw.vertexId = i; nodes.Add(sn); arrayNode [i] = sn; if (v.y <= lowerY) { if (v.z >= rightMostX) { rightMostX = v.z; lowerY = v.y; topLeftCorner = empty; } } if (v.y >= higherY) { if (v.z >= rightMostX) { rightMostX = v.z; higherY = v.y; topRightCorner = empty; } } } topLeftCorner.GetComponent <SceneNode>().IsFixed = true; topRightCorner.GetComponent <SceneNode>().IsFixed = true; GameObject edgesObj = new GameObject(); edgesObj.name = "Edges"; edgesObj.transform.parent = def; edgesObj.transform.localPosition = Vector3.zero; SceneEdges = new List <SceneEdge> (); Dictionary <int[], int> sharedEdges = new Dictionary <int[], int> (new EdgeComparer(vertices.Length)); for (int i = 0; i < triangles.Length; i = i + 3) { int a = triangles [i]; int b = triangles [i + 1]; int c = triangles [i + 2]; // Flexion nodes int[] aEdge = new int[] { b, c }; int[] bEdge = new int[] { c, a }; int[] cEdge = new int[] { a, b }; // A int [] key; if (sharedEdges.ContainsKey((key = aEdge)) || sharedEdges.ContainsKey((key = new int[] { c, b }))) { int other = sharedEdges [key]; SceneEdge oa = CreateEdge(edgesObj.transform, other, a, vertices, false, arrayNode); SceneEdges.Add(oa); sharedEdges.Remove(key); } else { sharedEdges.Add(aEdge, a); SceneEdge bc = CreateEdge(edgesObj.transform, b, c, vertices, true, arrayNode); SceneEdges.Add(bc); } // B if (sharedEdges.ContainsKey((key = bEdge)) || sharedEdges.ContainsKey((key = new int[] { a, c }))) { int other = sharedEdges [key]; SceneEdge ob = CreateEdge(edgesObj.transform, other, b, vertices, false, arrayNode); SceneEdges.Add(ob); sharedEdges.Remove(key); } else { sharedEdges.Add(bEdge, b); SceneEdge ca = CreateEdge(edgesObj.transform, c, a, vertices, true, arrayNode); SceneEdges.Add(ca); } // C if (sharedEdges.ContainsKey((key = cEdge)) || sharedEdges.ContainsKey((key = new int[] { b, a }))) { int other = sharedEdges [key]; SceneEdge oc = CreateEdge(edgesObj.transform, other, c, vertices, false, arrayNode); SceneEdges.Add(oc); sharedEdges.Remove(key); } else { sharedEdges.Add(cEdge, c); SceneEdge ab = CreateEdge(edgesObj.transform, a, b, vertices, true, arrayNode); SceneEdges.Add(ab); } } SceneNodes = new List <SceneNode>(arrayNode); }