/* End IDatasmithSpotLightElement functions*/ /**********************************************/ /* Begin IDatasmithAreaLightElement functions*/ static LightShapeStyle GetLightShape(Asset asset) { AssetPropertyEnum lightShapeType = asset.FindByName("lightobjectareatype") as AssetPropertyEnum; if (lightShapeType != null) { return((LightShapeStyle)lightShapeType.Value); } return(LightShapeStyle.Point); }
static LightDistributionStyle GetLightDistribution(Asset asset) { AssetPropertyEnum lightDistribution = asset.FindByName("distribution") as AssetPropertyEnum; if (lightDistribution != null) { return((LightDistributionStyle)lightDistribution.Value); } return(LightDistributionStyle.Spherical); }
/* End IDatasmithLightActorElement functions */ /**********************************************/ /* Begin IDatasmithPointLightElement functions*/ //This function should return a enum but the corresponding enum haven't been found yet. static int GetInstensityUnits(Asset asset) { AssetPropertyEnum intensityUnits = asset.FindByName("intensityUnits") as AssetPropertyEnum; //Datamsith light units : Unitless, Candelas, Lumens if (intensityUnits != null) { return(intensityUnits.Value); } return(-1); }
private static Tuple <Type, Object> GetTypeAndValue(AssetProperty assetProperty, int level) { Object theValue; Type valueType; //For each AssetProperty, it has different type and value //must deal with it separately try { if (assetProperty is AssetPropertyBoolean) { AssetPropertyBoolean property = assetProperty as AssetPropertyBoolean; valueType = typeof(AssetPropertyBoolean); theValue = property.Value; } else if (assetProperty is AssetPropertyDistance) { AssetPropertyDistance property = assetProperty as AssetPropertyDistance; valueType = typeof(AssetPropertyDistance); theValue = property.Value; } else if (assetProperty is AssetPropertyDouble) { AssetPropertyDouble property = assetProperty as AssetPropertyDouble; valueType = typeof(AssetPropertyDouble); theValue = property.Value; } else if (assetProperty is AssetPropertyDoubleArray2d) { //Default, it is supported by PropertyGrid to display Double [] //Try to convert DoubleArray to Double [] AssetPropertyDoubleArray2d property = assetProperty as AssetPropertyDoubleArray2d; valueType = typeof(AssetPropertyDoubleArray2d); theValue = GetSystemArrayAsString(property.Value); } else if (assetProperty is AssetPropertyDoubleArray3d) { AssetPropertyDoubleArray3d property = assetProperty as AssetPropertyDoubleArray3d; valueType = typeof(AssetPropertyDoubleArray3d); //theValue = GetSystemArrayAsString( property.Value ); // 2017 theValue = Util.DoubleArrayString(property.GetValueAsDoubles()); // 2018 } else if (assetProperty is AssetPropertyDoubleArray4d) { AssetPropertyDoubleArray4d property = assetProperty as AssetPropertyDoubleArray4d; valueType = typeof(AssetPropertyDoubleArray4d); //theValue = GetSystemArrayAsString( property.Value ); // 2017 theValue = Util.DoubleArrayString(property.GetValueAsDoubles()); // 2018 } else if (assetProperty is AssetPropertyDoubleMatrix44) { AssetPropertyDoubleMatrix44 property = assetProperty as AssetPropertyDoubleMatrix44; valueType = typeof(AssetPropertyDoubleMatrix44); theValue = GetSystemArrayAsString(property.Value); } else if (assetProperty is AssetPropertyEnum) { AssetPropertyEnum property = assetProperty as AssetPropertyEnum; valueType = typeof(AssetPropertyEnum); theValue = property.Value; } else if (assetProperty is AssetPropertyFloat) { AssetPropertyFloat property = assetProperty as AssetPropertyFloat; valueType = typeof(AssetPropertyFloat); theValue = property.Value; } else if (assetProperty is AssetPropertyInteger) { AssetPropertyInteger property = assetProperty as AssetPropertyInteger; valueType = typeof(AssetPropertyInteger); theValue = property.Value; } else if (assetProperty is AssetPropertyReference) { AssetPropertyReference property = assetProperty as AssetPropertyReference; valueType = typeof(AssetPropertyReference); theValue = "REFERENCE"; //property.Type; } else if (assetProperty is AssetPropertyString) { AssetPropertyString property = assetProperty as AssetPropertyString; valueType = typeof(AssetPropertyString); theValue = property.Value; } else if (assetProperty is AssetPropertyTime) { AssetPropertyTime property = assetProperty as AssetPropertyTime; valueType = typeof(AssetPropertyTime); theValue = property.Value; } else { valueType = typeof(String); theValue = "Unprocessed asset type: " + assetProperty.GetType().Name; } if (assetProperty.NumberOfConnectedProperties > 0) { String result = ""; result = theValue.ToString(); TaskDialog.Show("Connected properties found", assetProperty.Name + ": " + assetProperty.NumberOfConnectedProperties); IList <AssetProperty> properties = assetProperty.GetAllConnectedProperties(); foreach (AssetProperty property in properties) { if (property is Asset) { // Nested? Asset asset = property as Asset; int size = asset.Size; for (int i = 0; i < size; i++) { //AssetProperty subproperty = asset[i]; // 2018 AssetProperty subproperty = asset.Get(i); // 2019 Tuple <Type, Object> valueAndType = GetTypeAndValue(subproperty, level + 1); String indent = ""; if (level > 0) { for (int iLevel = 1; iLevel <= level; iLevel++) { indent += " "; } } result += "\n " + indent + "- connected: name: " + subproperty.Name + " | type: " + valueAndType.Item1.Name + " | value: " + valueAndType.Item2.ToString(); } } } theValue = result; } } catch { return(null); } return(new Tuple <Type, Object>(valueType, theValue)); }
/// <summary> /// Gets the current value of the property on a component. /// </summary> /// <param name="component">The component with the property for which to retrieve the value.</param> /// <returns>The value of a property for a given component.</returns> public override object GetValue(object component) { //For each AssetProperty, it has different type and value //must deal with it separately try { if (m_assetProperty is AssetPropertyBoolean) { AssetPropertyBoolean property = m_assetProperty as AssetPropertyBoolean; m_valueType = typeof(Boolean); m_value = property.Value; } else if (m_assetProperty is AssetPropertyDistance) { AssetPropertyDistance property = m_assetProperty as AssetPropertyDistance; m_valueType = typeof(Double); m_value = property.Value; } else if (m_assetProperty is AssetPropertyDouble) { AssetPropertyDouble property = m_assetProperty as AssetPropertyDouble; m_valueType = typeof(Double); m_value = property.Value; } else if (m_assetProperty is AssetPropertyDoubleArray2d) { //Default, it is supported by PropertyGrid to display Double [] //Try to convert DoubleArray to Double [] AssetPropertyDoubleArray2d property = m_assetProperty as AssetPropertyDoubleArray2d; m_valueType = typeof(Double[]); m_value = GetSystemArray(property.Value); } else if (m_assetProperty is AssetPropertyDoubleArray3d) { AssetPropertyDoubleArray3d property = m_assetProperty as AssetPropertyDoubleArray3d; m_valueType = typeof(Double[]); m_value = GetSystemArray(property.Value); } else if (m_assetProperty is AssetPropertyDoubleArray4d) { AssetPropertyDoubleArray4d property = m_assetProperty as AssetPropertyDoubleArray4d; m_valueType = typeof(Double[]); m_value = GetSystemArray(property.Value); } else if (m_assetProperty is AssetPropertyDoubleMatrix44) { AssetPropertyDoubleMatrix44 property = m_assetProperty as AssetPropertyDoubleMatrix44; m_valueType = typeof(Double[]); m_value = GetSystemArray(property.Value); } else if (m_assetProperty is AssetPropertyEnum) { AssetPropertyEnum property = m_assetProperty as AssetPropertyEnum; m_valueType = typeof(int); m_value = property.Value; } else if (m_assetProperty is AssetPropertyFloat) { AssetPropertyFloat property = m_assetProperty as AssetPropertyFloat; m_valueType = typeof(float); m_value = property.Value; } else if (m_assetProperty is AssetPropertyInteger) { AssetPropertyInteger property = m_assetProperty as AssetPropertyInteger; m_valueType = typeof(int); m_value = property.Value; } else if (m_assetProperty is AssetPropertyReference) { AssetPropertyReference property = m_assetProperty as AssetPropertyReference; m_valueType = typeof(String); m_value = property.Type; } else if (m_assetProperty is AssetPropertyString) { AssetPropertyString property = m_assetProperty as AssetPropertyString; m_valueType = typeof(String); m_value = property.Value; } else if (m_assetProperty is AssetPropertyTime) { AssetPropertyTime property = m_assetProperty as AssetPropertyTime; m_valueType = typeof(DateTime); m_value = property.Value; } else { return(null); } } catch { return(null); } return(m_value); }
private void LogMaterial(AssetProperty asset, StringBuilder log, string t = null) { if (asset == null) { return; } log.Append(t + "Asset.Type:" + asset.Type.ToString() + "::" + asset.Name + "="); switch (asset.Type) { case AssetPropertyType.APT_Asset: Asset a = asset as Asset; log.Append("Asset,Size:" + a.Size + "\n"); for (int i = 0; i < a.Size; i++) { LogMaterial(a[i], log, t + "\t"); } break; case AssetPropertyType.APT_Boolean: AssetPropertyBoolean ab = asset as AssetPropertyBoolean; log.Append(ab.Value + "\n"); break; case AssetPropertyType.APT_Distance: AssetPropertyDistance ad = asset as AssetPropertyDistance; log.Append(ad.Value + "\n"); break; case AssetPropertyType.APT_Double: AssetPropertyDouble ado = asset as AssetPropertyDouble; log.Append(ado.Value + "\n"); break; case AssetPropertyType.APT_Double44: break; case AssetPropertyType.APT_DoubleArray2d: AssetPropertyDoubleArray2d ado2 = asset as AssetPropertyDoubleArray2d; log.Append(ado2.Value.get_Item(0) + "," + ado2.Value.get_Item(1) + "\n"); break; case AssetPropertyType.APT_DoubleArray3d: AssetPropertyDoubleArray3d ado3 = asset as AssetPropertyDoubleArray3d; log.Append(ado3.Value.get_Item(0) + "," + ado3.Value.get_Item(1) + "," + ado3.Value.get_Item(2) + "\n"); break; case AssetPropertyType.APT_DoubleArray4d: AssetPropertyDoubleArray4d ado4 = asset as AssetPropertyDoubleArray4d; log.Append(ado4.Value.get_Item(0) + "," + ado4.Value.get_Item(1) + "," + ado4.Value.get_Item(2) + "," + ado4.Value.get_Item(3) + "\n"); break; case AssetPropertyType.APT_Enum: AssetPropertyEnum ae = asset as AssetPropertyEnum; log.Append(ae.Value + "\n"); break; case AssetPropertyType.APT_Float: AssetPropertyFloat af = asset as AssetPropertyFloat; log.Append(af.Value + "\n"); break; case AssetPropertyType.APT_FloatArray: IList <float> lf = (asset as AssetPropertyFloatArray).GetValue(); foreach (float f in lf) { log.Append(f + ","); } log.Append("\n"); break; case AssetPropertyType.APT_Int64: AssetPropertyInt64 ai6 = asset as AssetPropertyInt64; log.Append(ai6.Value + "\n"); break; case AssetPropertyType.APT_Integer: AssetPropertyInteger ai = asset as AssetPropertyInteger; log.Append(ai.Value + "\n"); break; case AssetPropertyType.APT_List: break; case AssetPropertyType.APT_Properties: AssetProperties ap = asset as AssetProperties; log.Append("AssetProperties,Count:" + ap.Size + "\n"); for (int i = 0; i < ap.Size; i++) { LogMaterial(ap[i], log, t + "\t"); } break; case AssetPropertyType.APT_Reference: break; case AssetPropertyType.APT_String: AssetPropertyString _as = asset as AssetPropertyString; log.Append(_as.Value + "\n"); break; case AssetPropertyType.APT_Time: AssetPropertyTime at = asset as AssetPropertyTime; log.Append(at.Value + "\n"); break; case AssetPropertyType.APT_UInt64: AssetPropertyUInt64 aiu6 = asset as AssetPropertyUInt64; log.Append(aiu6.Value + "\n"); break; case AssetPropertyType.APT_Unknown: log.Append("\n"); break; default: log.Append("\n"); break; } foreach (Asset _a in asset.GetAllConnectedProperties()) { log.Append(t + "GetAllConnectedProperties:\n"); LogMaterial(_a, log, t + "\t"); } }