Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import PRC file or 3D PDF into FreeCAD #6090

Open
FreeCAD-Bug-Importer opened this issue Feb 7, 2022 · 1 comment
Open

import PRC file or 3D PDF into FreeCAD #6090

FreeCAD-Bug-Importer opened this issue Feb 7, 2022 · 1 comment
Labels
Mod: Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD Type: Feature FR for improvements or new features

Comments

@FreeCAD-Bug-Importer
Copy link
Collaborator

Issue imported from https://tracker.freecad.org/view.php?id=4403

  • Reporter: ferdymercury
  • Date submitted: 7/8/2020
  • FreeCAD version:
  • Category: Feature
  • Status: new
  • Tags: conversion, file format, import, STEP

Original report text

This is a follow up the suggestion I made in the forum.

PRC files are commonly used by several vendors to embed 3D models in a PDF file. Unfortunately, these files can only be opened with Adobe PDF reader. For example, Linux does not have a native Adobe viewer, which means it is impossible to view correctly this type of documents. One needs some workarounds (Wine, Virtualbox, or old Adobe versions for Linux).

I thought that in general, not only for Linux users, it would be nice if FreeCAD would be able to import PRC files in the same way it imports STEP files. (Also including nested parts in the tree model).

It is easy to extract the embedded PRC file from the 3D PDF, by just searching for 'stream.PRC' and 'endstream' bytes in a hex editor, so in principle this could be done automatically also by FreeCAD. Everything inbetween is the PRC binary file that can be extracted, and for example included in your own PDF with pdflatex media9 package.

Thinking about a 'far future', if FreeCAD is able to open and import it, this would allow in the future that Linux PDF viewers display inline also 3D models, by embedding a small FreeCAD plugin directly, instead of having to open it in external FreeCAD window. In the same way than Adobe PDF reader has a Flash Player plugin to do that.

To implement this feature, one might reuse some parts of this code: https://github.com/XenonofArcticus/libPRC

The PRC file format is defined here.

Other posts related to generating PRC files from a FreeCAD model:
https://forum.freecadweb.org/viewtopic.php?t=20224&start=10
https://forum.freecadweb.org/viewtopic.php?f=8&t=18497#p144546
(This is the opposite direction than the feature requested here)

Steps to reproduce

  • Download https://tetra4d.com/wp-content/uploads/2015/04/3D-PDF-Sample-Outlet.pdf
  • Open it with Bless hex editor or equivalent
  • Search for PRC keyword (search option Text, not Hex).
  • Select and delete in the hex editor from beginning of document until & including line above, containing keyword 'stream', so that first three bytes of the resulting file are 'PRC'.
  • Search for 'endstream' keyword. Delete from (including) this line until the end of the document.
  • Save result as .prc
  • In a Latex document, you can include it with
\usepackage{media9}
...
\includemedia[
  %label=dice, % name for referencing 3D object
  width=\linewidth,
  height=0.495\linewidth,
  3Dtoolbar,
  3Dmenu
  %activate=pagevisible,
  %3Dcoo=13.514159202575684 -210.37330627441406 265.50933837890625,
  %3Dc2c=-0.6669085025787354 0.39916229248046875 0.6292078495025635,
  %3Droo=9603.325257430366,
  %3Droll=-110.37121928895962,
  %3Dortho=0.001394091872498393,
  %3Dlights=Cube
  ]{}{result.prc}
  • Compile with pdflatex, and open it with Adobe PDF Reader

(Side note: if a 3D PDF file has several 3D models embedded, this has to be done in a for loop. Or the user has to select in the import dialog one among those)

%
%

FreeCAD Info

OS: Linux Mint 19.3 (MATE/mate)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.21775 (Git) AppImage
Build type: Release
Branch: master
Hash: 1f741aa511e898849e46ed14515fce416fe32acb
Python version: 3.8.2
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United States (en_US)

Other bug information

  • Priority: normal
  • Severity: feature
  • Category: Feature
  • Updated: 2/6/2021

Discussion from Mantis ticket

Comment by ferdymercury 2020-07-08 14:13

The following link is more updated than the one from libPRC I posted before.
https://github.com/vectorgraphics/asymptote/tree/50fb809fdaf2383385f09884174262964a046156/prc

One could expand the code in asymptote repository and write the functions in the opposite direction (Deserialize, Read) instead of (Serialize, Write). So that Asymptote library could be used as an 'intermediary'. Then, one would 'only' need to convert Asymptote structure to FreeCAD structure.

See also:
https://forum.freecadweb.org/viewtopic.php?t=156


Comment by wmayer 2020-12-10 16:49

https://forum.freecadweb.org/viewtopic.php?f=8&t=53116


Comment by ferdymercury 2020-12-10 16:54

See also: vectorgraphics/asymptote#167

@FreeCAD-Bug-Importer FreeCAD-Bug-Importer added Mod: Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD Type: Feature FR for improvements or new features labels Feb 7, 2022
@ferdymercury
Copy link

See also XenonofArcticus/libPRC#2 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mod: Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD Type: Feature FR for improvements or new features
Projects
None yet
Development

No branches or pull requests

2 participants