Three.js r120 was just released with the first version of a 3DMLoader which uses the rhino3dm.js library. The three.js editor also supports loading rhino 3dm files.
The first version was focused on getting all of the mechanics of loading rhino3dm.js in place and converting some important types like BREPs, Meshes, Extrusions, Points, Point Clouds, Curves, Dots, and Lights. Blocks are also supported, but do not take advantage of instancing (yet). There is also basic material support.
In the next version there should be support for more complete materials, textures, and a revision of the object conversion.
The easiest way to try this is to point your browser at the three.js editor and go to File->Import and select a Rhino file. If the Rhino file has no lights, I recommend you add a Directional Light in the three.js editor (Add->Directional Light).
@fraguada This is awesome!
I have a question, if I end up having ārhino3dm.jsā and ārhino3dm.wasmā in a repo, while not using npm, is there a way to know which version of those files I have?
However - I would recommend to change the demo a little bit: The points of the point cloud / control points appear as (ugly) black squares. It would most likely look better if those were displayed as little spheres instead (and not black, but maybe yellow, blue, red, grey for example).
Is there some documentation or can you point me to the code where I can find what types of curves should already supported?
EDIT @Luis I fount this code , but Iām not sure if I an make sense of it.
Further test makes it appear as if the curves are not rendered.
I exploded 1 curve as a test, and that does show up, bot I found that some curve object are selectable but not visible. Maybe due to the 100 point limit?
Unfortunately it has 500 vertices! Weāll have to work a bit to clean this up to avoid so many points. Iāll commit this to our fork and set up a PR to the three.js repo sometime this week.
Thanks for the update!
So am I correct to deduce from looking at the code that any curve is converted to a polyline?
In that case I might -for now- create polylines myself to control the conversion.
Anyway Iām following with great interest and hope our developer will have soon time to implement this.
for some reason, I am not getting the Breps. Any thoughts?
I simply made 3 files, one with a standard box (extrusion), one where I transformed the box into a mesh, and one with one polysurface and one surface inside.
The 3dmLoader relies on the render meshes of breps and extrusions. If you created a brep box in Rhino but never displayed it in a shaded mode, it wonāt have a render mesh.
I was trying to create the files too fast, so I actually have not switched to the shaded mode. I have another important question. If I add Custom User Data to my Rhino Objects, could I get that data somehow to three.js over the 3dmloader? If it is possible, would I have to expand/customize the 3dmloader? And if yes, where would that code go?
@mkarimi What else would be useful to capture? The warning says most of what we know: the object type is an Extrusion, and that there is no mesh associated with it. This means it was either created in Rhino, but never got a render mesh, or it was created by some other scripted method which didnāt bother to generate a render mesh. This warning is thrown here: three.js/3DMLoader.js at dev Ā· mrdoob/three.js Ā· GitHub
I understand that @fraguada . I think the warning message are clear too. I was just proposing to add an onWarn() function to 3DMLoader.parse() to make retrieving these warnings easier. .parse ( buffer : ArrayBuffer, onLoad : Function, onProgress : Function, onError : Function , onWarn : Function)
The reason Iām asking this is that I like to show these warnings on the UI and without such a utility I have to hijack the console.warn() to retrieve these warnings.
Hi @fraguada I am getting the error you mention due to missing render meshesā¦
THREE.3DMLoader: ObjectType_Brep has no associated mesh geometry.
Here is the salient code for how the breps are createdā¦
public static Brep[] StepToBrep(byte[] file)
{
// import the step file to a new 3dm document
FileIO.SaveByteArrayToTempFile(file, stpName);
RhinoDoc doc = RhinoDoc.CreateHeadless(null);
doc.Import(FileIO.GetTempFilePath(stpName));
// extract breps
var rhinoObjs = doc.Objects.FindByObjectType(ObjectType.Brep);
var breps = new List<Brep>();
foreach (var item in rhinoObjs)
{
var brep = (Brep)item.Geometry;
brep.EnsurePrivateCopy(); // decouples the brep from the document object which otherwise can cause it to fail to serialize to json
brep.Compact();
breps.Add(brep);
}
// return breps
return breps.ToArray();
}
Do you know if it is possible to obtain render meshes for them given this code is running in a Compute instance?