Пример #1
0
        public void Load(SUFaceRef p_suFaceRef)
        {
            SUDrawingElementRef drawingRef = SKPCExport.SUFaceToDrawingElement(p_suFaceRef);
            SUEntityRef         entityRef  = SKPCExport.SUDrawingElementToEntity(drawingRef);

            m_identity = SkpEntityCache.GetIdentity(entityRef);

            SUMaterialRef suFrontMaterialRef = default(SUMaterialRef);

            SKPCExport.SUFaceGetFrontMaterial(p_suFaceRef, ref suFrontMaterialRef);
            m_frontMaterialIdentity = SkpEntityCache.GetIdentity(SKPCExport.SUMaterialToEntity(suFrontMaterialRef));

            SUMaterialRef suBackMaterialRef = default(SUMaterialRef);

            SKPCExport.SUFaceGetBackMaterial(p_suFaceRef, ref suBackMaterialRef);
            m_backMaterialIdentity = SkpEntityCache.GetIdentity(SKPCExport.SUMaterialToEntity(suBackMaterialRef));

            m_faceMesh = new SkpFaceMesh(this);
            m_faceMesh.Load(p_suFaceRef);
        }
Пример #2
0
        public static Dictionary <string, SkpFace> GetEntityFaces(SUEntitiesRef p_suEntitiesRef, SkpModel p_model)
        {
            Dictionary <string, SkpFace> surfaces = new Dictionary <string, SkpFace>(200);

            long faceCount = 0;

            SKPCExport.SUEntitiesGetNumFaces(p_suEntitiesRef, ref faceCount);

            if (faceCount > 0)
            {
                SUFaceRef[] faces = new SUFaceRef[faceCount];
                SKPCExport.SUEntitiesGetFaces(p_suEntitiesRef, faceCount, faces, ref faceCount);

                for (long i = 0; i < faceCount; i++)
                {
                    SkpFace surface = new SkpFace(p_model);
                    surface.Load(faces[i]);
                    surfaces.Add(surface.Identity, surface);
                }
            }

            return(surfaces);
        }
Пример #3
0
        public static Task <Dictionary <string, SkpFace> > GetEntityFacesAsync(SUEntitiesRef p_suEntitiesRef, SkpModel p_model)
        {
            TaskCompletionSource <Dictionary <string, SkpFace> > tcs = new TaskCompletionSource <Dictionary <string, SkpFace> >();
            long faceCount = 0;

            SKPCExport.SUEntitiesGetNumFaces(p_suEntitiesRef, ref faceCount);

            if (faceCount > 0)
            {
                SUFaceRef[] faces = new SUFaceRef[faceCount];
                SKPCExport.SUEntitiesGetFaces(p_suEntitiesRef, faceCount, faces, ref faceCount);

                TaskExcutor.Run <SkpFace, SUFaceRef>(faces, f =>
                {
                    SkpFace surface = new SkpFace(p_model);
                    surface.Load(f);
                    return(surface);
                }).ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        tcs.TrySetException(t.Exception);
                    }
                    else
                    {
                        tcs.TrySetResult(t.Result.ToDictionary(p => p.Identity, p => p));
                    }
                });
            }
            else
            {
                tcs.TrySetResult(new Dictionary <string, SkpFace>());
            }

            return(tcs.Task);
        }
Пример #4
0
        static unsafe void Main(string[] args)
        {
            SUInitialize();

            nuint major, minor;

            SUGetAPIVersion(&major, &minor);
            Console.WriteLine($"SU API Version");
            Console.WriteLine($"  Major = {major}");
            Console.WriteLine($"  Minor = {minor}");

            SUResult   res;
            SUModelRef model;
            var        path1 = System.Text.Encoding.ASCII.GetBytes("model.skp\0");
            var        path2 = (sbyte[])(Array)path1;

            fixed(sbyte *path3 = path2)
            {
                res = SUModelCreateFromFile(&model, path3);
            }

            SUEntitiesRef entities;

            res = SUModelGetEntities(model, &entities);

            // Get all the faces from the entities object
            nuint faceCount;

            res = SUEntitiesGetNumFaces(entities, &faceCount);
            if (faceCount > 0)
            {
                var faces = new SUFaceRef[faceCount];
                fixed(SUFaceRef *faceRef = faces)
                {
                    res = SUEntitiesGetFaces(entities, faceCount, faceRef, &faceCount);
                }

                // Get all the edges in this face
                for (nuint i = 0; i < faceCount; i++)
                {
                    Console.WriteLine($"Face {i + 1}:");
                    nuint edgeCount;
                    res = SUFaceGetNumEdges(faces[i], &edgeCount);
                    if (edgeCount > 0)
                    {
                        var edges = new SUEdgeRef[edgeCount];
                        fixed(SUEdgeRef *edgeRef = edges)
                        {
                            res = SUFaceGetEdges(faces[i], edgeCount, edgeRef, &edgeCount);
                        }

                        // Get the vertex positions for each edge
                        for (nuint j = 0; j < edgeCount; j++)
                        {
                            SUVertexRef startVertex, endVertex;
                            res = SUEdgeGetStartVertex(edges[j], &startVertex);
                            res = SUEdgeGetEndVertex(edges[j], &endVertex);

                            SUPoint3D start, end;
                            res = SUVertexGetPosition(startVertex, &start);
                            res = SUVertexGetPosition(endVertex, &end);
                            // Now do something with the point data

                            Console.WriteLine($"  Edge {j + 1}:");
                            Console.WriteLine($"    Start: {start.x},{start.y},{start.z}");
                            Console.WriteLine($"    End: {end.x},{end.y},{end.z}");
                        }
                    }
                }
            }

            // Get model name
            SUStringRef name;

            res = SUStringCreate(&name);
            res = SUModelGetName(model, &name);
            nuint name_length;

            res = SUStringGetUTF8Length(name, &name_length);
            var nameUtf8 = new sbyte[name_length + 1];

            fixed(sbyte *nameUtf8Ref = nameUtf8)
            {
                res = SUStringGetUTF8(name, name_length + 1, nameUtf8Ref, &name_length);
            }

            res = SUStringRelease(&name);

            res = SUModelRelease(&model);
            SUTerminate();
        }
Пример #5
0
        public void Load(SUFaceRef face)
        {
            SUMeshHelperRef helper = default(SUMeshHelperRef);

            SKPCExport.SUMeshHelperCreate(ref helper, face);
            long vCount = 0;

            SKPCExport.SUMeshHelperGetNumVertices(helper, ref vCount);
            if (vCount > 0)
            {
                m_vertices = new SUPoint3D[vCount];
                SKPCExport.SUMeshHelperGetVertices(helper, vCount, m_vertices, ref vCount);

                for (int i = 0; i < vCount; i++)
                {
                    m_vertices[i].x *= 0.0254;
                    m_vertices[i].y *= 0.0254;
                    m_vertices[i].z *= 0.0254;
                }
            }

            long fCount = 0;
            long ret    = 0;

            SKPCExport.SUMeshHelperGetNumTriangles(helper, ref fCount);
            if (fCount > 0)
            {
                long[] fs = new long[3 * fCount];
                m_triangles = new int[3 * fCount];
                SKPCExport.SUMeshHelperGetVertexIndices(helper, 3 * fCount, fs, ref ret);

                for (long j = 0; j < 3 * fCount; j++)
                {
                    m_triangles[j] = (int)fs[j];
                }
            }

            long frontUVCount = 0;

            SKPCExport.SUMeshHelperGetNumVertices(helper, ref frontUVCount);
            if (frontUVCount > 0)
            {
                m_uvsFront = new SUPoint3D[frontUVCount];
                SKPCExport.SUMeshHelperGetFrontSTQCoords(helper, frontUVCount, m_uvsFront, ref frontUVCount);
            }

            long backUVCount = 0;

            SKPCExport.SUMeshHelperGetNumVertices(helper, ref backUVCount);
            if (backUVCount > 0)
            {
                m_uvsBack = new SUPoint3D[backUVCount];
                SKPCExport.SUMeshHelperGetBackSTQCoords(helper, backUVCount, m_uvsBack, ref backUVCount);
            }

            long normalCount = 0;

            SKPCExport.SUMeshHelperGetNumVertices(helper, ref normalCount);
            if (backUVCount > 0)
            {
                m_normals = new SUVector3D[normalCount];
                SKPCExport.SUMeshHelperGetNormals(helper, normalCount, m_normals, ref normalCount);
            }

            SKPCExport.SUMeshHelperRelease(ref helper);
        }