WebGL export

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
cmundi
Posts: 28
Joined: Thu Apr 17, 2014 5:03 am

Re: WebGL export

Post by cmundi »

I just exported a hacked up object as WebGL. :) I'm almost out of excuses not to learn WebGL. Nice!
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: WebGL export

Post by bernd »

yorik wrote:It's pretty simple, really... Select some geometry, then file->export->webgl.
Just have been playing with this for the first time. It's a great feature very useable. Found only moving (hold right mouse button) and turning (hold left mousebutton). Is there any zoom too?

EDIT: Just found it the middle button :shock: :o :oops:
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: WebGL export

Post by yorik »

Actually the webgl exporter uses a "template", a webgl viewer I found (Actually IIRC Dan Falck found), and simply inserts the FreeCAD geometry inside. Everything is in Arch/importWebGL.py. Other templates could easily be used instead if you want a different viewer.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: WebGL export

Post by bernd »

yorik wrote:Actually the webgl exporter uses a "template", a webgl viewer I found (Actually IIRC Dan Falck found), and simply inserts the FreeCAD geometry inside. Everything is in Arch/importWebGL.py. Other templates could easily be used instead if you want a different viewer.
Ahh thanks for information. I need to play with this a bit. All my modells where exported not usable in Browser. Found they are all in mm (ifcimport). If they are im m or cm the webglexport works great :)
User avatar
rockn
Veteran
Posts: 1791
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: WebGL export

Post by rockn »

It work well in mm for me.
http://wood3dservices.fr/webgl/Pergola.html
But I have two important things to do to have this nice export.
I must place the model so as to have the total reference mark in the center of the structure.
And I must modify the postion of the camera in html file like that :

Code: Select all

camera.position.set( 0.0, -8000.0, 500.0 );
The camera position in three.js is very complicated to understand. :oops:
Formations - Assistance - Développement : https://freecad-france.com
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: WebGL export

Post by bernd »

rockn wrote:It work well in mm for me.
http://wood3dservices.fr/webgl/Pergola.html
Ahh, that looks cool.
rockn wrote:I must place the model so as to have the total reference mark in the center of the structure.
What is the total reference mark ? A point defined in importWebGL.py, or the origin of global coordinate system (0,0,0), or some other point?
User avatar
rockn
Veteran
Posts: 1791
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: WebGL export

Post by rockn »

Oups, wrong translation. "The reference mark" is the origin of global coordinate system (0,0,0) in the FreeCAD model.
Formations - Assistance - Développement : https://freecad-france.com
User avatar
rockn
Veteran
Posts: 1791
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: WebGL export

Post by rockn »

Hello,
Do you think it's possible to have html template out of the source code ? Could be cool to edit it easily and why not have more than one template.
Second : In the template I can't force the camera position. How can I force the camera postion before I make the export ?

See how I export my structure in a macro :

Code: Select all

if f3dformat == 'html':
		copyPergo = Draft.move([poteaux,poutres, solives,cfichesa,cfichesb,cfichesc,cfichesd,piedsPoteaux, wall, muraillere],FreeCAD.Vector(-pergolaLongueur/2, -pergolaLargeur/2, -pergolaHauteur/2), copy = True) # To place all my structure in the center of the FreeCAD model
		importWebGL.export(copyPergo,filePath)
		print("/!\ AJOUTER CECI DANS FICHIER HTML")
		print("camera.position.set( 0.0, -8000.0, 500.0 );")
		print("/!\ ")
		for obj in copyPergo :
			App.ActiveDocument.removeObject(obj.Name)
Formations - Assistance - Développement : https://freecad-france.com
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: WebGL export

Post by jreinhardt »

I second the motion. I want to include a 3D view of the parts in the BOLTS web page, and for this a template without the html boilerplate would be really handy.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: WebGL export

Post by yorik »

In git commit 8f469bf I just added some mechanisms to make that simpler. I didn't put the template outside of the file, because then we would need additional GUI stuff to choose the template, etc... But it is now easy to use and change the template from a python script, like this:

Code: Select all

import importWebGL
mytemplatefile = open( "/home/yorik/mytemplate.html" )
mytemplate = mytemplatefile.read()
mytemplatefile.close()
importWebGL.template = mytemplate
importWebGL.export( FreeCADGui.Selection.getSelection(), "/home/yorik/test.html" )
You can get the default template simply with:

Code: Select all

import importWebGL
print importWebGL.template
You can also change the export style (do it before calling the export() function):

Code: Select all

importWebGL.wireframeStyle = "faceloop"
"faceloop" is the default, but you can also use "multimaterial" or None
Post Reply