Importing X3d files into three.js - three.js

is there a way to import X3d files into three.js?
Maybe convert the X3d file into something that three.js can read? Like OBJ or STL?
Thanks for the help!

X3DOM
There is no X3D loader for three.js at the moment, but you could use X3DOM instead if you have to use that file format.
Otherwise, you'd have to write your own loader or convert to another format as you suspected.
Convert X3D to OBJ
However you could use the command-line tool AOPT mentioned in the X3DOM issue to make a webservice, then you could make ajax queries to the webservice to use it in client-side javascript.
aopt -i filename.x3db -e filename.obj
Otherwise X3DOM being open source, so you could dig into its code and try to extract only the parts that deal with parsing the file, and write an OBJ file accordingly, but that would require good knowledge of the X3D and OBJ formats, and solid javascript knowledge. You could skip the first part by having a 1-pixel canvas with X3DOM to feed it the files to parse though.

Related

Modification 3D file to the website

I use WebGL.
Is there a way to modify a .obj file (or another 3D file) for example on photoshop? When I do some change on such a file, I would like it to keep the changes I made when I load it on a website.
I know it is not possible with .obj, so is there another format to do this?
I think you can load some 3d files into photoshop these days, but I'm pretty sure you will not be able to modify them.
To modify .obj files you can use 3d software such as 3DS Max or Maya, or you could use an online tools such as the three.js editor or claria.io
There are probably various ways to achieve what you want.
If I understood you correctly, you actually have multiple questions, here are some answers:
Which 3D editing software could I use?
If you want to perform some modification with a powerful 3D modeling tool, I would recommend to download and try blender. It is completely free, but in fact a very advanced 3D modeling software.
In case you just want to smooth your mesh, simplify it, or apply some other generic operation like this, then MeshLab might be sufficient (also available for free).
Which 3D model format should I use for delivering my 3D asset on the Web?
If you use X3DOM for displaying your 3D file, you can use the standardized X3D format (like OBJ, X3D content can be imported / exported in both, blender and meshlab). This has the advantage that you can use X3DOM's inline tag and directly import an X3D file, which means you can edit the 3D content without needing to re-convert your data for the Web.
However, using OBJ, X3D or whatever text-based delivery format might not be the wisest choice if your 3D asset is large, since this will introduce long download times. Therefore, if you have complex assets / scenes, you should also consider to convert your 3D assets to a compact, optimized delivery format for the Web, such as glTF or SRC.

How to load a gltf model to Three.js?

I decided to try out gltf format for rendering models in Three.js and I'm using this converter (http://cesiumjs.org/convertmodel.html) to convert the model from Collada to GlTF. It spits out a *.gltf file, however in the examples in Three.js they pass a *.json file. How can I load the *.gltf file or how can I get the proper set of files to load? Thanks
You can use THREE.glTFLoader which can be found in the examples/js/loaders directory.
For a demo, see http://threejs.org/examples/webgl_loader_gltf.html.
three.js r.95
The gltf file is a valid json file as far as I understand it.
I opened a file converted from collada to gltf and it is just plain json.
I put it also through the validator at JSONLint.
I would suggest to change the file ending from .gltf to .json .

How can you embed multiple SVG images in a print layout using a scripted procedure?

I currently have a script that produces a large amount of 3.5-inch-square SVG images. What I need is to be able to put these SVGs in a layout which can be easily and accurately printed.
I have tried using an HTML template, but HTML/CSS does not have sufficiently robust printing support.
What document layout language is most appropriate for handling SVG images, and how could this be implemented in a scripting language?
I use Ruby to generate my SVGs, and although preferable, it is not required that Ruby also be the language used to generate the print layout.
I'd suggest compiling all SVGs to a larger SVG, placing everything where you want it, and convert that to PDF using one of multiple options:
Using Inkscape on the command line, like
inkscape -f in.svg -A out.pdf
Using Batik
java -jar batik-rasterizer.jar -m application/pdf -d out.pdf in.svg
Using librsvg, like
rsvg-convert -f pdf -o out.pdf in.svg
(Probably the most lightweight option)
You might also be able to use the rsvg2 Ruby gem with a Cairo PDF surface. Documentation seems scarce or scattered, though.
If you have a budget, Prince is what you want. Since you've already tried to use CSS+HTML to get it working, you may have a working solution almost ready. Just generate the HTML, SVG, and CSS (use the CSS3 paged media extensions for best control), then pass it off to Prince to generate the PDF. I've used this for several projects, and it works great.
There are free options that work like Prince, notably wkhtmltopdf, but they might not respect your paging options as much as Prince.
Otherwise, you might be able to hack something together using Cairo, by creating a page-sized SVG image and laying it out, adding links to the multiple external SVG files.
Either of these options will end up generating a PDF, which is the only way to ensure that it will print the same no matter which browser or OS is being used.

Do you know some Ruby api to manipulate EPS files?

I am making a web app using Rails 3 to make some drawing, but I need to make EPS files.
Do you know some gem or api to create EPS (Encapsulated PostScript) images?
I am not close to use another image format, maybe SVG (Scalable Vector Graphics) could be an alternative, but my requirement was using EPS's.
Thank you!
Don't know how complicated your drawings are. I could well imagine you can just do it with erb, and some helper methods. See example files at http://people.sc.fsu.edu/~jburkardt/data/eps/eps.html (open eps files in text editor)

XML file format for describing animation movements?

Is there an XML file format for describing animation movements?
Is SVG what is currently used? I want to describe 3d information for movements in a format that I can then use in Papervision.
Maybe you can take a look at SMIL which is a XML language for multimedia presentations containing timing, transitions, animations which can be combined with SVG. It's recommended by W3C.
If you're interested in 3d animations then you should consider X3D which is an XML language for 3d which also contains animations. It's developed by webd3d
But I don't know about usage in papervision.
For X3D take a look at X3Dom
http://x3dom.org
http://github.com/x3dom/x3dom

Resources