Load three js model into forge viewer - autodesk-forge

I try to load a three.js file (Json from rvt) into the offline version of the forge viewer. How I can do this?
Thank you!

Forge viewer is based on three.js. It is similar to adding mesh to the scene in native three.js context. The below are one demo extension.
https://github.com/Autodesk-Forge/library-javascript-viewer-extensions/tree/0c0db2d6426f4ff4aea1042813ed10da17c63554/src/Autodesk.ADN.Viewing.Extension.MeshImporter
In this demo, the json file (Arbor Press.json) is from Inventor. It contains the definition of the geometry and material. The code of the extension will parse the json, and create mesh in the scene of Forge Viewer.
You might also need to take a look at the other extension for examples of changing material colors:
https://github.com/Autodesk-Forge/library-javascript-viewer-extensions/blob/0c0db2d6426f4ff4aea1042813ed10da17c63554/src/Autodesk.ADN.Viewing.Extension.Material/Autodesk.ADN.Viewing.Extension.Material.js
However please be aware your meshes will not be detected by the viewer selection logic, some extra work would be needed if you want that.

Related

Converting dwg file into gltf with color

I have an Autocad dwg file that i want to convert into gltf. I have used autodesk forge as well as autodesk forge tools in VS Code to get gltf. Both the tools are able to convert into gltf but the problem is there is no color in the gltf, it is just black and white.
Is there some way to get color in the gltf file or obj file?
The mapping of colors from Forge models to glTF in forge-convert-utils is pretty basic at the moment but it should be able to get at least some basic diffuse color. Try this:
open the gltf file, find the list of materials, and see what colors you see in baseColorFactor properties; if the values are [0,0,0,0], the problem is in the conversion
if you see non-zero values there, perhaps there's a problem with lighting up the model in your viewing application; for example, when loading a glTF model into a three.js app, you must add at least an ambient light otherwise the model will remain black
If you're still having issues, please consider sharing your DWG (confidentially) with us via forge (dot) help (at) autodesk (dot) com, and we'll debug it locally.
EDIT: As discussed in https://github.com/petrbroz/vscode-forge-tools/issues/16, the issue was a lack of support for meshes with vertex colors in the converter library. As of forge-convert-utils version 3.4.0, and vscode-forge-tools version 1.5.1, vertex colors in Forge models are now properly translated into glTF vertex colors.

Missing elements in autodesk forge

I'm playing around with coordinates in autodesk forge and by some chance i noticed that some of the element(door in my case) doesn't have an fragment id. I've tried to use selection and fittoview to try and display which is the problematic element and to my surprise the element doesnt even exist in the viewer (I still managed to use getProperties to show all the properties though).
Is this because of some bug occurred during the conversion from revit to forge or is it because of an error in my programming?
It seems to be expected that small objects get lost in Revit export processes, cf.:
Model objects missing in custom exporter context
Small objects missing in DWG export
How large is your missing door? How large is the model?

How can I export a .dwg file from the Forge Viewer that also includes MarkupsCore markups?

I'm working on a javascript application that uses the MarkupsCore extension to create markups on a floor plan in the Autodesk Forge Viewer. I want to export a .dwg file from the viewer, but I also want the file to contain those markups. I basically know how to export the .dwg file, but I don't know how to combine the svg markups with the file before exporting. Is this even possible? If so, how?
The markups as stored/saved as SVG files, which is a XML-based format to describe geometry. And I believe you know that :-) I did a quick search and found a few articles about SVG to DXF conversion, where DXF can be imported and converted into DWG via AutoCAD engine (or Design Automation API).
So a route would be: show DWG model, add markups, save as SVG, convert to DXF, convert again to DWG, merge into original DWG. I don't have such a sample nor can guarantee it will work and be accurate, sorry.

Forge viewer: Custom materials step-by-step

I've seen some examples of high quality and detailed models that works for the Autodesk Model Derivative. Some example are Dotty, Dasher and Fusion Race Car. Dotty is actually amazing.. even has some reflection added in there.
So, to achieve this I would need to upload the textures and the materials with my model. I've tried to reproduce the guide telling me to create a ZIP containing of the OBJ, MTL and PNG. First of all, to be sure I am on the correct path when I am testing out different workflows: is OBJ the only format that can be uploaded with custom materials/textures? I know that I can add standard materials to rvt, fbx, 3ds etc, but I do not have a clear idea on how to upload custom materials/textures.
Could you kindly give me a step-by-step how to get the best possible visualization of the uploaded models? Thanks a lot
Models from Fusion 360 uses the built-in material library, in the case of Fusion Race Car you mentioned. The Dasher sample uses a Revit model of a "well-designed" model in Revit, but no custom materials. Don't have much info on the Dotty format, but would consider the direction of obj or rcp (Reality Capture or point cloud) files, both can have texture.
For a custom material, OBJ is the best route as of now, allowing you to include your textures. As far as Forge, the translation is exactly the same: upload the zip with all files and post a job with rootFilename pointing to the .obj file.

Nodal color information are lost for collada 3D files (*.dae)

I have a collada (.dae) 3D file with nodal colour for contouring. But these information are lost while uploading to autodesk viewer api. I have attached the file for reference.
https://1drv.ms/u/s!ApS9nIpyJIuQbJulgP5rcm1b-ic
Is there any other way to show contour in viewer api ? Please help.
Yes, unfortunately, the DAE, Obj, FBX pipelines only translation geometry. Material & Textures won't get through. We are working on a process to handle this as well as supporting glTF. The is no solution to workaround this limitation at this time.