コード例 #1
0
    static void UseTXMP(Oni.InstanceDescriptor ides)
    {
        Texture2D l_tex = null;

        if ((l_tex = ObtainTXFrom(ides)) != null)
        {
            Texture2DQuery.Loaded(ides.Index, l_tex);
            Debug.Log(ides.Decode <Round2.TXMP>());
            //DeserializeAs<Round2.TXMP>(ides.AsXmlStream());
        }

        //Debug.Log(ides.Name);
    }
コード例 #2
0
        internal void TMP_InstallNewCharacter(Oni.InstanceFile level0)
        {
            List <Mesh>       l_meshes = new List <Mesh>();
            List <GameObject> l_parts  = new List <GameObject>();

            foreach (Links.M3GMLNK geomery in this.BodySet.TRBS.Elements[4].TRCM.Geometry.TRGA.Geometries)
            {
                l_meshes.Add(geomery.M3GM.UnityMesh);
            }

            for (int i = 0; i < this.BodySet.TRBS.Elements[4].TRCM.BodyPartCount; i++)
            {
                GameObject l_newest;
                l_parts.Add(l_newest = GameObject.CreatePrimitive(PrimitiveType.Cube));
                l_newest.name        = ((__ONCC.Bodyparts)i).ToString();
                l_newest.GetComponent <MeshFilter>().mesh = l_meshes[i];
                GameObject.Destroy(l_newest.collider);
                l_newest.renderer.material.shader = Shader.Find("TwoSidedDiffuse");
            }

            for (int i = 0; i < this.BodySet.TRBS.Elements[4].TRCM.BodyPartCount; i++)
            {
                l_parts[i].transform.parent = l_parts[this.BodySet.TRBS.Elements[4].TRCM.Hierarchy.TRIA.Elements[i].Parent].transform;
                Vector3 lpos = this.BodySet.TRBS.Elements[4].TRCM.Position.TRTA.Translations[i];
                l_parts[i].transform.localPosition = new UnityEngine.Vector3(-lpos.Value.x, lpos.Value.y, lpos.Value.z);
                Material l_m = l_parts[i].renderer.material;
                Texture2DQuery.TexturePend(this.BodyTextures.TRMA.Textures[i].TXMP.id, u => l_m.mainTexture = u);
            }

            //l_parts[0].transform.parent = new GameObject("chr").transform;
            Animation l_a = l_parts[0].gameObject.AddComponent <Animation>();

            l_parts[0].AddComponent <GUIANIMCONTROL>();
            CharacterController l_cc = l_parts[0].AddComponent <CharacterController>();

            Camera.allCameras[0].transform.parent =
                l_parts[0].transform;
        }
コード例 #3
0
    void MakeFromM3GM(M3GM data)
    {
        int[] indiсes = data.TriangleStrips.IDXA.DecodeForM3GM_1();

        if (!this.flags.Contains("FaceCollision"))
        {
            List <int> indcs  = new List <int>();
            List <int> _3inds = new List <int>();

            foreach (int _m in indiсes)
            {
                _3inds.Add(_m);

                if (_3inds.Count > 2)
                {
                    _3inds.Reverse();
                    indcs.AddRange(_3inds);
                    _3inds.Clear();
                }
            }

            indiсes = indcs.ToArray();
        }

        UnityEngine.Vector3[] planeNormals = new List <Round2.Vector3>(data.Points.PNTA.Positions).ConvertAll <UnityEngine.Vector3>(u => u.Value).ToArray();
        UnityEngine.Vector3[] pts          = new List <Round2.Vector3>(data.Points.PNTA.Positions).ConvertAll <UnityEngine.Vector3>(u => new UnityEngine.Vector3(-u.Value.x, u.Value.y, u.Value.z)).ToArray();
        UnityEngine.Vector2[] uvs          = new List <Round2.Vector2>(data.TextureCoordinates.TXCA.TexCoords).ConvertAll <UnityEngine.Vector2>(u => u.Value).ToArray();
        UnityEngine.Vector3[] normals      = new List <Round2.Vector3>(data.VertexNormals.VCRA.Normals).ConvertAll <UnityEngine.Vector3>(u => u.Value).ToArray();
        GameObject            l_ch         = GameObject.CreatePrimitive(PrimitiveType.Plane);

        l_ch.AddComponent <Animation>();
        Destroy(l_ch.collider);

        Texture2DQuery.TexturePend(m_obj.Geometry.M3GA.Geometries[0].M3GM.Texture.TXMP.id, tex =>
        {
            l_ch.renderer.material.mainTexture = m_tex = tex;
        });

        l_ch.transform.parent        = transform;
        l_ch.transform.localPosition = UnityEngine.Vector3.zero;
        l_ch.transform.localRotation = UnityEngine.Quaternion.identity;
        l_ch.transform.localScale    = UnityEngine.Vector3.one;
        Mesh m = new Mesh();

        m.vertices  = pts;
        m.uv        = uvs;
        m.normals   = normals;
        m.triangles = indiсes;
        m.RecalculateBounds();
        m.RecalculateNormals();
        l_ch.GetComponent <MeshFilter>().mesh   = m;
        l_ch.AddComponent <MeshCollider>().mesh = m;

        {
            float[] l_trs = new List <string>(m_obj.Transform.Split(" ".ToCharArray())).ConvertAll(u => float.Parse(u)).ToArray();

            Oni.Matrix l_trsm = new Oni.Matrix
                                (
                l_trs[0],
                l_trs[1],
                l_trs[2],
                0,
                l_trs[3],
                l_trs[4],
                l_trs[5],
                0,
                l_trs[6],
                l_trs[7],
                l_trs[8],
                0,
                l_trs[9],
                l_trs[10],
                l_trs[11],
                1
                                );

            Oni.Vector3    scale;
            Oni.Vector3    trans;
            Oni.Quaternion rot;
            //l_trsm.Transpose();
            l_trsm.Decompose(out scale, out rot, out trans);
            transform.localScale = new UnityEngine.Vector3(scale.X, scale.Y, scale.Z);
            transform.position   = new UnityEngine.Vector3(-trans.X, trans.Y, trans.Z);
            UnityEngine.Vector3 l_eulerz = new UnityEngine.Quaternion(rot.X, rot.Y, rot.Z, rot.W).eulerAngles;
            transform.rotation = UnityEngine.Quaternion.Euler(l_eulerz.x, -l_eulerz.y, -l_eulerz.z);
        }
        if (m_obj.Animation.OBAN != null && m_obj.Animation.OBAN.KeyFrames != null)
        {
            float[] l_trs  = new List <string>(m_obj.Animation.OBAN.InitialTransform.Split(" ".ToCharArray())).ConvertAll(u => float.Parse(u)).ToArray();
            float[] l_trss = new List <string>(m_obj.Animation.OBAN.BaseTransform.Split(" ".ToCharArray())).ConvertAll(u => float.Parse(u)).ToArray();

            Oni.Matrix l_trsm = new Oni.Matrix
                                (
                l_trs[0],
                l_trs[1],
                l_trs[2],
                0,
                l_trs[3],
                l_trs[4],
                l_trs[5],
                0,
                l_trs[6],
                l_trs[7],
                l_trs[8],
                0,
                l_trs[9],
                l_trs[10],
                l_trs[11],
                1
                                );

            Oni.Matrix l_trsms = new Oni.Matrix
                                 (
                l_trss[0],
                l_trss[1],
                l_trss[2],
                0,
                l_trss[3],
                l_trss[4],
                l_trss[5],
                0,
                l_trss[6],
                l_trss[7],
                l_trss[8],
                0,
                l_trss[9],
                l_trss[10],
                l_trss[11],
                1
                                 );

            Oni.Vector3    scale;
            Oni.Vector3    trans;
            Oni.Quaternion rot;
            //l_trsm.Transpose();
            l_trsm.Decompose(out scale, out rot, out trans);
            transform.localScale = new UnityEngine.Vector3(scale.X, scale.Y, scale.Z);
            transform.position   = new UnityEngine.Vector3(-trans.X, trans.Y, trans.Z);
            UnityEngine.Vector3 l_eulz = new UnityEngine.Quaternion(rot.X, rot.Y, rot.Z, rot.W).eulerAngles;
            transform.rotation = __q = UnityEngine.Quaternion.Euler(l_eulz.x, -l_eulz.y, -l_eulz.z);
        }
    }
コード例 #4
0
        public void InitEnv()
        {
            for (int index = 0; index < Environment.AKEV.Quads.AGQG.Quads.Length; index++)
            {
                int           txi    = this.Environment.AKEV.QuadTextures.AGQR.Elements[index].Texture.Value;
                Links.TXMPLNK l_lnk  = this.Environment.AKEV.Textures.TXMA.Textures[txi];
                AGQGQuad      l_quad = Environment.AKEV.Quads.AGQG.Quads[index];

                if ((l_quad.Flags & GunkFlags.Ghost) != 0 || (l_quad.Flags & GunkFlags.StairsUp) != 0 || (l_quad.Flags & GunkFlags.StairsDown) != 0 || (l_quad.Flags & GunkFlags.DoorFrame) != 0 || (l_quad.Flags & GunkFlags.Furniture) != 0)
                {
                    continue;
                }

                string l_hash = new object[]
                {
                    l_quad.Flags,
                    l_quad.ObjectId,
                    (l_lnk != null && l_lnk.TXMP != null ? l_lnk.TXMP.id : -1)
                }.ArrayAsSml();

                EmitVertex
                (
                    l_hash,
                    this.Environment.AKEV.Points.PNTA.Positions[l_quad.Points[2].Value],
                    this.Environment.AKEV.TextureCoordinates.TXCA.TexCoords[l_quad.TextureCoordinates[2].Value],
                    l_quad.Points[2]
                );

                EmitVertex
                (
                    l_hash,
                    this.Environment.AKEV.Points.PNTA.Positions[l_quad.Points[1].Value],
                    this.Environment.AKEV.TextureCoordinates.TXCA.TexCoords[l_quad.TextureCoordinates[1].Value],
                    l_quad.Points[1]
                );

                EmitVertex
                (
                    l_hash,
                    this.Environment.AKEV.Points.PNTA.Positions[l_quad.Points[0].Value],
                    this.Environment.AKEV.TextureCoordinates.TXCA.TexCoords[l_quad.TextureCoordinates[0].Value],
                    l_quad.Points[0]
                );

                EmitVertex
                (
                    l_hash,
                    this.Environment.AKEV.Points.PNTA.Positions[l_quad.Points[3].Value],
                    this.Environment.AKEV.TextureCoordinates.TXCA.TexCoords[l_quad.TextureCoordinates[3].Value],
                    l_quad.Points[3]
                );

                EmitVertex
                (
                    l_hash,
                    this.Environment.AKEV.Points.PNTA.Positions[l_quad.Points[2].Value],
                    this.Environment.AKEV.TextureCoordinates.TXCA.TexCoords[l_quad.TextureCoordinates[2].Value],
                    l_quad.Points[2]
                );

                EmitVertex
                (
                    l_hash,
                    this.Environment.AKEV.Points.PNTA.Positions[l_quad.Points[0].Value],
                    this.Environment.AKEV.TextureCoordinates.TXCA.TexCoords[l_quad.TextureCoordinates[0].Value],
                    l_quad.Points[0]
                );
            }

            int l_counter = 0;

            foreach (string l_objname in m_objectsTrs.Keys)
            {
                GameObject g     = new GameObject(l_objname);
                MeshFilter mf    = g.AddComponent <MeshFilter>();
                object[]   l_arr = l_objname.SmlToArray();
                l_counter = l_arr == null || l_arr[2] == null ? -1 : (int)l_arr[2];
                Material l_objmat = g.AddComponent <MeshRenderer>().material = new Material(Shader.Find("VertexShadedDiffuse"));

                if (l_counter >= 0)
                {
                    Texture2DQuery.TexturePend(l_counter, tex => l_objmat.mainTexture = tex);
                }

                Mesh m = new Mesh();
                List <UnityEngine.Vector3> vrts = new List <UnityEngine.Vector3>();
                List <UnityEngine.Vector2> uvs  = new List <UnityEngine.Vector2>();
                List <int> idx = new List <int>();

                foreach (VRTX l_vrtx in m_objectsTrs[l_objname])
                {
                    vrts.Add(l_vrtx.pos);
                    idx.Add(l_vrtx.realIDX);
                    uvs.Add(l_vrtx.uv);
                }

                m.vertices  = vrts.ToArray();
                m.triangles = idx.ToArray();
                m.uv        = uvs.ToArray();
                m.RecalculateBounds();
                m.RecalculateNormals();
                mf.mesh = m;
                g.AddComponent <MeshCollider>().mesh = m;
            }
        }