コード例 #1
0
ファイル: RoomEx.cs プロジェクト: suruz/TR2-Level-Viewer
 void Start()
 {
     m_Mesh            = GetComponent <MeshFilter>().mesh;
     m_RoomVertices    = m_Mesh.vertices;
     m_SharedTriangles = MeshModifier.GetSharedTriangles(m_Mesh);
     m_RoomAnalyzer    = new SurfaceAnalyzer(m_Mesh);
     m_RoomEdges       = m_RoomAnalyzer.Analyze(m_RoomVertices, m_SharedTriangles, null);
     m_Material        = GetComponent <MeshRenderer>().sharedMaterial;
 }
コード例 #2
0
ファイル: RoomEx.cs プロジェクト: Gh0stBlade/TR2-Level-Viewer
 void Start()
 {
     m_RoomVertices = m_Mesh.vertices;
     m_SharedTriangles = MeshModifier.GetSharedTriangles(m_Mesh);
     m_RoomAnalyzer = new SurfaceAnalyzer(m_Mesh);
     m_RoomEdges = m_RoomAnalyzer.Analyze(m_RoomVertices, m_SharedTriangles,null);
 }
コード例 #3
0
ファイル: RoomEx.cs プロジェクト: suruz/TR2-Level-Viewer
    public List <Edge> RayCast(Vector3 origin, Vector3 dir, float raylength = 200)
    {
        //first select a face from face network
        //then find a edge that is normal to ground.

        //if  normal going upward and found next edge diagonal - > go to mirror face
        //if normal going upward found next edge horizontal - > next edge lader step
        //                                                  -> if lader step found chek it is topmost go to mirror face
        //else

        //if normal going downward and found next edge horizontal - > go to mirror face
        //f normal going downward and found next edge diagonal - > third edge is lader step
        //                                                   -> if lader step found chek it is topmost go to mirror face

        Vector3 hitpoint = Vector3.zero;
        int     faceid   = Physic3D.RayCast(m_Transform, m_RoomVertices, m_SharedTriangles, origin, dir, raylength, ref hitpoint);

        //find all edeges connected to faceid
        List <Edge> edges = new List <Edge>();

        if (faceid != -1)
        {
            //Debug.Log("Room.RayCast:" + faceid);
            Triangle face      = m_RoomAnalyzer.LodTriangles[faceid];
            int      ntrycount = 0;

            Edge TempEdge     = null;
            Edge platformEdge = null;
            while (platformEdge == null)
            {
                for (int k = 0; k < face.vertex.Length; k++)
                {
                    int     nextid = (k + 1) % face.vertex.Length;
                    Vector3 upvec  = (face.vertex[nextid].position - face.vertex[k].position).normalized;
                    float   dot    = Vector3.Dot(Vector3.up, upvec);

                    if (dot == 1.0f)                    //goin upward
                    {
                        //check if next edge is diagonal
                        int     diagonalvtx0   = nextid;
                        int     diagonalvtx1   = (nextid + 1) % face.vertex.Length;
                        Vector3 diagvec        = (face.vertex[diagonalvtx1].position - face.vertex[diagonalvtx0].position).normalized;
                        bool    isdiag         = (Vector3.Dot(upvec, diagvec) != 0);
                        bool    gotomirrorface = false;

                        if (!isdiag)                        //found ladder step
                        {
                            Edge e = new Edge(face.vertex[diagonalvtx0].position, face.vertex[diagonalvtx1].position);
                            e.AtoB   = diagvec;
                            TempEdge = e;

                            //check if this is top most step
                            if (SurfaceAnalyzer.ComputeEdgeCollapseCost(face.vertex[diagonalvtx0], face.vertex[diagonalvtx1]) < 1)
                            {
                                platformEdge = e;
                                break;
                            }
                            else
                            {
                                gotomirrorface = true;
                            }
                        }
                        else
                        {
                            gotomirrorface = true;
                        }

                        if (gotomirrorface)
                        {
                            List <Triangle> faces = face.vertex[diagonalvtx0].face;
                            for (int i = 0; i < faces.Count; i++)
                            {
                                if (faces[i].HasVertex(face.vertex[diagonalvtx1]) && !faces[i].HasVertex(face.vertex[k]))
                                {
                                    face = faces[i];
                                    break;
                                }
                            }
                        }
                    }
                    else if (dot == -1.0f)
                    {
                        //check if next edge is diagonal
                        int     diagonalvtx0   = nextid;
                        int     diagonalvtx1   = (nextid + 1) % face.vertex.Length;
                        Vector3 diagvec        = (face.vertex[diagonalvtx1].position - face.vertex[diagonalvtx0].position).normalized;
                        bool    isdiag         = (Vector3.Dot(upvec, diagvec) != 0);
                        bool    gotomirrorface = false;

                        if (!isdiag)                        //found lowest ladder step
                        {
                            gotomirrorface = true;
                        }
                        else
                        {
                            Edge e = new Edge(face.vertex[diagonalvtx1].position, face.vertex[k].position);
                            e.AtoB   = (face.vertex[k].position - face.vertex[diagonalvtx1].position).normalized;
                            TempEdge = e;

                            //check if this is top most step
                            if (SurfaceAnalyzer.ComputeEdgeCollapseCost(face.vertex[diagonalvtx1], face.vertex[k]) < 1)
                            {
                                platformEdge = e;
                                break;
                            }
                            else
                            {
                                gotomirrorface = true;
                            }
                        }

                        if (gotomirrorface)
                        {
                            List <Triangle> faces = face.vertex[diagonalvtx1].face;
                            for (int i = 0; i < faces.Count; i++)
                            {
                                if (faces[i].HasVertex(face.vertex[k]) && !faces[i].HasVertex(face.vertex[diagonalvtx0]))
                                {
                                    face = faces[i];
                                    break;
                                }
                            }
                        }
                    }
                }

                ntrycount++;
                if (ntrycount > 20)
                {
                    if (TempEdge != null)
                    {
                        platformEdge = TempEdge;
                    }
                    break;
                }
            }

            if (platformEdge != null)
            {
                edges.Add(platformEdge);
            }
        }

        return(edges);
    }