Feature Request: 3D PDF Exporting to Asymptote format.

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
jruiz
Posts: 480
Joined: Tue Oct 28, 2014 1:07 pm
Contact:

Feature Request: 3D PDF Exporting to Asymptote format.

Post by jruiz »

Hi.
Just wondering if it could be feasible (no to hard to do) to add to FreeCAD the feature of exporting projects to Asymptote (.asy) format.
After that, with LaTeX, it could be get an interactive .pdf file showing the project.
Regards.



The following was written after part of the discussion have been developed:
Last edited by jruiz on Fri Sep 25, 2020 3:22 pm, edited 3 times in total.
I have uploaded many FreeCAD video tutorials to my YouTube channel
User avatar
jruiz
Posts: 480
Joined: Tue Oct 28, 2014 1:07 pm
Contact:

Re: Feature Request: 3D PDF Exporting to Asymptote format.

Post by jruiz »

For people not knowing Asymptote programming here there is a link to a video tutorial showing a way of getting an interactive pdf-3d file from Asymptote code into LaTeX code.
Getting interactive pdf-3d files from Asymptote and LaTeX
Regards.
I have uploaded many FreeCAD video tutorials to my YouTube channel
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Feature Request: 3D PDF Exporting to Asymptote format.

Post by wmayer »

There is a different way to create 3D PDF files. The MeshLab project already supports this for many years and from this workflow we have adopted the step to create IDTF meshes.

The workflow is:
  1. Create a IDTF mesh
  2. Convert the IDTF file into u3d format. You get the utility from here: https://github.com/ningfei/u3d
  3. LaTeX has a package to read in u3d files
Another way is to use the PRC format. There is a library libPRC (that uses libharu and parts of asymptote) that can be used to directly create 3D PDF files without using a LaTeX installation.

Here I have implemented a little utility that creates a 3D PDF from a BMS mesh file (it's the internal mesh format of FreeCAD).
https://github.com/wwmayer/Pdf3D

In order to build this application you must clone this repository and make sure to also checkout the sub-modules. Then build it with:

Code: Select all

mkdir build
cd build
cmake ..
make
Then use it like this:

Code: Select all

./mshtopdf input.bms -o output.pdf
This version doesn't support any materials but only raw mesh data. The libPRC library offers a tool to create a pdf from an OSG scene graph. So, maybe it might be an option for the future to implement a tool to create a pdf from an OpenInventor scene.
User avatar
jruiz
Posts: 480
Joined: Tue Oct 28, 2014 1:07 pm
Contact:

Re: Feature Request: 3D PDF Exporting to Asymptote format.

Post by jruiz »

wmayer wrote: Mon Aug 24, 2020 1:22 pm There is a different way to create 3D PDF files. The MeshLab project already supports this for many years and from this workflow we have adopted the step to create IDTF meshes.

The workflow is:
  1. Create a IDTF mesh
  2. Convert the IDTF file into u3d format. You get the utility from here: https://github.com/ningfei/u3d
  3. LaTeX has a package to read in u3d files
Thanks a lot.
Some weeks ago I uploaded a video tutorial explaining this workflow. :D
A way of getting interactive pdf-3d (1/2) (From FreeCAD, MeshLab and LaTeX)
wmayer wrote: Mon Aug 24, 2020 1:22 pm
Another way is to use the PRC format. There is a library libPRC (that uses libharu and parts of asymptote) that can be used to directly create 3D PDF files without using a LaTeX installation.

Here I have implemented a little utility that creates a 3D PDF from a BMS mesh file (it's the internal mesh format of FreeCAD).
https://github.com/wwmayer/Pdf3D

In order to build this application you must clone this repository and make sure to also checkout the sub-modules. Then build it with:

Code: Select all

mkdir build
cd build
cmake ..
make
Then use it like this:

Code: Select all

./mshtopdf input.bms -o output.pdf
This version doesn't support any materials but only raw mesh data. The libPRC library offers a tool to create a pdf from an OSG scene graph. So, maybe it might be an option for the future to implement a tool to create a pdf from an OpenInventor scene.
Thank you very much again.
Gonna take a look at this method.
In this way can we manage color and lights/shadows of the models?
By the way. Do you know about any free (free as in freedom) viewer with which these pdf-3d can be opened for interacting with them?
Regards.
I have uploaded many FreeCAD video tutorials to my YouTube channel
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Feature Request: 3D PDF Exporting to Asymptote format.

Post by wmayer »

jruiz wrote: Mon Aug 24, 2020 11:48 pm In this way can we manage color and lights/shadows of the models?
Not with the bms format because it doesn't support materials, lights or colors. However, as said if we implement a converter to export a OpenInventor scene using libPRC it will be possible. Coin3d offers the class SoVectorizeAction and in a sub-class the virtual methods can be re-implemented exporting to the prc format.

Here is the code to convert an osg scene (OpenSceneGraph) to the prc format: https://github.com/XenonofArcticus/libP ... /osgdb_prc
By the way. Do you know about any free (free as in freedom) viewer with which these pdf-3d can be opened for interacting with them?
No, the only application I know of that supports 3D PDF is the Acrobat Reader.

Btw, in the linked video above you talked about the Asymptote Vector graphic language. I had a quick look at it but couldn't figure out how one would export 3D data. Do you know how to do this or do you have a simple example?
If it's not too difficult it's still an option to export to the .asy format as this way we don't need a 3rd party library.
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Feature Request: 3D PDF Exporting to Asymptote format.

Post by wmayer »

A related thread which discusses a few more options can be found here: https://forum.freecadweb.org/viewtopic.php?f=24&t=20224
User avatar
jruiz
Posts: 480
Joined: Tue Oct 28, 2014 1:07 pm
Contact:

Re: Feature Request: 3D PDF Exporting to Asymptote format.

Post by jruiz »

wmayer wrote: Tue Aug 25, 2020 9:05 am Btw, in the linked video above you talked about the Asymptote Vector graphic language. I had a quick look at it but couldn't figure out how one would export 3D data.
I am not very sure of understanding you question.
In Asymptote: The Vector Graphics Language some details are explained.

Once an Asymptote code is compiled a pdf is generated.
wmayer wrote: Tue Aug 25, 2020 9:05 am Do you know how to do this or do you have a simple example?
Again, not sure about this question:
-in Asymptote page there are examples of codes.
I have uploaded many FreeCAD video tutorials to my YouTube channel
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Feature Request: 3D PDF Exporting to Asymptote format.

Post by wmayer »

jruiz wrote: Mon Aug 24, 2020 11:48 pm In this way can we manage color and lights/shadows of the models?
Yesterday I tried a pdf file which was created from a bms file and when opening it inside the Acrobat reader there are a lot of options to set lighting, shadows, wireframe, points, ... display modes and a few things more.
jruiz wrote: Mon Aug 24, 2020 11:48 pm By the way. Do you know about any free (free as in freedom) viewer with which these pdf-3d can be opened for interacting with them?
It's not a free (only freeware with the option to buy a license) and only runs on Windows but is an alternative to the Acrobat reader: PDF-XChange Editor / Editor Plus
On their website they claim they support 3D but I couldn't get it working to display the exported mesh.
Again, not sure about this question:
-in Asymptote page there are examples of codes.
There are many examples but I couldn't find one where a 3D mesh (with materials) will be created.
jaisejames
Posts: 384
Joined: Sat Sep 24, 2016 6:51 am

Re: Feature Request: 3D PDF Exporting to Asymptote format.

Post by jaisejames »

wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Feature Request: 3D PDF Exporting to Asymptote format.

Post by wmayer »

Many thanks for the link.

I had to install a very old Blender version in order to get the script being accepted.

Here is the output of a mesh cube:

Code: Select all

/*
 * Asymptote export of Untitled, SCE:Scene
 * produced using asymptote_export.py 1.1
 * by Scott Pakin, scott.blend@pakin.org
 */

import three;

size(500);

// CA:Camera, OB:Camera
currentprojection = perspective(camera = (7.4811, -6.5076, 5.3437),
                                target = (-58.005, 54.559, -39.181),
                                autoadjust = false,
                                showtarget = false,
                                up = (-0.31737, 0.31247, 0.89534));

// LA:Spot, OB:Lamp
// WO:World
currentlight = light(diffuse = rgb(1, 1, 1),
                     specular = rgb(1, 1, 1),
                     background = rgb(0.078281, 0.16041, 0.25),
                     0.56639, 0.21839, 0.79467);

// ME:Cube, OB:Cube
draw(surface((-1, -1, -1)--(-1, -1, 1)--(-1, 1, 1)--(-1, 1, -1)--cycle),
     rgb(0.8, 0.8, 0.8));
draw(surface((1, 1, 1)--(1, 1, -1)--(-1, 1, -1)--(-1, 1, 1)--cycle),
     rgb(0.8, 0.8, 0.8));
draw(surface((1, 1, -1)--(1, -1, -1)--(-1, -1, -1)--(-1, 1, -1)--cycle),
     rgb(0.8, 0.8, 0.8));
draw(surface((1, 1, 1)--(-1, 1, 1)--(-1, -1, 1)--(1, -1, 1)--cycle),
     rgb(0.8, 0.8, 0.8));
draw(surface((1, 1, -1)--(1, 1, 1)--(1, -1, 1)--(1, -1, -1)--cycle),
     rgb(0.8, 0.8, 0.8));
draw(surface((1, -1, -1)--(1, -1, 1)--(-1, -1, 1)--(-1, -1, -1)--cycle),
     rgb(0.8, 0.8, 0.8));

Post Reply