Example #1
0
        public static string GetMaterialDefault(SUDrawingElementRef element)
        {
            SUMaterialRef suMaterialRef = default(SUMaterialRef);

            SKPCExport.SUDrawingElementGetMaterial(element, ref suMaterialRef);
            return(GetIdentity(SKPCExport.SUMaterialToEntity(suMaterialRef)));
        }
Example #2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="groupRef"></param>
        public void Load(SUGroupRef groupRef)
        {
            SUDrawingElementRef drawingRef = SKPCExport.SUGroupToDrawingElement(groupRef);
            SUEntityRef         entityRef  = SKPCExport.SUDrawingElementToEntity(drawingRef);

            m_identity = SkpEntityCache.GetIdentity(entityRef);
            m_defaultMaterialIdentity = SkpEntityCache.GetMaterialDefault(drawingRef);

            SUEntitiesRef entities = default;

            SKPCExport.SUGroupGetEntities(groupRef, ref entities);

            m_faces     = SkpFace.GetEntityFaces(entities, Model);
            m_instances = SkpInstance.GetEntityInstances(entities, Model);
            m_groups    = SkpGroup.GetEntityGroups(entities, Model);

            SUTransformation transform = default;

            SKPCExport.SUGroupGetTransform(groupRef, ref transform);
            m_transform = new SkpTransform(transform);

            SUStringRef groupName = default(SUStringRef);

            SKPCExport.SUStringCreate(ref groupName);
            SKPCExport.SUGroupGetName(groupRef, ref groupName);
            m_name = Utilities.GetString(groupName);
            SKPCExport.SUStringRelease(ref groupName);

            m_clusters = SkpFaceCluster.Load(m_faces.Values, m_model);
        }
Example #3
0
        /// <summary>
        /// 获取唯一标记
        /// </summary>
        /// <param name="suEntity"></param>
        /// <param name="p_indentityDefault"></param>
        /// <returns></returns>
        public static string GetIdentity(SUEntityRef suEntity)
        {
            if (suEntity.ptr == IntPtr.Zero)
            {
                return(null);
            }

            long persistentID = default;

            SKPCExport.SUEntityGetPersistentID(suEntity, ref persistentID);
            if (persistentID != 0)
            {
                string identityStr = persistentID.ToString();
                return(identityStr);
            }

            if (GetAttribute(suEntity, "Sandu", "Identity", out string identitySandu))
            {
                return(identitySandu);
            }

            int entityID = default;

            SKPCExport.SUEntityGetID(suEntity, ref entityID);
            string identityID = entityID.ToString();

            return(identityID);
        }
Example #4
0
        /// <summary>
        /// 获取属性值
        /// </summary>
        /// <param name="suEntityRef"></param>
        /// <param name="attributeName"></param>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        public static bool GetAttribute(SUEntityRef suEntityRef, string attributeName, string propertyName, out string defaultValue)
        {
            if (suEntityRef.ptr == IntPtr.Zero)
            {
                defaultValue = null;
                return(false);
            }
            SUAttributeDictionaryRef dictionaryRef = default(SUAttributeDictionaryRef);

            if (SKPCExport.SUEntityGetAttributeDictionary(suEntityRef, attributeName, ref dictionaryRef) == SUResult.SU_ERROR_NONE)
            {
                SUTypedValueRef propertyValueRef = default(SUTypedValueRef);
                if (SKPCExport.SUAttributeDictionaryGetValue(dictionaryRef, attributeName, ref propertyValueRef) == SUResult.SU_ERROR_NONE)
                {
                    SUStringRef temp = default;
                    SKPCExport.SUStringCreate(ref temp);
                    SKPCExport.SUTypedValueGetString(propertyValueRef, ref temp);
                    defaultValue = Utilities.GetString(temp);
                    SKPCExport.SUStringRelease(ref temp);
                    return(true);
                }
            }
            defaultValue = null;
            return(false);
        }
Example #5
0
        public void Load(SUComponentDefinitionRef p_suComponentRef)
        {
            SUDrawingElementRef drawingRef = SKPCExport.SUComponentDefinitionToDrawingElement(p_suComponentRef);
            SUEntityRef         entityRef  = SKPCExport.SUDrawingElementToEntity(drawingRef);

            m_identity = SkpEntityCache.GetIdentity(entityRef);
            m_defaultMaterialIdentity = SkpEntityCache.GetMaterialDefault(drawingRef);

            SUEntitiesRef entities = default(SUEntitiesRef);

            SKPCExport.SUComponentDefinitionGetEntities(p_suComponentRef, ref entities);
            m_instances = SkpInstance.GetEntityInstances(entities, Model);
            m_groups    = SkpGroup.GetEntityGroups(entities, Model);
            m_faces     = SkpFace.GetEntityFaces(entities, Model);
            m_clusters  = SkpFaceCluster.Load(m_faces.Values, m_model);
        }
Example #6
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);
        }
Example #7
0
        /// <summary>
        /// 异步加载组件
        /// </summary>
        /// <param name="model"></param>
        /// <param name="p_model"></param>
        /// <returns></returns>
        public static Task <Dictionary <string, SkpComponent> > GetComponentsAsync(SUModelRef model, SkpModel p_model)
        {
            TaskCompletionSource <Dictionary <string, SkpComponent> > tcs = new TaskCompletionSource <Dictionary <string, SkpComponent> >();

            Task.Run(() =>
            {
                long componentsCount = 0;
                SKPCExport.SUModelGetNumComponentDefinitions(model, ref componentsCount);

                if (componentsCount > 0)
                {
                    SUComponentDefinitionRef[] componentRefs = new SUComponentDefinitionRef[componentsCount];
                    SKPCExport.SUModelGetComponentDefinitions(model, componentsCount, componentRefs, ref componentsCount);

                    TaskExcutor.Run <SkpComponent, SUComponentDefinitionRef>(componentRefs, c =>
                    {
                        SkpComponent component = new SkpComponent(p_model);
                        component.Load(c);
                        return(component);
                    }).ContinueWith(t =>
                    {
                        if (t.IsFaulted)
                        {
                            tcs.TrySetException(t.Exception);
                        }
                        else
                        {
                            Dictionary <string, SkpComponent> components = t.Result.ToDictionary(p => p.Identity, p => p);
                            tcs.TrySetResult(components);
                        }
                    });
                }
                else
                {
                    tcs.TrySetResult(new Dictionary <string, SkpComponent>());
                }
            });

            return(tcs.Task);
        }
Example #8
0
        public static Task <Dictionary <string, SkpGroup> > GetEntityGroupsAsync(SUEntitiesRef p_suEntitiesRef, SkpModel p_model)
        {
            TaskCompletionSource <Dictionary <string, SkpGroup> > tcs = new TaskCompletionSource <Dictionary <string, SkpGroup> >();

            long groupsCount = 0;

            SKPCExport.SUEntitiesGetNumGroups(p_suEntitiesRef, ref groupsCount);

            if (groupsCount > 0)
            {
                SUGroupRef[] groupRefs = new SUGroupRef[groupsCount];
                SKPCExport.SUEntitiesGetGroups(p_suEntitiesRef, groupsCount, groupRefs, ref groupsCount);

                TaskExcutor.Run <SkpGroup, SUGroupRef>(groupRefs, g =>
                {
                    SkpGroup group = new SkpGroup(p_model);
                    group.Load(g);

                    return(group);
                }).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, SkpGroup>());
            }

            return(tcs.Task);
        }
Example #9
0
        public static Dictionary <string, SkpGroup> GetEntityGroups(SUEntitiesRef p_suEntitiesRef, SkpModel p_model)
        {
            Dictionary <string, SkpGroup> groups = new Dictionary <string, SkpGroup>(100);

            long groupsCount = 0;

            SKPCExport.SUEntitiesGetNumGroups(p_suEntitiesRef, ref groupsCount);

            if (groupsCount > 0)
            {
                SUGroupRef[] groupRefs = new SUGroupRef[groupsCount];
                SKPCExport.SUEntitiesGetGroups(p_suEntitiesRef, groupsCount, groupRefs, ref groupsCount);

                for (long i = 0; i < groupsCount; i++)
                {
                    SkpGroup group = new SkpGroup(p_model);
                    group.Load(groupRefs[i]);
                    groups.Add(group.Identity, group);
                }
            }

            return(groups);
        }
Example #10
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);
        }
Example #11
0
        public static Dictionary <string, SkpComponent> GetComponents(SUModelRef model, SkpModel p_model)
        {
            Dictionary <string, SkpComponent> components = new Dictionary <string, SkpComponent>(200);

            long componentsCount = 0;

            SKPCExport.SUModelGetNumComponentDefinitions(model, ref componentsCount);

            if (componentsCount > 0)
            {
                SUComponentDefinitionRef[] componentRefs = new SUComponentDefinitionRef[componentsCount];
                SKPCExport.SUModelGetComponentDefinitions(model, componentsCount, componentRefs, ref componentsCount);

                for (long i = 0; i < componentsCount; i++)
                {
                    SkpComponent component = new SkpComponent(p_model);
                    component.Load(componentRefs[i]);
                    components.Add(component.Identity, component);
                }
            }

            return(components);
        }
Example #12
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);
        }
Example #13
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="value"></param>
        public SkpDataValue(SUTypedValueRef value)
        {
            SUTypedValueType type = SUTypedValueType.SUTypedValueType_Empty;

            SKPCExport.SUTypedValueGetType(value, ref type);
            m_dataType = (DataType)type;

            switch (type)
            {
            case SUTypedValueType.SUTypedValueType_Empty:
            {
                m_value = null;
                break;
            }

            case SUTypedValueType.SUTypedValueType_Byte:
            {
                byte temp = default;
                SKPCExport.SUTypedValueGetByte(value, ref temp);
                m_value = temp;
                break;
            }

            case SUTypedValueType.SUTypedValueType_Short:
            {
                short temp = default;
                SKPCExport.SUTypedValueGetInt16(value, ref temp);
                m_value = temp;
                break;
            }

            case SUTypedValueType.SUTypedValueType_Int32:
            {
                int temp = default;
                SKPCExport.SUTypedValueGetInt32(value, ref temp);
                m_value = temp;
                break;
            }

            case SUTypedValueType.SUTypedValueType_Float:
            {
                float temp = default;
                SKPCExport.SUTypedValueGetFloat(value, ref temp);
                m_value = temp;
                break;
            }

            case SUTypedValueType.SUTypedValueType_Double:
            {
                double temp = default;
                SKPCExport.SUTypedValueGetDouble(value, ref temp);
                m_value = temp;
                break;
            }

            case SUTypedValueType.SUTypedValueType_Bool:
            {
                bool temp = default;
                SKPCExport.SUTypedValueGetBool(value, ref temp);
                m_value = temp;
                break;
            }

            case SUTypedValueType.SUTypedValueType_Color:
            {
                SUColor temp = default;
                SKPCExport.SUTypedValueGetColor(value, ref temp);
                m_value = /*new SkpColor(temp)*/ temp;
                break;
            }

            case SUTypedValueType.SUTypedValueType_Time:
            {
                long temp = default;
                SKPCExport.SUTypedValueGetTime(value, ref temp);
                m_value = new System.DateTime(1970, 1, 1).AddSeconds(temp);
                break;
            }

            case SUTypedValueType.SUTypedValueType_String:
            {
                SUStringRef temp = default;
                SKPCExport.SUStringCreate(ref temp);
                SKPCExport.SUTypedValueGetString(value, ref temp);
                m_value = Utilities.GetString(temp);
                SKPCExport.SUStringRelease(ref temp);
                break;
            }

            case SUTypedValueType.SUTypedValueType_Vector3D:
            {
                double[] temp = new double[3];
                SKPCExport.SUTypedValueGetVector3d(value, temp);
                m_value = new SUVector3D {
                    x = temp[0], y = temp[1], z = temp[2]
                };
                break;
            }

            case SUTypedValueType.SUTypedValueType_Array:
            {
                long count = default;
                SKPCExport.SUTypedValueGetNumArrayItems(value, ref count);
                SUTypedValueRef[] values = new SUTypedValueRef[count];
                SKPCExport.SUTypedValueGetArrayItems(value, count, values, ref count);
                SkpDataValue[] temp = new SkpDataValue[count];
                for (int i = 0; i < count; i++)
                {
                    temp[i] = new SkpDataValue(values[i]);
                }
                m_value = temp;
                break;
            }

            default:
                break;
            }
        }
Example #14
0
 /// <summary>
 /// 获取组件identity
 /// </summary>
 /// <param name="p_suComponentRef"></param>
 /// <returns></returns>
 public static string GetIdentity(SUComponentDefinitionRef p_suComponentRef)
 {
     return(SkpEntityCache.GetIdentity(SKPCExport.SUComponentDefinitionToEntity(p_suComponentRef)));
 }
Example #15
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);
        }