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!
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: Thu Aug 27, 2020 3:13 pm Here is the content of a simple cube where the six sides have different colors:

Code: Select all

/*
 * Created by FreeCAD <http://www.freecadweb.org>
 */

import three;

size(500);

// CA:Camera, OB:Camera
currentprojection = orthographic(camera = (15, 5, 5),
                                 target = (5, 5, 5),
                                 showtarget = false,
                                 up = (0, 0, 1));

// ME:Mesh, OB:Mesh
draw(surface((0, 10, 0)--(0, 0, 10)--(0, 10, 10)--cycle),
     rgb(1, 0.666667, 0));
draw(surface((0, 0, 0)--(0, 0, 10)--(0, 10, 0)--cycle),
     rgb(1, 0.666667, 0));
draw(surface((10, 0, 10)--(10, 10, 0)--(10, 10, 10)--cycle),
     rgb(0, 0, 1));
draw(surface((10, 0, 10)--(10, 0, 0)--(10, 10, 0)--cycle),
     rgb(0, 0, 1));
draw(surface((10, 0, 0)--(10, 0, 10)--(0, 0, 0)--cycle),
     rgb(0, 1, 0));
draw(surface((0, 0, 0)--(10, 0, 10)--(0, 0, 10)--cycle),
     rgb(0, 1, 0));
draw(surface((10, 10, 10)--(10, 10, 0)--(0, 10, 0)--cycle),
     rgb(0, 0.666667, 1));
draw(surface((10, 10, 10)--(0, 10, 0)--(0, 10, 10)--cycle),
     rgb(0, 0.666667, 1));
draw(surface((0, 10, 0)--(10, 10, 0)--(0, 0, 0)--cycle),
     rgb(0.333333, 0.666667, 0));
draw(surface((0, 0, 0)--(10, 10, 0)--(10, 0, 0)--cycle),
     rgb(0.333333, 0.666667, 0));
draw(surface((10, 10, 10)--(0, 10, 10)--(0, 0, 10)--cycle),
     rgb(1, 0, 0));
draw(surface((10, 10, 10)--(0, 0, 10)--(10, 0, 10)--cycle),
     rgb(1, 0, 0));
Save it as cube.asy.

To render the content: asy -V cube.asy
To create a PDF file: asy -f pdf cube.asy -o cube.pdf
Asymptote code can be included easily into a LaTeX document for generating (for example) a pdf file. If interested, see attachment, and read it with Acrobat Reader.
LaTeX Code, nameOfLaTeXFile.tex:

Code: Select all

\documentclass[a4paper,10pt]{article}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}
\usepackage{asymptote}

%opening
\title{Including Asymptote code into a \LaTeX{} document}
\author{ An author}

\begin{document}

\maketitle

\begin{abstract}
An abstract
\end{abstract}

\section{A section}
This is a section. Here an Asymptote code is included.
\begin{figure}[h!]
    \centering
    \begin{asy}
//Asymtote code can be written here directily or you can include an Asymptote file:
     include "nameOfAsymptoteFile.asy";
    \end{asy}
    \caption{FreeCAD figure exported as Asymptote code}
    \label{fig:aLabel}
\end{figure}
\section{Compiling \LaTeX{} document with an Asymptote code}
For obtaining a \textit{pdf} file from this \LaTeX{} document, compile in this way:
\begin{enumerate}
 \item \textit{\$ pdflatex nameOfLaTexFile}
 \item \label{it:compilingAsymptoteFile}\textit{\$ asy  nameOfLaTexFile-1.asy}
 \item \textit{\$ pdflatex nameOfLaTexFile}
\end{enumerate}
So, nameOfLaTexFile.pdf file will be generated. If more than one Asymptote code is included into the \LaTeX{} code, the item \ref{it:compilingAsymptoteFile} shoud be replaced by:
\begin{itemize}
 \item \textit{\$ asy nameOfLaTexFile\-*.asy}
\end{itemize}
As for each Asymptote code included in the \LaTeX{} document, an Asymptote code, \textit{nameOfLaTexFile-i.asy, i=1,2$\ldots$} will be generated.

If you want to interact with the pdf-3D, read it with Acrobat Reader $\circledR$
\end{document}
Asymptote code, nameAsymptoteFile.asy::

Code: Select all

/*
 * Created by FreeCAD <http://www.freecadweb.org>
 */

import three;

size(300); // replaced 500 by 300

// CA:Camera, OB:Camera
currentprojection = orthographic(camera = (15, 5, 5),
                                 target = (5, 5, 5),
                                 showtarget = false,
                                 up = (0, 0, 1));

// ME:Mesh, OB:Mesh
draw(surface((0, 10, 0)--(0, 0, 10)--(0, 10, 10)--cycle),
     rgb(1, 0.666667, 0));
draw(surface((0, 0, 0)--(0, 0, 10)--(0, 10, 0)--cycle),
     rgb(1, 0.666667, 0));
draw(surface((10, 0, 10)--(10, 10, 0)--(10, 10, 10)--cycle),
     rgb(0, 0, 1));
draw(surface((10, 0, 10)--(10, 0, 0)--(10, 10, 0)--cycle),
     rgb(0, 0, 1));
draw(surface((10, 0, 0)--(10, 0, 10)--(0, 0, 0)--cycle),
     rgb(0, 1, 0));
draw(surface((0, 0, 0)--(10, 0, 10)--(0, 0, 10)--cycle),
     rgb(0, 1, 0));
draw(surface((10, 10, 10)--(10, 10, 0)--(0, 10, 0)--cycle),
     rgb(0, 0.666667, 1));
draw(surface((10, 10, 10)--(0, 10, 0)--(0, 10, 10)--cycle),
     rgb(0, 0.666667, 1));
draw(surface((0, 10, 0)--(10, 10, 0)--(0, 0, 0)--cycle),
     rgb(0.333333, 0.666667, 0));
draw(surface((0, 0, 0)--(10, 10, 0)--(10, 0, 0)--cycle),
     rgb(0.333333, 0.666667, 0));
draw(surface((10, 10, 10)--(0, 10, 10)--(0, 0, 10)--cycle),
     rgb(1, 0, 0));
draw(surface((10, 10, 10)--(0, 0, 10)--(10, 0, 10)--cycle),
     rgb(1, 0, 0));

Attachments
nameOfLaTeXFile.pdf
(143.2 KiB) Downloaded 58 times
Last edited by jruiz on Fri Aug 28, 2020 11:06 am, edited 1 time in total.
I have uploaded many FreeCAD video tutorials to my YouTube channel
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

Is it supposed to look like this?
Is it supposed to look like this?
asymptote-acrobat.png (57.54 KiB) Viewed 1681 times
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
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 »

Kunda1 wrote: Thu Aug 27, 2020 8:18 pm asymptote-acrobat.png
Yup.
If you open the pdf file with Acrobat Reader, the figure could be rotated, translated, zoomed in, zoomed out.
I have uploaded many FreeCAD video tutorials to my YouTube channel
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

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

Post by chrisb »

This is really a great improvement. Thanks!
It's a pity the other pdf viewers don't support it (e.g. MacOS pdf viewer).
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

chrisb wrote: Thu Aug 27, 2020 9:11 pm This is really a great improvement. Thanks!
It's a pity the other pdf viewers don't support it (e.g. MacOS pdf viewer).
Yea, doesn't look like Okular can support it either :(
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
aapo
Posts: 624
Joined: Mon Oct 29, 2018 6:41 pm

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

Post by aapo »

Hmm, this is great!!! Thanks! :D
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

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

Post by wmayer »

Kunda1 wrote: Thu Aug 27, 2020 10:29 pm
chrisb wrote: Thu Aug 27, 2020 9:11 pm This is really a great improvement. Thanks!
It's a pity the other pdf viewers don't support it (e.g. MacOS pdf viewer).
Yea, doesn't look like Okular can support it either :(
None of the available PDF viewers on Linux support 3D PDF. Most of them use the poppler library which lacks of this feature. Acrobat reader support for Linux has been dropped in around 2014 and it's recommended not to use it because of many security risks.

On Windows besides Acrobat reader there are PDF XChange which claims to support 3D but I couldn't get it to work and apparently the FoxIt Reader: https://www.foxitsoftware.com/de/pdf-editor/addons.php

So, maybe it's possible to run one of the Windows alternatives under WINE.

Btw, asymptote can be used to display a static image for viewers that don't support 3D so that at least you can see something:
https://sourceforge.net/p/asymptote/dis ... /4af338f6/
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

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

Post by easyw-fc »

wmayer wrote: Fri Aug 28, 2020 6:14 am None of the available PDF viewers on Linux support 3D PDF. Most of them use the poppler library which lacks of this feature.
...
Btw, asymptote can be used to display a static image for viewers that don't support 3D so that at least you can see something:
https://sourceforge.net/p/asymptote/dis ... /4af338f6/
Is there any chance to implement this feature on a Linux pdf viewer?
Is there any project on this direction?
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

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

Post by wmayer »

Is there any chance to implement this feature on a Linux pdf viewer?
It's for sure possible.

In the past the u3d format was used and there I don't know if there is any OSS library to read-in this part from a PDF file.
Now the u3d format is declared deprecated and replaced by the PRC format. The asymptote project has a method to read in a PRC file and it needs a bit testing of what can be done with it.

What I don't know is how a PRC file is written into a PDF. A PRC file starts with the three characters 'P', 'R', 'C' but the binary part of a PDF doesn't include these characters, maybe it's additionally compressed with zlib.

For a few years the PRC format is ISO standard but you don't get the specification for free. But maybe the asymptote project has implemented everything what's needed to handle all this.
Is there any project on this direction?
I don't know of any project.
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

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

Post by jmaustpc »

This is a link to where you can download the ECMA standard for U3D from 2007, if that is of any use to any of you.

http://www.ecma-international.org/publi ... dition.pdf

The last time we talked about this, I thought we pretty much came to the conclusion that 3dpdf was a dead format? According to this it is...
https://boxshot.com/3d-pdf/make/

and
https://boxshot.com/3d-pdf/alternatives/

which amongst other details concludes with pretty much, just use HTML/WebGL which most browsers support and will likely continue to support.

I don't know if they are correct but since there only seems to be one viewer that only works on Windows, it looks dead or at least has a doubtful future.
Post Reply