Exemple #1
0
        public static bool Build(Wm3Mesh mesh, TextureManager textureManager, out GameObject gameObj)
        {
            bool success   = false;
            Mesh unityMesh = new Mesh();

            gameObj = null;
            if (Construct(unityMesh, mesh))
            {
                Material[] materials;
                bool       isOverlay = mesh.Flags.IsSet(Wm3Flags.Overlay);
                if (textureManager.BuildMeshMaterials(mesh.Textures, mesh.Ambient, isOverlay, out materials))
                {
                    gameObj      = SpawnMeshObject(unityMesh, materials);
                    gameObj.name = unityMesh.name;
                    gameObj.transform.position = mesh.Position;
                    gameObj.isStatic           = true;
                    success = true;

                    //TODO: move to static helper class
                    Renderer renderer = gameObj.GetComponent <Renderer>();
                    Collider collider = gameObj.GetComponent <Collider>();

                    if (mesh.Flags.IsSet(Wm3Flags.Invisible))
                    {
                        renderer.enabled = false;
                    }

                    if (mesh.Flags.IsSet(Wm3Flags.Passable))
                    {
                        collider.enabled = false;
                    }
                }
            }
            return(success);
        }
Exemple #2
0
        private static bool Construct(Mesh mesh, Wm3Mesh wm3Mesh)
        {
            if (wm3Mesh.Loaded)
            {
                mesh.subMeshCount = wm3Mesh.NumSubmeshes;
                mesh.vertices     = wm3Mesh.Vertices;
                mesh.normals      = wm3Mesh.Normals;
                mesh.uv           = wm3Mesh.Uv;
                mesh.name         = wm3Mesh.Name;
                for (int j = 0; j < wm3Mesh.NumSubmeshes; j++)
                {
                    mesh.SetTriangles(wm3Mesh.Triangles[j], j);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }