示例#1
0
        private static IMeshBuilder <MaterialBuilder> BuildMapGeometryMeshStatic(MapGeometryModel model)
        {
            var meshBuilder = VERTEX.CreateCompatibleMesh();

            foreach (MapGeometrySubmesh submesh in model.Submeshes)
            {
                List <MapGeometryVertex> vertices = submesh.GetVertices();
                List <ushort>            indices  = submesh.GetIndices();

                MaterialBuilder material  = new MaterialBuilder(submesh.Material).WithUnlitShader();
                var             primitive = meshBuilder.UsePrimitive(material);

                List <VERTEX> gltfVertices = new List <VERTEX>();
                foreach (MapGeometryVertex vertex in vertices)
                {
                    gltfVertices.Add(CreateVertex(vertex));
                }

                for (int i = 0; i < indices.Count; i += 3)
                {
                    VERTEX v1 = gltfVertices[indices[i + 0]];
                    VERTEX v2 = gltfVertices[indices[i + 1]];
                    VERTEX v3 = gltfVertices[indices[i + 2]];

                    primitive.AddTriangle(v1, v2, v3);
                }
            }

            return(meshBuilder);
        }
示例#2
0
    void realityCheck(ContactInfo cantactInfo)
    {
        ContactInfo info         = cantactInfo;
        SURFACE     otherSurface = info.otherSurface;
        SURFACE     selfSurface  = info.selfSurface;
        VERTEX      vertex       = info.selfVertex;


        if (vertex != null)//point contact surface
        {
            bool inSurface  = Math3D.isProjectInSurface(vertex.pos, otherSurface.points[0].pos, otherSurface.points[1].pos);
            bool offContact = offContactSurface(vertex, otherSurface);
            if (!inSurface || offContact)
            {
                deleteContact(info);
            }
        }
        else if (selfSurface != null)//surface contact surface
        {
            bool surface0InSurface1 = surfaceInSurface(otherSurface, selfSurface);
            bool surface1InSurface0 = surfaceInSurface(selfSurface, otherSurface);
            bool OffContact         = offContactSurface(selfSurface.points[0], otherSurface);
            if (((!surface0InSurface1) && (!surface1InSurface0)) || OffContact)
            {
                deleteContact(info);
            }
        }
    }
示例#3
0
        public void OnPolymesh(PolymeshTopology node)
        {
            int nPts    = node.NumberOfPoints;
            int nFacets = node.NumberOfFacets;

            Debug.Print($"Polymesh : {nPts} vertices {nFacets} facets");

            IList <XYZ> vertices = node.GetPoints();
            IList <XYZ> normals  = node.GetNormals();

            DistributionOfNormals distrib = node.DistributionOfNormals;

            VERTEX[]  vertexs = new VERTEX[nPts];
            XYZ       p;
            Transform t = CurrentTransform;

            for (int i = 0; i < nPts; i++)
            {
                p = t.OfPoint(node.GetPoint(i));
                //vertexs[i] = new VERTEX((float)(p.Y*_foot_to_m), (float)(p.Z*_foot_to_m), (float)(p.X*_foot_to_m));
                vertexs[i] = new VERTEX((float)(p.Y), (float)(p.Z), (float)(p.X));
            }

            var prim = _mesh.UsePrimitive(_material);

            PolymeshFacet f;

            for (int i = 0; i < nFacets; i++)
            {
                f = node.GetFacet(i);
                prim.AddTriangle(vertexs[f.V1], vertexs[f.V2], vertexs[f.V3]);
            }
        }
    public SURFACE otherSurface; //correspond to the surface of CollideInfo

    public void reset()
    {
        other             = null;
        extraObj          = null;
        coupleContactInfo = null;
        blockDirect       = Vector3.zero;
        selfVertex        = null;
        selfSurface       = null;
        otherSurface      = null;
    }
 public void copy(ContactInfo otherInfo)
 {
     self              = otherInfo.self;
     other             = otherInfo.other;
     extraObj          = otherInfo.extraObj;
     coupleContactInfo = otherInfo.coupleContactInfo;
     blockDirect       = otherInfo.blockDirect;
     selfVertex        = otherInfo.selfVertex;
     otherSurface      = otherInfo.otherSurface;
 }
示例#6
0
        private static VERTEX _CreateVertex(Vector3 position, Matrix4x4 xform)
        {
            var v = new VERTEX();

            v.Geometry.Position = Vector3.Transform(position, xform);
            v.Geometry.Normal   = Vector3.Normalize(Vector3.TransformNormal(position, xform));
            v.Material.Color    = Vector4.One;
            v.Material.TexCoord = Vector2.Zero;

            return(v);
        }
 public void init()
 {
     minCollideTime   = -1;
     collidePoint     = Vector3.zero;
     collideSurfaceP0 = Vector3.zero;
     collideSurfaceP1 = Vector3.zero;
     intersectPoint   = Vector3.zero;
     vertex           = null;
     surface          = null;
     node             = null;
     reachGoalobj     = null;
 }
示例#8
0
    bool offContactSurface(VERTEX vertex, SURFACE surface)
    {
        Vector3 beginVec = vertex.pos - surface.points[0].pos;
        float   distDot  = Vector3.Dot(beginVec, surface.normal.direct);
        //Debug.Log ( distDot );
        float distLimit = 0.00001f;

        if (distDot > distLimit || distDot < -distLimit)
        {
            return(true);
        }
        return(false);
    }
示例#9
0
    protected void createVertexs()
    {
        offsetVec = new Vector3[vertexNum];

        for (int i = 0; i < vertexNum; i++)
        {
            offsetVec[i] = Vector3.zero;
        }
        _vertexs = new VERTEX[vertexNum];
        for (int i = 0; i < vertexNum; i++)
        {
            _vertexs[i] = new VERTEX(this);
        }
    }
示例#10
0
        private static VERTEX CreateVertex(MapGeometryVertex vertex)
        {
            VERTEX gltfVertex = new VERTEX();

            Vector3 position = vertex.Position.Value;
            Vector3 normal   = vertex.Normal.HasValue ? vertex.Normal.Value : Vector3.Zero;
            Color   color1   = vertex.SecondaryColor.HasValue ? vertex.SecondaryColor.Value : new Color(0, 0, 0, 1);
            Vector2 uv1      = vertex.DiffuseUV.HasValue ? vertex.DiffuseUV.Value : Vector2.Zero;
            Vector2 uv2      = vertex.LightmapUV.HasValue ? vertex.LightmapUV.Value : Vector2.Zero;

            return(gltfVertex
                   .WithGeometry(position, normal)
                   .WithMaterial(color1, uv1, uv2));
        }
示例#11
0
文件: HBEdge.cs 项目: andybak/CGAL
        public VERTEX GetVertex <VERTEX>() where VERTEX : HBVertex
        {
            if (Vertex == null)
            {
                return(null);
            }

            VERTEX vert = Vertex as VERTEX;

            if (vert == null)
            {
                throw new InvalidCastException("Vertex is not a " + typeof(VERTEX));
            }

            return(vert);
        }
示例#12
0
 public bool isOutOfStage()
 {
     if (Stage.border == null)
     {
         return(false);
     }
     for (int j = 0; j < _vertexs.Length; j++)
     {
         VERTEX point = _vertexs[j];
         if (Stage.isPointInStage(point.pos))
         {
             return(false);
         }
     }
     return(true);
 }
示例#13
0
    public void collideWithOtherBox(ABox other)
    {
        calculateGlobalspeedAndRelateVec(this, other);

        //if (!isObjsMatchCondition ( other ))
        //    return;

        for (int k = 0; k < other._surfaces.Length; k++)
        {
            SURFACE surface = other._surfaces[k];
            for (int j = 0; j < _vertexs.Length; j++)
            {
                VERTEX vertex = _vertexs[j];
                vertexContactSurface(vertex, surface);
            }
        }
        CollideManager.totalCollideObjNumPerFrame++;
    }
示例#14
0
 protected void initNormal()
 {
     for (int i = 0; i < surfaceNum; i++)
     {
         normals[i].init(_surfaces[i]);
         _surfaces[i].normal = normals[i];
     }
     for (int i = 0; i < surfaceNum; i++)
     {
         NORMAL   normal        = _surfaces[i].normal;
         VERTEX[] surfacePoints = _surfaces[i].points;
         for (int j = 0; j < surfacePoints.Length; j++)
         {
             VERTEX vertex = surfacePoints[j];
             vertex.normals.Add(normal);
         }
     }
 }
示例#15
0
        static void Main(string[] args)
        {
            var material = new MaterialBuilder("material1").WithUnlitShader();

            var mesh = VERTEX.CreateCompatibleMesh("points");

            // create a point cloud primitive
            var pointCloud = mesh.UsePrimitive(material, 1);

            var galaxy = new Galaxy();

            galaxy.scaleOverPlane = 0.05f;
            galaxy.randomJitter   = 0.01f;
            foreach (var startPoint in galaxy.CreateStarts(50000))
            {
                pointCloud.AddPoint((startPoint, Vector4.One));
            }

            galaxy.scaleOverPlane = 0.15f;
            galaxy.randomJitter   = 0.02f;
            foreach (var startPoint in galaxy.CreateStarts(50000))
            {
                pointCloud.AddPoint((startPoint, new Vector4(0.4f, 0.8f, 0.7f, 1)));
            }

            galaxy.randomJitter = 0.07f;
            foreach (var startPoint in galaxy.CreateStarts(10000))
            {
                pointCloud.AddPoint((startPoint, new Vector4(0.2f, 0.6f, 0.5f, 1)));
            }

            // create a new gltf model
            var model = ModelRoot.CreateModel();

            // add all meshes (just one in this case) to the model
            model.CreateMeshes(mesh);

            // create a scene, a node, and assign the first mesh (the terrain)
            model.UseScene("Default")
            .CreateNode().WithMesh(model.LogicalMeshes[0]);

            // save the model as GLB
            model.SaveGLB("Galaxy.glb");
        }
        public static ModelRoot ToGltf(this SimpleSkin skn, Dictionary <string, MagickImage> materialTextues = null)
        {
            SceneBuilder sceneBuilder = new SceneBuilder("model");
            var          meshBuilder  = VERTEX.CreateCompatibleMesh();

            foreach (SimpleSkinSubmesh submesh in skn.Submeshes)
            {
                MaterialBuilder material         = new MaterialBuilder(submesh.Name).WithUnlitShader();
                var             submeshPrimitive = meshBuilder.UsePrimitive(material);

                // Assign submesh Image
                if (materialTextues is not null && materialTextues.ContainsKey(submesh.Name))
                {
                    MagickImage submeshImage = materialTextues[submesh.Name];
                    AssignMaterialTexture(material, submeshImage);
                }

                // Build vertices
                var vertices = new List <VERTEX>(submesh.Vertices.Count);
                foreach (SimpleSkinVertex vertex in submesh.Vertices)
                {
                    VertexPositionNormal positionNormal = new VertexPositionNormal(vertex.Position, vertex.Normal);
                    VertexTexture1       uv             = new VertexTexture1(vertex.UV);

                    vertices.Add(new VERTEX(positionNormal, uv));
                }

                // Add vertices to primitive
                for (int i = 0; i < submesh.Indices.Count; i += 3)
                {
                    VERTEX v1 = vertices[submesh.Indices[i + 0]];
                    VERTEX v2 = vertices[submesh.Indices[i + 1]];
                    VERTEX v3 = vertices[submesh.Indices[i + 2]];

                    submeshPrimitive.AddTriangle(v1, v2, v3);
                }
            }

            sceneBuilder.AddRigidMesh(meshBuilder, new AffineTransform(new Vector3(-1, 1, 1), Quaternion.Identity, Vector3.Zero).Matrix);

            return(sceneBuilder.ToGltf2());
        }
示例#17
0
        public static ModelRoot ToGltf(this StaticObject staticObject)
        {
            ModelRoot root  = ModelRoot.CreateModel();
            Scene     scene = root.UseScene("default");

            var mesh = VERTEX.CreateCompatibleMesh();

            foreach (StaticObjectSubmesh submesh in staticObject.Submeshes)
            {
                MaterialBuilder material  = new MaterialBuilder(submesh.Name);
                var             primitive = mesh.UsePrimitive(material);

                List <VERTEX> vertices = new List <VERTEX>();
                foreach (StaticObjectVertex vertex in submesh.Vertices)
                {
                    vertices.Add(new VERTEX()
                                 .WithGeometry(vertex.Position)
                                 .WithMaterial(vertex.UV));
                }

                for (int i = 0; i < submesh.Indices.Count; i += 3)
                {
                    VERTEX v1 = vertices[(int)submesh.Indices[i + 0]];
                    VERTEX v2 = vertices[(int)submesh.Indices[i + 1]];
                    VERTEX v3 = vertices[(int)submesh.Indices[i + 2]];

                    primitive.AddTriangle(v1, v2, v3);
                }
            }

            scene
            .CreateNode()
            .WithMesh(root.CreateMesh(mesh));

            return(root);
        }
示例#18
0
文件: DxDLL.cs 项目: Rare25/BarrageDX
		public static int  DrawPolygon( out VERTEX  Vertex, int  PolygonNum, int  GrHandle, int  TransFlag, int  UVScaling)
		{
			if( System.IntPtr.Size == 4 )
			{
				return dx_DrawPolygon_x86( out Vertex , PolygonNum , GrHandle , TransFlag , UVScaling );
			}
			else
			{
				return dx_DrawPolygon_x64( out Vertex , PolygonNum , GrHandle , TransFlag , UVScaling );
			}
		}
示例#19
0
文件: DxDLL.cs 项目: Rare25/BarrageDX
		extern static int  dx_DrawPolygon_x64( out VERTEX  Vertex, int  PolygonNum, int  GrHandle, int  TransFlag, int  UVScaling);
示例#20
0
 public void AddTriangle(Material material, VERTEX a, VERTEX b, VERTEX c)
 {
     _Mesh.UsePrimitive(material).AddTriangle(a, b, c);
 }
示例#21
0
        private Model.BodyglTFModel GetglTFBodyModel(Body2 swBody)
        {
            BodyglTFModel BodyModel = new BodyglTFModel();

            if (swBody == null)
            {
                return(null);
            }
            try
            {
                var BodyMaterial = (double[])swBody.MaterialPropertyValues2;
                if (BodyMaterial != null)
                {
                    BodyModel.BodyMaterialValue = BodyMaterial;
                }

                #region 网格化
                Tessellation swTessellation = swBody.GetTessellation(null);
                if (swTessellation != null)
                {
                    swTessellation.NeedFaceFacetMap = true;
                    swTessellation.NeedVertexParams = true;
                    swTessellation.NeedVertexNormal = true;
                    swTessellation.ImprovedQuality  = true;
                    // How to handle matches across common edges
                    swTessellation.MatchType = (int)swTesselationMatchType_e.swTesselationMatchFacetTopology;
                    // Do it
                    bool bResult = swTessellation.Tessellate();
                }
                else
                {
                    return(null);
                }
                #endregion
                Face2 swFace = (Face2)swBody.GetFirstFace();

                while (swFace != null)
                {
                    Model.FaceglTFModel FaceModel = new FaceglTFModel();
                    var FaceMaterial = swFace.MaterialPropertyValues;
                    if (FaceMaterial != null)
                    {
                        FaceModel.FaceMaterialValue = FaceMaterial;
                    }
                    #region 面的三角化
                    int[] aFacetIds    = (int[])swTessellation.GetFaceFacets(swFace);
                    int   iNumFacetIds = aFacetIds.Length;
                    for (int iFacetIdIdx = 0; iFacetIdIdx < iNumFacetIds; iFacetIdIdx++)
                    {
                        int[] aFinIds = (int[])swTessellation.GetFacetFins(aFacetIds[iFacetIdIdx]);
                        // There should always be three fins per facet
                        FaceVertexModel model  = new FaceVertexModel();
                        List <double[]> points = new List <double[]>();
                        for (int iFinIdx = 0; iFinIdx < 3; iFinIdx++)
                        {
                            int[] aVertexIds = (int[])swTessellation.GetFinVertices(aFinIds[iFinIdx]);
                            // Should always be two vertices per fin
                            double[] aVertexCoords1 = (double[])swTessellation.GetVertexPoint(aVertexIds[0]);
                            double[] aVertexCoords2 = (double[])swTessellation.GetVertexPoint(aVertexIds[1]);
                            var      v1             = new VERTEX(Convert.ToSingle(aVertexCoords1[0]),
                                                                 Convert.ToSingle(aVertexCoords1[1]),
                                                                 Convert.ToSingle(aVertexCoords1[2]));
                            var v2 = new VERTEX(Convert.ToSingle(aVertexCoords2[0]),
                                                Convert.ToSingle(aVertexCoords2[1]),
                                                Convert.ToSingle(aVertexCoords2[2]));
                            bool isContain = false;
                            foreach (var item in points)
                            {
                                if ((Math.Abs(item[0] - aVertexCoords1[0]) + Math.Abs(item[1] - aVertexCoords1[1]) + Math.Abs(item[2] - aVertexCoords1[2])) < 0.00001)
                                {
                                    isContain = true;
                                }
                            }
                            if (!isContain)
                            {
                                points.Add(aVertexCoords1);
                            }

                            isContain = false;
                            foreach (var item in points)
                            {
                                if ((Math.Abs(item[0] - aVertexCoords2[0]) + Math.Abs(item[1] - aVertexCoords2[1]) + Math.Abs(item[2] - aVertexCoords2[2])) < 0.00001)
                                {
                                    isContain = true;
                                }
                            }
                            if (!isContain)
                            {
                                points.Add(aVertexCoords2);
                            }
                            // Create a line
                            //swModel.CreateLine2(aVertexCoords1[0], aVertexCoords1[1], aVertexCoords1[2], aVertexCoords2[0], aVertexCoords2[1], aVertexCoords2[2]);
                        }
                        if (points.Count == 3)
                        {
                            model.a = new VERTEX(Convert.ToSingle(points[0][0]),
                                                 Convert.ToSingle(points[0][1]),
                                                 Convert.ToSingle(points[0][2]));
                            model.b = new VERTEX(Convert.ToSingle(points[1][0]),
                                                 Convert.ToSingle(points[1][1]),
                                                 Convert.ToSingle(points[1][2]));
                            model.c = new VERTEX(Convert.ToSingle(points[2][0]),
                                                 Convert.ToSingle(points[2][1]),
                                                 Convert.ToSingle(points[2][2]));
                            FaceModel.FaceTri.Add(model);
                        }
                    }
                    if (FaceModel.FaceTri.Count > 0)
                    {
                        BodyModel.FaceList.Add(FaceModel);
                    }
                    swFace = (Face2)swFace.GetNextFace();
                    #endregion
                }
            }
            catch (Exception ex)
            {
            }
            return(BodyModel);
        }
示例#22
0
        public static void DoIt()
        {
            // todo: do something with laz file...
            var material = new MaterialBuilder("material1").WithUnlitShader();

            var mesh = VERTEX.CreateCompatibleMesh("points");

            // create a point cloud primitive
            var pointCloud = mesh.UsePrimitive(material, 1);


            var points = LasReader.Readlas("utrecht.laz");

            foreach (var p in points)
            {
                pointCloud.AddPoint((p, new Vector4(0.4f, 0.8f, 0.7f, 1)));
            }

            // create a new gltf model
            var model = ModelRoot.CreateModel();

            // add all meshes (just one in this case) to the model
            model.CreateMeshes(mesh);

            // create a scene, a node, and assign the first mesh (the terrain)
            model.UseScene("Default")
            .CreateNode().WithMesh(model.LogicalMeshes[0]);

            // save the model as GLB
            model.SaveGLB("Galaxy.glb");

            MessageBox.Show("Galaxy.glb is created");

            /**
             *
             * var galaxy = new Galaxy();
             *
             * galaxy.scaleOverPlane = 0.05f;
             * galaxy.randomJitter = 0.01f;
             * foreach (var startPoint in galaxy.CreateStarts(50000))
             * {
             *  pointCloud.AddPoint((startPoint, Vector4.One));
             * }
             *
             * galaxy.scaleOverPlane = 0.15f;
             * galaxy.randomJitter = 0.02f;
             * foreach (var startPoint in galaxy.CreateStarts(50000))
             * {
             *  pointCloud.AddPoint((startPoint, new Vector4(0.4f, 0.8f, 0.7f, 1)));
             * }
             *
             * galaxy.randomJitter = 0.07f;
             * foreach (var startPoint in galaxy.CreateStarts(10000))
             * {
             *  pointCloud.AddPoint((startPoint, new Vector4(0.2f, 0.6f, 0.5f, 1)));
             * }
             *
             * // create a new gltf model
             * var model = ModelRoot.CreateModel();
             *
             * // add all meshes (just one in this case) to the model
             * model.CreateMeshes(mesh);
             *
             * // create a scene, a node, and assign the first mesh (the terrain)
             * model.UseScene("Default")
             *  .CreateNode().WithMesh(model.LogicalMeshes[0]);
             *
             * // save the model as GLB
             * model.SaveGLB("Galaxy.glb");
             *
             * MessageBox.Show("Galaxy.glb is created");
             */
        }
示例#23
0
		public static int  DrawPolygonBase( out VERTEX  Vertex, int  VertexNum, int  PrimitiveType, int  GrHandle, int  TransFlag, int  UVScaling)
		{
			return dx_DrawPolygonBase( out Vertex , VertexNum , PrimitiveType , GrHandle , TransFlag , UVScaling );
		}
示例#24
0
        private static void ContainedMeshToGLTF(List <RawMeshContainer> meshes, FileInfo outfile)
        {
            var scene = new SharpGLTF.Scenes.SceneBuilder();

            int mIndex = -1;

            foreach (var mesh in meshes)
            {
                ++mIndex;
                long indCount = mesh.indices.Length;
                var  expmesh  = new MESH(string.Format(Path.GetFileNameWithoutExtension(outfile.FullName) + "_mesh_{0}", mIndex));

                var prim = expmesh.UsePrimitive(new MaterialBuilder("Default"));
                for (long i = 0; i < indCount; i += 3)
                {
                    uint idx0 = mesh.indices[i + 1];
                    uint idx1 = mesh.indices[i];
                    uint idx2 = mesh.indices[i + 2];

                    //VPNT
                    Vec3 p_0 = new Vec3(mesh.vertices[idx0].X, mesh.vertices[idx0].Y, mesh.vertices[idx0].Z);
                    Vec3 n_0 = new Vec3(mesh.normals[idx0].X, mesh.normals[idx0].Y, mesh.normals[idx0].Z);
                    Vec4 t_0 = new Vec4(new Vec3(mesh.tangents[idx0].X, mesh.tangents[idx0].Y, mesh.tangents[idx0].Z), 1);

                    Vec3 p_1 = new Vec3(mesh.vertices[idx1].X, mesh.vertices[idx1].Y, mesh.vertices[idx1].Z);
                    Vec3 n_1 = new Vec3(mesh.normals[idx1].X, mesh.normals[idx1].Y, mesh.normals[idx1].Z);
                    Vec4 t_1 = new Vec4(new Vec3(mesh.tangents[idx1].X, mesh.tangents[idx1].Y, mesh.tangents[idx1].Z), 1);

                    Vec3 p_2 = new Vec3(mesh.vertices[idx2].X, mesh.vertices[idx2].Y, mesh.vertices[idx2].Z);
                    Vec3 n_2 = new Vec3(mesh.normals[idx2].X, mesh.normals[idx2].Y, mesh.normals[idx2].Z);
                    Vec4 t_2 = new Vec4(new Vec3(mesh.tangents[idx2].X, mesh.tangents[idx2].Y, mesh.tangents[idx2].Z), 1);

                    //VCT
                    Vec2 tx0_0 = new Vec2(mesh.tx0coords[idx0].X, mesh.tx0coords[idx0].Y);
                    Vec2 tx1_0 = new Vec2(mesh.tx1coords[idx0].X, mesh.tx1coords[idx0].Y);

                    Vec2 tx0_1 = new Vec2(mesh.tx0coords[idx1].X, mesh.tx0coords[idx1].Y);
                    Vec2 tx1_1 = new Vec2(mesh.tx1coords[idx1].X, mesh.tx1coords[idx1].Y);

                    Vec2 tx0_2 = new Vec2(mesh.tx0coords[idx2].X, mesh.tx0coords[idx2].Y);
                    Vec2 tx1_2 = new Vec2(mesh.tx1coords[idx2].X, mesh.tx1coords[idx2].Y);

                    Vec4 col_0 = new Vec4(mesh.colors[idx0].X, mesh.colors[idx0].Y, mesh.colors[idx0].Z, mesh.colors[idx0].W);
                    Vec4 col_1 = new Vec4(mesh.colors[idx1].X, mesh.colors[idx1].Y, mesh.colors[idx1].Z, mesh.colors[idx1].W);
                    Vec4 col_2 = new Vec4(mesh.colors[idx2].X, mesh.colors[idx2].Y, mesh.colors[idx2].Z, mesh.colors[idx2].W);

                    // vertex build
                    var v0 = new VERTEX(new VPNT(p_0, n_0, t_0), new VCT(col_0, tx0_0, tx1_0));
                    var v1 = new VERTEX(new VPNT(p_1, n_1, t_1), new VCT(col_1, tx0_1, tx1_1));
                    var v2 = new VERTEX(new VPNT(p_2, n_2, t_2), new VCT(col_2, tx0_2, tx1_2));

                    // triangle build
                    prim.AddTriangle(v0, v1, v2);
                }
                scene.AddRigidMesh(expmesh, System.Numerics.Matrix4x4.Identity);
            }

            var model = scene.ToGltf2();

            model.SaveGLB(Path.GetFullPath(outfile.FullName).Replace(".mesh", ".glb"));
        }
示例#25
0
		public static int  DrawPolygon( out VERTEX  Vertex, int  PolygonNum, int  GrHandle, int  TransFlag, int  UVScaling)
		{
			return dx_DrawPolygon( out Vertex , PolygonNum , GrHandle , TransFlag , UVScaling );
		}
示例#26
0
    //collide will ocur after this time
    public void vertexContactSurface(VERTEX vertex, SURFACE surface)
    {
        //ignore vertexs which is back to surface
        bool isFacing = false;

        for (int i = 0; i < vertex.normals.Count; i++)
        {
            Vector3 vertexNormal = vertex.normals[i].direct;
            float   facingDot    = Vector3.Dot(vertexNormal, surface.normal.direct);
            float   threshold    = 0.000001f;
            if (facingDot > -threshold && facingDot < threshold)
            {
                facingDot = 0;
            }
            if (facingDot < 0)
            {
                isFacing = true;
                break;
            }
        }
        if (!isFacing)
        {
            return;
        }
        //check if under surface
        Vector3 beginVec = surface.points[0].pos - vertex.pos;
        float   dist     = Vector3.Dot(beginVec, surface.normal.direct);

        if (dist > 0)//ignore the surfaces which is back to vertex
        {
            return;
        }

        // relateVec intersect surface
        Vector3 perpendicularVec = surface.normal.direct * dist;
        float   angle            = Vector3.Angle(-relateVec, perpendicularVec);

        if (angle >= 90)//parallel
        {
            return;
        }
        float length = Mathf.Abs(dist) / Mathf.Cos(Mathf.Deg2Rad * angle);

        Vector3 intersectPoint = vertex.pos - relateVec.normalized * length;
        //contactsurface
        float collideTime = length / relateVec.magnitude;

        surface.belongToObj.computeGlobalSpeed();
        Vector3 surfaceGlobalSpeedVec = surface.belongToObj.globalSpeedVec;
        Vector3 collideSurfaceP0      = surface.points[0].pos + surfaceGlobalSpeedVec * collideTime;
        Vector3 collideSurfaceP1      = surface.points[1].pos + surfaceGlobalSpeedVec * collideTime;
        //Vector3 collideSurfaceNormal = surface.normal.direct;
        //check if in contact surface
        Vector3 collidePoint = vertex.pos + globalSpeedVec * collideTime;

        if (Math3D.isProjectInSurface(collidePoint, collideSurfaceP0, collideSurfaceP1))   //will contact in future
        {
            CollideInfo info = CollideManager.collideInfo;
            if (info.minCollideTime == -1 || collideTime < info.minCollideTime)
            {
                info.minCollideTime   = collideTime;
                info.collidePoint     = collidePoint;
                info.collideSurfaceP0 = collideSurfaceP0;
                info.collideSurfaceP1 = collideSurfaceP1;
                info.intersectPoint   = intersectPoint;
                info.vertex           = vertex;
                info.surface          = surface;
                info.node             = null;
                info.reachGoalobj     = null;
            }
        }
    }
示例#27
0
文件: DxDLL.cs 项目: Rare25/BarrageDX
		extern static int  dx_DrawPolygonBase_x64( out VERTEX  Vertex, int  VertexNum, int  PrimitiveType, int  GrHandle, int  TransFlag, int  UVScaling);
示例#28
0
文件: DxDLL.cs 项目: Rare25/BarrageDX
		public static int  DrawPolygonBase( out VERTEX  Vertex, int  VertexNum, int  PrimitiveType, int  GrHandle, int  TransFlag, int  UVScaling)
		{
			if( System.IntPtr.Size == 4 )
			{
				return dx_DrawPolygonBase_x86( out Vertex , VertexNum , PrimitiveType , GrHandle , TransFlag , UVScaling );
			}
			else
			{
				return dx_DrawPolygonBase_x64( out Vertex , VertexNum , PrimitiveType , GrHandle , TransFlag , UVScaling );
			}
		}
示例#29
0
        private static IMeshBuilder <MaterialBuilder> BuildMesh(PapaMeshBinding meshBinding)
        {
            var meshBuilder = VERTEX.CreateCompatibleMesh();

            foreach (PapaMaterialGroup materialGroup in meshBinding.Mesh.MaterialGroups)
            {
                // Skip empty materials
                if (materialGroup.PrimitiveCount == 0)
                {
                    continue;
                }

                MaterialBuilder materialBuiler    = new MaterialBuilder(materialGroup.Name).WithSpecularGlossinessShader();
                var             materialPrimitive = meshBuilder.UsePrimitive(materialBuiler);

                // Check for DiffuseColor material parameter
                if (materialGroup.Material.VectorParameters.Any(x => x.Name == "DiffuseColor"))
                {
                    PapaVectorParameter diffuseColor = materialGroup.Material.VectorParameters.FirstOrDefault(x => x.Name == "DiffuseColor");

                    materialBuiler.UseChannel(KnownChannel.Diffuse).Parameter = diffuseColor.Value;
                }

                int minVertex = int.MaxValue;
                int maxVertex = int.MinValue;
                for (uint i = materialGroup.FirstIndex; i < materialGroup.PrimitiveCount * 3; i++)
                {
                    uint index = meshBinding.Mesh.Indices[(int)i];

                    if (index < minVertex)
                    {
                        minVertex = (int)index;
                    }
                    if (index > maxVertex)
                    {
                        maxVertex = (int)index;
                    }
                }

                int           vertexCount = maxVertex - minVertex + 1;
                List <VERTEX> vertices    = new(vertexCount);
                for (int i = minVertex; i < maxVertex + 1; i++)
                {
                    PapaVertex papaVertex = meshBinding.Mesh.Vertices[i];
                    VERTEX     vertex     = new VERTEX();

                    vertex.Geometry = new VertexPositionNormal()
                    {
                        Position = papaVertex.Position.Value,
                        Normal   = papaVertex.Normal.HasValue ? papaVertex.Normal.Value : new Vector3()
                    };

                    vertex.Material = new VertexColor2Texture2()
                    {
                        Color0    = papaVertex.Color1.HasValue ? papaVertex.Color1.Value : new Color(),
                        Color1    = papaVertex.Color2.HasValue ? papaVertex.Color2.Value : new Color(),
                        TexCoord0 = papaVertex.TexCoord1.HasValue ? papaVertex.TexCoord1.Value : new Vector2(),
                        TexCoord1 = papaVertex.TexCoord2.HasValue ? papaVertex.TexCoord2.Value : new Vector2(),
                    };

                    vertices.Add(vertex);
                }

                for (uint i = materialGroup.FirstIndex; i < materialGroup.PrimitiveCount * 3; i += 3)
                {
                    int index0 = (int)meshBinding.Mesh.Indices[(int)i + 0] - minVertex;
                    int index1 = (int)meshBinding.Mesh.Indices[(int)i + 1] - minVertex;
                    int index2 = (int)meshBinding.Mesh.Indices[(int)i + 2] - minVertex;

                    VERTEX vertex0 = vertices[index0];
                    VERTEX vertex1 = vertices[index1];
                    VERTEX vertex2 = vertices[index2];

                    materialPrimitive.AddTriangle(vertex0, vertex1, vertex2);
                }
            }

            return(meshBuilder);
        }