示例#1
0
        /// <summary>
        /// Returns the C# value from USD or null if there was no value or the value could not be converted.
        /// </summary>
        object GetCSharpValue(UsdAttribute attr, UsdTimeCode time)
        {
            UsdTypeBinding binding;

            if (!UsdIo.Bindings.GetReverseBinding(attr.GetTypeName(), out binding))
            {
                // No binding for this type.
                return(null);
            }
            return(binding.toCsObject(attr.Get(time)));
        }
        /// <summary>
        /// Serializes the attribute value to USD-ASCII and writes it to Debug.Log.
        /// </summary>
        void DebugPrintAttr(Scene srcScene, UsdAttribute attr, UsdTimeCode time)
        {
            // Copy the desired attribute into a temp scene, with nothing other than this one attr.
            var tmpScene = Scene.Create();

            // Up-Axis is unrelated to the attribute, but it makes the generated USDA look more correct,
            // since it will include an up-axis.
            tmpScene.UpAxis = srcScene.UpAxis;

            // Define the owning prim for the attribute.
            var tmpPrim = tmpScene.Stage.DefinePrim(attr.GetPath().GetPrimPath(), attr.GetPrim().GetTypeName());

            // Define the attribute itself.
            var tmpAttr = tmpPrim.CreateAttribute(attr.GetName(), attr.GetTypeName());

            // Gather the default value and the value at the current time.
            var defaultVal = attr.Get(UsdTimeCode.Default());
            var valAtTime  = attr.Get(time);

            // Copy them to the new attribute.
            if (!defaultVal.IsEmpty())
            {
                tmpAttr.Set(defaultVal);
            }

            if (attr.ValueMightBeTimeVarying())
            {
                tmpAttr.Set(valAtTime, time);
            }

            // If this is an array, get the size.
            var arraySize = -1;

            if (valAtTime.IsArrayValued())
            {
                arraySize = (int)valAtTime.GetArraySize();
            }

            // Metadata cannot be time-varying.
            UsdMetadataValueMap metaData = attr.GetAllMetadata();

            foreach (var key in metaData.GetKeys())
            {
                tmpAttr.SetMetadata(key, metaData.GetValue(key));
            }

            // Export the single attribute to a string.
            var stringified = "";

            tmpScene.Stage.ExportToString(out stringified, addSourceFileComment: false);

            // Dispose the tmp scene.
            tmpScene.Close();
            tmpScene = null;

            // Print.
            if (arraySize > -1)
            {
                stringified = "Array Size: " + arraySize + "\n" + stringified;
            }

            Debug.Log("Path: <" + attr.GetPath().ToString() + ">\n" + stringified);
        }