Пример #1
0
 public void ResetMorph(GameObject gao)
 {
     // First, reset vertex buffer
     if (Settings.s.platform == Settings.Platform.N64)
     {
         foreach (GeometricObjectElementVisualList.GeometricElementListEntry entry in elementsVisual.Value.elements)
         {
             if (entry.element.Value is GeometricObjectElementTriangles)
             {
                 GeometricObjectElementTriangles el = entry.element.Value as GeometricObjectElementTriangles;
                 el.ResetVertexBuffer();
             }
         }
     }
     for (int i = 0; i < num_elementsVisual; i++)
     {
         ROMStruct entry1 = elementsVisual.Value.elements[i].element.Value;
         if (entry1 != null && entry1 is GeometricObjectElementTriangles)
         {
             GeometricObjectElementTriangles tris1 = entry1 as GeometricObjectElementTriangles;
             MeshFilter[] mfs = gao.GetComponentsInChildren <MeshFilter>();
             MeshFilter   mf  = mfs.FirstOrDefault(m => m.name == "ElementTriangles @ " + tris1.Offset);
             if (mf != null)
             {
                 tris1.ResetMorph(mf.sharedMesh, this);
                 //mf.mesh.RecalculateNormals();
             }
         }
     }
 }
Пример #2
0
        public GameObject GetGameObject(Type type, CollideType collideType = CollideType.None)
        {
            GameObject gao = new GameObject("GeometricObject @ " + Offset);

            if (type == Type.Visual)
            {
                gao.layer = LayerMask.NameToLayer("Visual");
            }
            else
            {
                gao.layer = LayerMask.NameToLayer("Collide");
            }
            gao.name = gao.name + " - S0:" + scaleFactor
                       + " - S1:" + factor_1
                       + " - U0:" + string.Format("{0:X4}", unk0)
                       + " - U1:" + string.Format("{0:X4}", unk1)
                       + " - U2:" + string.Format("{0:X4}", hasVertexColors)
                       + " - U3:" + string.Format("{0:X4}", lookAtMode);
            MapLoader l = MapLoader.Loader;

            if (type == Type.Visual)
            {
                if (elementsVisual.Value != null)
                {
                    // First, reset vertex buffer
                    if (Settings.s.platform == Settings.Platform.N64)
                    {
                        foreach (GeometricObjectElementVisualList.GeometricElementListEntry entry in elementsVisual.Value.elements)
                        {
                            if (entry.element.Value is GeometricObjectElementTriangles)
                            {
                                GeometricObjectElementTriangles el = entry.element.Value as GeometricObjectElementTriangles;
                                el.ResetVertexBuffer();
                            }
                        }
                    }
                    //gao.transform.position = new Vector3(UnityEngine.Random.Range(-100f, 100f), UnityEngine.Random.Range(-100f, 100f), UnityEngine.Random.Range(-100f, 100f));
                    foreach (GeometricObjectElementVisualList.GeometricElementListEntry entry in elementsVisual.Value.elements)
                    {
                        /*if (entry.element.Value == null) {
                         *      l.print("Visual element null: " + entry.element.type);
                         * }*/
                        if (entry.element.Value != null)
                        {
                            GameObject child = null;
                            if (entry.element.Value is GeometricObjectElementTriangles)
                            {
                                GeometricObjectElementTriangles el = entry.element.Value as GeometricObjectElementTriangles;
                                child = el.GetGameObject(type, this);
                            }
                            else if (entry.element.Value is GeometricObjectElementSprites)
                            {
                                GeometricObjectElementSprites el = entry.element.Value as GeometricObjectElementSprites;
                                child = el.GetGameObject(type, this);
                            }
                            if (child != null)
                            {
                                child.transform.SetParent(gao.transform);
                                child.transform.localPosition = Vector3.zero;
                            }
                        }
                    }
                }
                if (lookAtMode != 0)
                {
                    BillboardBehaviour billboard = gao.AddComponent <BillboardBehaviour>();
                    billboard.mode = (BillboardBehaviour.LookAtMode)lookAtMode;
                }
            }
            else
            {
                if (elementsCollide.Value != null)
                {
                    foreach (GeometricObjectElementCollideList.GeometricElementListEntry entry in elementsCollide.Value.elements)
                    {
                        if (entry.element.Value == null)
                        {
                            l.print("Collide element null: " + entry.element.type);
                        }
                        if (entry.element.Value != null)
                        {
                            GameObject child = null;
                            if (entry.element.Value is GeometricObjectElementCollideTriangles)
                            {
                                GeometricObjectElementCollideTriangles el = entry.element.Value as GeometricObjectElementCollideTriangles;
                                child = el.GetGameObject(type, this, collideType: collideType);
                            }
                            else if (entry.element.Value is GeometricObjectElementCollideSpheres)
                            {
                                GeometricObjectElementCollideSpheres el = entry.element.Value as GeometricObjectElementCollideSpheres;
                                child = el.GetGameObject(type, this, collideType: collideType);
                            }
                            else if (entry.element.Value is GeometricObjectElementCollideAlignedBoxes)
                            {
                                GeometricObjectElementCollideAlignedBoxes el = entry.element.Value as GeometricObjectElementCollideAlignedBoxes;
                                child = el.GetGameObject(type, this, collideType: collideType);
                            }
                            if (child != null)
                            {
                                child.transform.SetParent(gao.transform);
                                child.transform.localPosition = Vector3.zero;
                            }
                        }
                    }
                }
            }
            return(gao);
        }
        public void MorphVertices(Mesh mesh, GeometricObjectElementTriangles tris2, GeometricObject go1, GeometricObject go2, float lerp)
        {
            CompressedVector3Array v1, v2;

            if (Settings.s.platform == Settings.Platform._3DS)
            {
                v1 = go1.verticesVisual.Value;
                v2 = go2.verticesVisual.Value;
            }
            GeometricObjectElementTriangles tris1 = this;

            if (Settings.s.platform == Settings.Platform.N64)
            {
                if (tris1.sz_vertices != tris2.sz_vertices)
                {
                    return;
                }
                Vector3[] verts1 = RSP.RSPParser.ParseVerticesOnly(tris1.triangles.Value.rspCommands, tris1.vertices.Value.vertices, go1);
                Vector3[] verts2 = RSP.RSPParser.ParseVerticesOnly(tris2.triangles.Value.rspCommands, tris2.vertices.Value.vertices, go2);
                for (int i = 0; i < verts1.Length; i++)
                {
                    verts1[i] = Vector3.Lerp(verts1[i], verts2[i], lerp);
                }
                mesh.vertices = verts1;
            }
            else if (Settings.s.platform == Settings.Platform._3DS)
            {
                Vector3[] verts1, verts2;
                if (tris1.sz_vertices == 0)
                {
                    verts1 = go1.verticesVisual.Value.GetVectors(go1.ScaleFactor);
                }
                else
                {
                    // Use vertices located in element
                    verts1 = tris1.triangles.Value.verts.Select(v => v.GetVector(go1.ScaleFactor)).ToArray();
                }
                if (tris2.sz_vertices == 0)
                {
                    verts2 = go2.verticesVisual.Value.GetVectors(go2.ScaleFactor);
                }
                else
                {
                    // Use vertices located in element
                    verts2 = tris2.triangles.Value.verts.Select(v => v.GetVector(go2.ScaleFactor)).ToArray();
                }
                if (verts1.Length != verts2.Length)
                {
                    return;
                }
                for (int i = 0; i < verts1.Length; i++)
                {
                    verts1[i] = Vector3.Lerp(verts1[i], verts2[i], lerp);
                }
                mesh.vertices = verts1;
            }
            else if (Settings.s.platform == Settings.Platform.DS)
            {
                Vector3[] verts1 = DS3D.GeometryParser.ParseVerticesOnly(tris1.triangles.Value.ds3dCommands, go1);
                Vector3[] verts2 = DS3D.GeometryParser.ParseVerticesOnly(tris2.triangles.Value.ds3dCommands, go2);
                for (int i = 0; i < verts1.Length; i++)
                {
                    verts1[i] = Vector3.Lerp(verts1[i], verts2[i], lerp);
                }
                mesh.vertices = verts1;
            }
        }