コード例 #1
0
        public bool RayIntersects(Ray ray, SurfaceModelMesh model, out float distance)
        {
            distance = float.NaN;
            var vertices = Vertices;
            var indices  = Indices;
            var localRay = Ray.Transform(ray, model.Transform.Inverted());

            for (int i = 0; i < model.IndexCount; i += 3)
            {
                var idx1 = indices[i + model.StartIndex];
                var idx2 = indices[i + 1 + model.StartIndex];
                var idx3 = indices[i + 2 + model.StartIndex];

                var v1 = vertices[idx1 + model.StartVertex];
                var v2 = vertices[idx2 + model.StartVertex];
                var v3 = vertices[idx3 + model.StartVertex];

                if (Ray.IntersectsTriangle(localRay, v1.Position, v2.Position, v3.Position, out float hitDist))
                {
                    distance = float.IsNaN(distance) ? hitDist : Math.Min(hitDist, distance);
                }
            }

            return(!float.IsNaN(distance));
        }
コード例 #2
0
 private void DrawSolidModel(SurfaceModelMesh model, MaterialInfo material)
 {
     RenderHelper.BeginDrawModel(VertexBuffer, model.Transform, material);
     RenderHelper.ModelShader.IsSelected.Set(model.IsSelected);
     DrawModelElements(model);
     RenderHelper.EndDrawModel(VertexBuffer);
 }
コード例 #3
0
 private void DrawModelElements(SurfaceModelMesh model)
 {
     VertexBuffer.DrawElementsBaseVertex(PrimitiveType.Triangles,
                                         model.StartVertex,
                                         model.IndexCount,
                                         model.StartIndex * 4);
 }
コード例 #4
0
        private void RenderPartialMesh(MeshRenderMode renderMode, SurfaceModelMesh model, MaterialInfo material)
        {
            if (renderMode == MeshRenderMode.Wireframe && model.IsSelected)
            {
                //in wireframe mode, disable depth and color mask
                //but still write in stencil mask, this is needed for drawing the selection outline correctly
                GL.ColorMask(false, false, false, false);
                GL.DepthMask(false);
            }

            if (renderMode != MeshRenderMode.Wireframe || model.IsSelected)
            {
                DrawSolidModel(model, material);
            }

            if (model.IsSelected)
            {
                RenderHelper.DisableStencilMask();
            }

            if (renderMode == MeshRenderMode.Wireframe && model.IsSelected)
            {
                GL.ColorMask(true, true, true, true);
                GL.DepthMask(true);
            }

            if (renderMode == MeshRenderMode.Wireframe || renderMode == MeshRenderMode.SolidWireframe)
            {
                var wireColor = model.IsSelected && renderMode == MeshRenderMode.SolidWireframe ? RenderHelper.WireframeColorAlt : RenderHelper.WireframeColor;
                DrawWireframeModel(model, wireColor, 1f);
            }
        }
コード例 #5
0
        private SurfaceModelMesh AddMeshGeometry(ModelMeshReference modelMesh, List <int> indexList, List <VertVNT> vertexList)
        {
            var     geometry        = modelMesh.GetGeometry();
            int     indexOffset     = indexList.Count;
            int     vertexOffset    = vertexList.Count;
            var     triangleIndices = geometry.GetTriangleIndices();
            Vector3 minPos          = new Vector3(9999f);
            Vector3 maxPos          = new Vector3(-9999f);

            indexList.AddRange(triangleIndices);

            foreach (var vertex in geometry.Vertices)
            {
                var glVertex = new VertVNT()
                {
                    Position = vertex.Position.ToGL(),
                    Normal   = vertex.Normal.ToGL(),
                    TexCoord = geometry.IsTextured ? vertex.TexCoord.ToGL() : Vector2.Zero
                };

                minPos = Vector3.ComponentMin(minPos, glVertex.Position);
                maxPos = Vector3.ComponentMax(maxPos, glVertex.Position);
                vertexList.Add(glVertex);
            }

            var model = new SurfaceModelMesh(this, modelMesh, indexOffset, geometry.IndexCount, vertexOffset);

            model.BoundingBox = BBox.FromMinMax(minPos, maxPos);

            MeshModels.Add(model);
            return(model);
        }
コード例 #6
0
 private void DrawWireframeModel(SurfaceModelMesh model, Vector4 color, float thickness)
 {
     RenderHelper.BeginDrawWireframe(VertexBuffer, model.Transform, thickness, color);
     DrawModelElements(model);
     RenderHelper.EndDrawWireframe(VertexBuffer);
 }