Exemplo n.º 1
0
        public static UnityComponent FromAssimpMetadata(aiMetadata meta)
        {
            UnityComponent metadata = null;

            if (meta != null && meta.Keys != null)
            {
                uint size = meta.Keys.Size();

                if (meta.Values != null && meta.Values.Size() == size)
                {
                    if (size > 0)
                    {
                        Dictionary <string, object> storage = new Dictionary <string, object>();

                        for (uint i = 0; i < size; ++i)
                        {
                            using (aiString key = meta.Keys.Get(i))
                            {
                                using (aiMetadataEntry entry = meta.Values.Get(i))
                                {
                                    object value = null;

                                    switch (entry.mType)
                                    {
                                    case aiMetadataType.AI_BOOL:
                                        value = entry.GetBool();
                                        break;

                                    case aiMetadataType.AI_INT32:
                                        value = entry.GetInt32();
                                        break;

                                    case aiMetadataType.AI_UINT64:
                                        value = entry.GetUInt64();
                                        break;

                                    case aiMetadataType.AI_FLOAT:
                                        value = entry.GetFloat();
                                        break;

                                    case aiMetadataType.AI_DOUBLE:
                                        value = entry.GetDouble();
                                        break;

                                    case aiMetadataType.AI_AISTRING:
                                        value = entry.GetString().C_Str();
                                        break;

                                    case aiMetadataType.AI_AIVECTOR3D:
                                        value = Assimp.Convert.AssimpToUnity.Vector3(entry.GetVector3D());
                                        break;
                                    }

                                    storage.Add(key.C_Str(), value);
                                }
                            }
                        }

                        metadata = new UnityComponent
                        {
                            type = typeof(Metadata)
                        };

                        metadata.CreateBackend();

                        AssimpMetadataSerializationContext context = new AssimpMetadataSerializationContext(metadata.type, storage);

                        ((BackendBinarySerializable)metadata.backend).serialized = Module.Import.Binary.serializer.Serialize(context.Callback);
                    }
                }
                else
                {
                    Debug.LogError("The number of metadata keys and values does not match.");
                }
            }

            return(metadata);
        }
Exemplo n.º 2
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(aiMetadataEntry obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }