コード例 #1
0
 public CollisionGroupNode(CollisionGroupNode root, string name)
 {
     Name      = name;
     Triangles = new List <CollisionTriangle>();
     Children  = new ObservableCollection <CollisionGroupNode>();
     Parent    = root;
     m_Scale   = Vector3.One;
 }
コード例 #2
0
        public OctreeNode(FAABox bounds, CollisionGroupNode node, List <CollisionTriangle> triangles)
        {
            Triangles = triangles;
            Bounds    = bounds;
            Group     = node;

            Children = new OctreeNode[8];

            SortTriangles();
        }
コード例 #3
0
        public CollisionTriangle(Vector3 v1, Vector3 v2, Vector3 v3, CollisionGroupNode parent)
        {
            Vertices    = new Vector3[] { v1, v2, v3 };
            VertexColor = WLinearColor.FromHexString("0xB0E0C0FF");

            Properties  = new CollisionProperty();
            ParentGroup = parent;

            CalculateCenter();
        }
コード例 #4
0
        private void LoadGeometryFromCollada(CollisionGroupNode parent, geometry geo)
        {
            mesh m = geo.Item as mesh;

            // For safety, read the model's definition of where the position data is
            // and grab it from there. We could just do a search for "position" in the
            // source list names, but this makes sure there are no errors.
            InputLocal  pos_input = Array.Find(m.vertices.input, x => x.semantic == "POSITION");
            source      pos_src   = Array.Find(m.source, x => x.id == pos_input.source.Trim('#'));
            float_array pos_arr   = pos_src.Item as float_array;

            // For some reason Maya puts a leading space in the face index data,
            // so we need to trim that out before trying to parse the index string.
            triangles tris = m.Items[0] as triangles;

            string[] indices = tris.p.Trim(' ').Split(' ');
            int      stride  = tris.input.Length; // Make sure this tool can support meshes with multiple vertex attributes.

            for (int i = 0; i < indices.Length; i += stride * 3)
            {
                int vec1_index = Convert.ToInt32(indices[i]);
                int vec2_index = Convert.ToInt32(indices[i + stride]);
                int vec3_index = Convert.ToInt32(indices[i + (stride * 2)]);

                Vector3 vec1 = new Vector3((float)pos_arr.Values[vec1_index * 3],
                                           (float)pos_arr.Values[(vec1_index * 3) + 1],
                                           (float)pos_arr.Values[(vec1_index * 3) + 2]);

                Vector3 vec2 = new Vector3((float)pos_arr.Values[vec2_index * 3],
                                           (float)pos_arr.Values[(vec2_index * 3) + 1],
                                           (float)pos_arr.Values[(vec2_index * 3) + 2]);

                Vector3 vec3 = new Vector3((float)pos_arr.Values[vec3_index * 3],
                                           (float)pos_arr.Values[(vec3_index * 3) + 1],
                                           (float)pos_arr.Values[(vec3_index * 3) + 2]);

                // The benefit of using this library is that we easily got the up-axis
                // info from the file. If the up-axis was defined as Z-up, we need to
                // swap the Y and Z components of our vectors so the mesh isn't sideways.
                // (The Wind Waker is Y-up.)
                if (m_UpAxis == UpAxisType.Z_UP)
                {
                    vec1 = SwapYZ(vec1);
                    vec2 = SwapYZ(vec2);
                    vec3 = SwapYZ(vec3);
                }

                CollisionTriangle new_tri = new CollisionTriangle(vec1, vec2, vec3, parent);

                parent.Triangles.Add(new_tri);
                Triangles.Add(new_tri);
            }
        }
コード例 #5
0
        public void InflateHierarchyRecursive(CollisionGroupNode last_parent, List <CollisionGroupNode> flat_hierarchy)
        {
            if (last_parent != null)
            {
                Parent = last_parent;
                last_parent.Children.Add(this);
            }

            if (m_FirstChildIndex != -1)
            {
                flat_hierarchy[m_FirstChildIndex].InflateHierarchyRecursive(this, flat_hierarchy);
            }

            if (m_NextSiblingIndex != -1)
            {
                flat_hierarchy[m_NextSiblingIndex].InflateHierarchyRecursive(last_parent, flat_hierarchy);
            }
        }
コード例 #6
0
        private CollisionGroupNode LoadGroupsFromColladaRecursive(CollisionGroupNode parent, node dae_node, geometry[] meshes)
        {
            CollisionGroupNode new_node = new CollisionGroupNode(parent, dae_node.name);

            m_Nodes.Add(new_node);

            if (dae_node.instance_geometry != null)
            {
                string   mesh_id  = dae_node.instance_geometry[0].url.Trim('#');
                geometry node_geo = Array.Find(meshes, x => x.id == mesh_id);

                LoadGeometryFromCollada(new_node, node_geo);
            }

            if (dae_node.node1 != null)
            {
                foreach (node n in dae_node.node1)
                {
                    new_node.Children.Add(LoadGroupsFromColladaRecursive(new_node, n, meshes));
                }
            }

            return(new_node);
        }
コード例 #7
0
        private void LoadFromObj(string[] lines, int roomIndex, int roomTableIndex)
        {
            RootNode = new CollisionGroupNode(null, string.Format("R{0}", roomTableIndex.ToString("D2")));
            m_Nodes.Add(RootNode);

            CollisionGroupNode CurrentCategory = null;
            CollisionGroupNode CurrentGroup    = null;

            List <Vector3> Vertices = new List <Vector3>();

            for (int i = 0; i < lines.Length; i++)
            {
                string[] SplitLine = lines[i].Split(' ');

                switch (SplitLine[0])
                {
                case "o":
                    CurrentCategory = new CollisionGroupNode(RootNode, $"C_{ SplitLine[1] }");
                    CurrentGroup    = new CollisionGroupNode(CurrentCategory, $"G_{ SplitLine[1] }");

                    RootNode.Children.Add(CurrentCategory);
                    CurrentCategory.Children.Add(CurrentGroup);

                    m_Nodes.Add(CurrentCategory);
                    m_Nodes.Add(CurrentGroup);
                    break;

                case "v":
                    // We've been burned by Europe before since they use , instead of . for marking decimal places. So this just makes sure that's not an issue.
                    float XCoord = Convert.ToSingle(SplitLine[1].Replace(',', '.'));
                    float YCoord = Convert.ToSingle(SplitLine[2].Replace(',', '.'));
                    float ZCoord = Convert.ToSingle(SplitLine[3].Replace(',', '.'));

                    Vertices.Add(new Vector3(XCoord, YCoord, ZCoord));
                    break;

                case "f":
                    int V1 = Convert.ToInt32(SplitLine[1].Split('/')[0]) - 1;
                    int V2 = Convert.ToInt32(SplitLine[2].Split('/')[0]) - 1;
                    int V3 = Convert.ToInt32(SplitLine[3].Split('/')[0]) - 1;

                    CollisionTriangle NewTri = new CollisionTriangle(Vertices[V1], Vertices[V2], Vertices[V3], CurrentGroup);

                    Triangles.Add(NewTri);
                    CurrentGroup.Triangles.Add(NewTri);
                    break;

                default:
                    break;
                }
            }

            FinalizeLoad();

            // Automatically set the room number.
            RootNode.RoomNumber = roomIndex;

            // Copy the room table index used by the original collision mesh's root node to all of the groups loaded from the dae.
            // This isn't perfect because some rooms (like dungeon hub rooms) have different collision groups using different room tables, and this method doesn't preserve that.
            // But this does work much better than not setting the room table index at all.
            foreach (CollisionGroupNode node in m_Nodes)
            {
                node.RoomTableIndex = roomTableIndex;
            }
        }