예제 #1
0
        public static bool LoadStaticMesh(string path, string fileName)
        {
            StaticMesh mesh = new StaticMesh();

            if (mesh.LoadMesh(path, fileName) == false)
            {
                return(false);
            }

            // 키생성
            string key = string.Empty;

            for (int i = 0; i < fileName.Length; i++)
            {
                if (fileName[i] == '.')
                {
                    break;
                }

                key += fileName[i];
            }

            instance.staticMeshMap.Add(key, mesh);
            return(true);
        }
예제 #2
0
 public StaticMesh(StaticMesh rhs) : base(rhs)
 {
     this.originMesh  = rhs.originMesh;
     this.mesh        = rhs.mesh;
     this.adjacency   = rhs.adjacency;
     this.materials   = rhs.materials;
     this.textures    = rhs.textures;
     this.subsetCount = rhs.subsetCount;
     this.vertices    = rhs.vertices;
     this.indices     = rhs.indices;
     this.vertexSize  = rhs.vertexSize;
     this.vertexCount = rhs.vertexCount;
     this.faceCount   = rhs.faceCount;
 }
예제 #3
0
        private void buttonMesh_Click(object sender, EventArgs e)
        {
            if (treeViewMesh.SelectedNode.Name == "nodeMesh")
            {
                return;
            }
            if (treeViewMesh.SelectedNode.Name == "nodeStaticMesh")
            {
                return;
            }
            if (treeViewMesh.SelectedNode.Name == "nodeDynamicMesh")
            {
                return;
            }

            string key = treeViewMesh.SelectedNode.Text;

            StaticMesh mesh = ResourceManager.CloneStaticMesh(key);

            if (mesh == null)
            {
                return;
            }

            GameObject obj = ObjectManager.CreateObject("");

            obj.AddComponent("Mesh", mesh);
            obj.AddComponent <MeshCollider>("MeshCollider");


            SphereCollider sphere = new SphereCollider();

            if (sphere != null)
            {
                sphere.gameObject = obj;
                sphere.transform  = obj.transform;
                obj.AddComponent("SphereCollider", sphere);
            }


            treeViewObject.Nodes[0].Nodes.Add(obj.name);
            treeViewObject.ExpandAll();
        }
예제 #4
0
        public override bool Raycast(Ray ray, out RaycastHit outHitInfo, float maxDistance)
        {
            RaycastHit info;

            info.distance = 0;
            info.collider = null;
            info.point    = new Vector3(0, 0, 0);
            outHitInfo    = info;

            CustomMesh sharedMesh = null;
            StaticMesh smesh      = (StaticMesh)gameObject.GetComponent <StaticMesh>();

            if (smesh != null)
            {
                sharedMesh = smesh;
            }
            if (sharedMesh == null)
            {
                return(false);
            }

            Vector3[] vertexPositions = null;
            int[]     indices         = null;
            // 버텍스 버퍼 가져오기
            // 인덱스 버퍼 가져오기
            vertexPositions = sharedMesh.GetVertices();
            if (vertexPositions == null)
            {
                return(false);
            }
            int vertexCount = sharedMesh.GetVertexCount();

            indices = sharedMesh.GetIndices();
            if (indices == null)
            {
                return(false);
            }
            int triangleCount = sharedMesh.GetFaceCount();
            //

            // TODO : (약함)로컬에서 충돌검사를 해야 빠르겠지...?
            Matrix matWorld = transform.world;

            int     index, ind;
            Vector3 v1;
            Vector3 v2;
            Vector3 v3;
            bool    result  = false;
            float   minDist = float.MaxValue;

            for (int i = 0; i < triangleCount; i++)
            {
                index = i * 3;
                v1    = vertexPositions[indices[index]];
                v2    = vertexPositions[indices[index + 1]];
                v3    = vertexPositions[indices[index + 2]];

                v1 = Vector3.TransformCoordinate(v1, matWorld);
                v2 = Vector3.TransformCoordinate(v2, matWorld);
                v3 = Vector3.TransformCoordinate(v3, matWorld);

                IntersectInformation intersectInfo;
                if (Geometry.IntersectTri(v1, v2, v3, ray.origin, ray.direction, out intersectInfo))
                {
                    result = true;
                    if (intersectInfo.Dist < minDist)
                    {
                        minDist       = intersectInfo.Dist;
                        info.distance = intersectInfo.Dist;
                        info.collider = this;
                        info.point    = v1 + intersectInfo.U * (v2 - v1) + intersectInfo.V * (v3 - v1);
                        outHitInfo    = info;
                    }
                }
            }


            return(result);
        }