I want to import mesh from a .gtlf/.glb file using hops.
So I tried to go around this issue, by creating a grasshopper component instead of reading a file within a script editor.
The component works perfectly outside of hops with any given format.
With hops it works when importing .obj, .3dm (tested only these), but when I try to import .gltf or .glb it fails to return a mesh. My guess would be that there might be some compatibility issues with the new Rhino 8 .glTF importer.
Please let me know if you have any suggestions on how to resolve this issue.
Import logic:
protected override void SolveInstance(IGH_DataAccess DA)
{
var tmpPath = "";
DA.GetData(0, ref tmpPath);
using( var doc = Rhino.RhinoDoc.CreateHeadless(null)){
doc.Import(tmpPath);
var ros = doc.Objects.FindByObjectType(Rhino.DocObjects.ObjectType.Mesh);
var meshes = new List<Rhino.Geometry.Mesh>();
foreach( Rhino.DocObjects.RhinoObject obj in ros )
{
meshes.Add(obj.DuplicateGeometry() as Rhino.Geometry.Mesh);
}
DA.SetDataList(0, meshes);
}
}
@Joshua_Kennedy I’m having the same exact issue when importing / exporting .glb/.gltf as well. This only happens when I’m exporting a headless RhinoDoc on HOPS / compute.rhino. It works fine in UI mode though.
Hi @Joshua_Kennedy , any news on this topic ?
I am encountering something that seems to be the same while trying to import gltf within Rhino.Testing context.
using (var headlessDoc = RhinoDoc.CreateHeadless(null))
{
var importResult = headlessDoc.Import(in_filepath);
}
importResult will always return false if the gltf file has materials.
While debugging I can tell that the failure happens in GltfRhinoMaterialConverter.Convert, NewContentFromTypeId doesn’t seem to find the PhysicallyBasedMaterialType within the doc context only when running in Rhino.Testing context.
The same code run through a normal Rhino instance works fine and the import succeeds.
Would be great to have a workaround / fix for this since we have to switch to manual testing for this feature instead of having our CI to do the job
I think the import problem is actually this issue. Can you try forcing the RDK_EtoUI plugin to load before you create your headless document? Something like this:
Rhino.PlugIns.PlugIn.LoadPlugIn(Guid.Parse("638a0098-0511-482b-95bf-8cf47fd32c17"));
using (var headlessDoc = RhinoDoc.CreateHeadless(null))
{
var importResult = headlessDoc.Import(in_filepath);
}
Sadly, even when loading RDK_EtoUI plugin before creating the doc the renderMaterial creation returns null.
I also tried to manually load the importGLTF plugin for good measure but it doesn’t change a thing.
Sorry about all this. I can reproduce your issue with a headless run of Rhino. I guess it’s not the RDK_EtoUI plugin where the PBR material glTF loads is defined but the Commands plugin. This is not right and I’ll see about getting it sorted. In the meantime I can get a glTF file with materials to import with headless Rhino if I add this line before the using statement
Rhino.PlugIns.PlugIn.LoadPlugIn(Guid.Parse("02bf604d-799c-4cc2-830e-8d72f21b14b7"));
using (var headlessDoc = RhinoDoc.CreateHeadless(null))
{
var importResult = headlessDoc.Import(in_filepath);
}