GUI/Types/Exporter/GltfModelExporter.cs
/// <summary>
/// Export a Valve VMDL to GLTF.
/// </summary>
/// <param name="resourceName">The name of the resource being exported.</param>
/// <param name="fileName">Target file name.</param>
/// <param name="model">The model resource to export.</param>
Export a Valve VMDL to GLTF.
Export a Valve VMDL to GLTF .
public void ExportToFile(string resourceName, string fileName, VModel model)
        {
            var exportedModel = ModelRoot.CreateModel();
            exportedModel.Asset.Generator = GENERATOR;
            var scene = exportedModel.UseScene(Path.GetFileName(resourceName));
            var embeddedMeshIndex = 0;
            void AddMeshNode(string name, VMesh mesh)
            {
                var exportedMesh = CreateGltfMesh(name, mesh, exportedModel, true);
                var modelSkeleton = model.GetSkeleton();
                if (modelSkeleton.AnimationTextureSize > 0)
                {
                    var skeleton = scene.CreateNode(name);
                    var joints = CreateGltfSkeleton(modelSkeleton, skeleton);
                    scene.CreateNode(name)
                        .WithSkinnedMesh(exportedMesh, Matrix4x4.Identity, joints);
                    skeleton.WorldMatrix = TRANSFORMSOURCETOGLTF;
                }
                else
                {
                    var meshNode = scene.CreateNode(name)
                        .WithMesh(exportedMesh);
                    meshNode.WorldMatrix = TRANSFORMSOURCETOGLTF;
                }
            }
            foreach (var mesh in model.GetEmbeddedMeshes())
            {
                var name = $"Embedded Mesh {++embeddedMeshIndex}";
                AddMeshNode(name, mesh);
            }
            foreach (var meshReference in model.GetReferencedMeshNames())
            {
                var meshResource = GuiContext.LoadFileByAnyMeansNecessary(meshReference + "_c");
                if (meshResource == null)
                {
                    continue;
                }
                var nodeName = Path.GetFileNameWithoutExtension(meshReference);
                var mesh = new VMesh(meshResource);
                AddMeshNode(nodeName, mesh);
            }
            exportedModel.Save(fileName);
        }
public void ExportToFile ( string resourceName , string fileName , VModel model ) { var exportedModel = ModelRoot . CreateModel ( ) ; exportedModel . Asset . Generator = GENERATOR ; var scene = exportedModel . UseScene ( Path . GetFileName ( resourceName ) ) ; var embeddedMeshIndex = 0 ; void AddMeshNode ( string name , VMesh mesh ) { var exportedMesh = CreateGltfMesh ( name , mesh , exportedModel , true ) ; var modelSkeleton = model . GetSkeleton ( ) ; if ( modelSkeleton . AnimationTextureSize > 0 ) { var skeleton = scene . CreateNode ( name ) ; var joints = CreateGltfSkeleton ( modelSkeleton , skeleton ) ; scene . CreateNode ( name ) . WithSkinnedMesh ( exportedMesh , Matrix4x4 . Identity , joints ) ; skeleton . WorldMatrix = TRANSFORMSOURCETOGLTF ; } else { var meshNode = scene . CreateNode ( name ) . WithMesh ( exportedMesh ) ; meshNode . WorldMatrix = TRANSFORMSOURCETOGLTF ; } } foreach ( var mesh in model . GetEmbeddedMeshes ( ) ) { var name = $" Embedded Mesh  { ++ embeddedMeshIndex } " ; AddMeshNode ( name , mesh ) ; } foreach ( var meshReference in model . GetReferencedMeshNames ( ) ) { var meshResource = GuiContext . LoadFileByAnyMeansNecessary ( meshReference + " " ) ; if ( meshResource == null ) { continue ; } var nodeName = Path . GetFileNameWithoutExtension ( meshReference ) ; var mesh = new VMesh ( meshResource ) ; AddMeshNode ( nodeName , mesh ) ; } exportedModel . Save ( fileName ) ; }
Export a Valve VMDL to GLTF.
Export a Valve VMDL to GLTF .
// Add skeleton and skin // Rotate upright, scale inches to meters. // Rotate upright, scale inches to meters. // Add embedded meshes // Add external meshes
resourceName
string
The name of the resource being exported.
The name of the resource being exported .
fileName
string
Target file name.
Target file name .
model
VModel
The model resource to export.
The model resource to export .