示例#1
0
    void LoadTriangleLists()
    {
        int len = _faces.Length;

        triangleLists = new int[len][];
        for (int i = 0; i < len; i++)
        {
            BSPFileParser.Face f = _faces[i];
            triangleLists[i] = new int[f.n_meshverts];
            for (int j = f.meshvert; j < f.meshvert + f.n_meshverts; j++)
            {
                triangleLists[i][j - f.meshvert] = f.vertex + _meshverts[j];
            }
        }
    }
示例#2
0
    ArrayList backfaceCulling(Camera cam, ArrayList visibleFaces)
    {
        ArrayList visible = new ArrayList();

        foreach (int i in visibleFaces)
        {
            BSPFileParser.Face f      = _faces[i];
            Vector3            normal = Right2Left(new Vector3(f.normal[0], f.normal[1], f.normal[2]));
            if (Vector3.Dot(cam.transform.forward, normal) < BACKCULLINGFACTOR)
            {
                visible.Add(i);
            }
        }
        return(visible);
    }
示例#3
0
    // Load all of meshes to construct game objects
    // and as children be add to gmObject
    void LoadAllMeshAndObject(GameObject gmObject, BSPFileParser.Model m, string childName)
    {
        gmObject.transform.DetachChildren();

        meshes  = new UnityEngine.Mesh[m.face + m.n_faces];
        objects = new UnityEngine.GameObject[m.face + m.n_faces];
        for (int faceIndex = m.face; faceIndex < m.face + m.n_faces; faceIndex++)
        {
            BSPFileParser.Face f = _faces [faceIndex];

            // Construct Mesh
            UnityEngine.Mesh mesh = new UnityEngine.Mesh();
            mesh.vertices = vertices;
            mesh.normals  = normals;
            mesh.uv       = uvs;
            mesh.uv2      = uv2s;
            mesh.colors   = colors;
            int[] triangles = new int[f.n_meshverts];
            for (int j = f.meshvert; j < f.meshvert + f.n_meshverts; j++)
            {
                triangles[j - f.meshvert] = f.vertex + _meshverts[j];
            }
            mesh.triangles = triangles;

            // Construct GameObject
            GameObject childObject = new GameObject(childName);
            childObject.AddComponent <MeshFilter>().mesh       = mesh;
            childObject.AddComponent <MeshRenderer>().material = _materials[f.texture];

            if (colliderType == ModelColliderType.MeshCollider)
            {
                childObject.AddComponent <MeshCollider>().sharedMesh = mesh;
            }

            childObject.transform.SetParent(gmObject.transform);

            meshes[faceIndex]  = mesh;
            objects[faceIndex] = childObject;
        }

        if (colliderType == ModelColliderType.BoxCollider)
        {
            LoadCollider(gmObject);
        }
    }
示例#4
0
    // Load all of meshes to construct game objects
    // and as children be add to gmObject
    void LoadAllMeshAndObject(GameObject gmObject, string childName)
    {
        gmObject.transform.DetachChildren();

        int len = _leafs.Length;

        meshes  = new UnityEngine.Mesh[len];
        objects = new UnityEngine.GameObject[len];
        for (int leafIndex = 0; leafIndex < len; leafIndex++)
        {
            BSPFileParser.BSPTreeLeaf lf = _leafs[leafIndex];

            // Construct Mesh
            UnityEngine.Mesh mesh = new UnityEngine.Mesh();
            mesh.vertices = vertices;
            mesh.normals  = normals;
            mesh.uv       = uvs;
            mesh.uv2      = uv2s;
            mesh.colors   = colors;

            materials         = new UnityEngine.Material[lf.n_leaffaces];
            mesh.subMeshCount = lf.n_leaffaces;
            for (int leafFaceIndex = lf.leafface; leafFaceIndex < lf.leafface + lf.n_leaffaces; leafFaceIndex++)
            {
                int faceIndex        = _leaffaces[leafFaceIndex];
                BSPFileParser.Face f = _faces[faceIndex];
                materials[leafFaceIndex - lf.leafface] = allmaterials[f.texture];
                mesh.SetTriangles(triangleLists[faceIndex], leafFaceIndex - lf.leafface);
            }

            // Construct GameObject
            GameObject childObject = new GameObject(childName);
            childObject.AddComponent <MeshFilter>().mesh         = mesh;
            childObject.AddComponent <MeshRenderer>().materials  = materials;
            childObject.AddComponent <MeshCollider>().sharedMesh = mesh;
            childObject.transform.SetParent(gmObject.transform);

            // Cache GameObject and Mesh
            meshes[leafIndex]  = mesh;
            objects[leafIndex] = childObject;
        }
    }
示例#5
0
    void LoadTriangles(ArrayList faceIndices)
    {
        mesh.subMeshCount = faceIndices.Count;
        materials         = new UnityEngine.Material[faceIndices.Count];
        for (int i = 0; i < faceIndices.Count; i++)
        {
            BSPFileParser.Face f = _faces[(int)faceIndices[i]];
            materials[i] = allmaterials[f.texture];

            int[] triangles = new int[f.n_meshverts];
            for (int j = f.meshvert; j < f.meshvert + f.n_meshverts; j++)
            {
                triangles[j - f.meshvert] = f.vertex + _meshverts[j];
            }

            mesh.SetTriangles(triangles, i);
        }
        //Debug.Log(count);
        GetComponent <MeshFilter> ().mesh        = mesh;
        GetComponent <MeshRenderer> ().materials = materials;
        GetComponent <MeshCollider>().sharedMesh = mesh;
    }