コード例 #1
0
        private void QuadGO(QuadBlock qb, GameObject gameObject, bool highDetail, Vector3 middlePosition)
        {
            List <Vector2> uvs      = new List <Vector2>();
            List <Vector3> vertices = new List <Vector3>();
            List <Color>   colors   = new List <Color>();
            List <Vertex>  vertList = qb.GetVertexList(this, highDetail);
            List <int>     indices  = new List <int>();

            for (int i = 0; i < vertList.Count; i++)
            {
                Vertex vertA = vertList[i];
                indices.Add(i);
                vertices.Add(new Vector3(vertA.coord.X / 255.0f, vertA.coord.Y / 255.0f, -vertA.coord.Z / 255.0f) - middlePosition);
                uvs.Add(vertA.uv);
                colors.Add(new Color(vertA.color.X / 255.0f, vertA.color.Y / 255.0f, vertA.color.Z / 255.0f));
            }

            //Add Components
            var filter       = gameObject.AddComponent <MeshFilter>();
            var meshRenderer = gameObject.AddComponent <MeshRenderer>();

            //meshRenderer.material = new Material(Shader.Find("Custom/Double-Sided"));
            meshRenderer.material = new Material(highDetail ? Shader.Find("PS1") : Shader.Find("PS1Low"));
            if (highDetail)
            {
                meshRenderer.material.SetTexture("_Tex0", midTextures[qb.tex[0].midlods[2].Tag()]);
                meshRenderer.material.SetTexture("_Tex1", midTextures[qb.tex[1].midlods[2].Tag()]);
                meshRenderer.material.SetTexture("_Tex2", midTextures[qb.tex[2].midlods[2].Tag()]);
                meshRenderer.material.SetTexture("_Tex3", midTextures[qb.tex[3].midlods[2].Tag()]);
                meshRenderer.material.SetInt("_flipRotate0", (int)qb.faceFlags[0].rotateFlipType);
                meshRenderer.material.SetInt("_flipRotate1", (int)qb.faceFlags[1].rotateFlipType);
                meshRenderer.material.SetInt("_flipRotate2", (int)qb.faceFlags[2].rotateFlipType);
                meshRenderer.material.SetInt("_flipRotate3", (int)qb.faceFlags[3].rotateFlipType);
            }
            else
            {
                var tag = qb.texlow.Tag();
                if (lowTextures.ContainsKey(tag))
                {
                    meshRenderer.material.SetTexture("_Tex", lowTextures[tag]);
                    meshRenderer.material.SetInt("_flipRotate", (int)qb.faceFlags[0].rotateFlipType);
                }
            }
            meshRenderer.material.SetInt("_invisibleTriggers", qb.quadFlags.HasFlag(QuadFlags.InvisibleTriggers)? 1 : 0);
            filter.mesh = new Mesh
            {
                vertices  = vertices.ToArray(),
                triangles = indices.ToArray(),
                colors    = colors.ToArray(),
                uv        = uvs.ToArray()
            };
            filter.mesh.RecalculateNormals();
            filter.mesh.RecalculateBounds();
        }
コード例 #2
0
ファイル: Scene.cs プロジェクト: ctr-branch/CTR-tools-1
        private int levelShiftDivide = 92;  // one step width

        /// <summary>
        /// Return QuadBlocks associated with the leaf, make sure you pass a leaf and not a branch.
        /// </summary>
        /// <param name="leaf"></param>
        public List <QuadBlock> GetListOfLeafQuadBlocks(VisData leaf)
        {
            List <QuadBlock> leafQuadBlocks = new List <QuadBlock>();
            uint             ptrQuadBlock   = (uint)(((leaf.ptrQuadBlock) / levelShiftDivide) + levelShiftOffset);
            uint             numQuadBlock   = leaf.numQuadBlock;

            for (int i = 0; i < numQuadBlock; i++)
            {
                long      index = ptrQuadBlock + i;
                QuadBlock quad  = quads[(int)Math.Min(Math.Max(index, 0), quads.Count - 1)];
                leafQuadBlocks.Add(quad);
            }

            return(leafQuadBlocks);
        }