Exporting VRML from Blender

I have lots of old VRML files. I’d love it if I could resurrect them and get browsers to show them. I’ve tried loading the VRML files directly into three.js with fairly unsatifactory results. Then I found that I can import the VRML files into Blender, with much more reasonable results. So I got to wondering – what if I was exporting VRML from Blender? Would that VRML go any better with three.js than VRML that was written by 3DSmax back in the ’90’s?

Using the file I was working with for my mesh modeling and lighting courses while I was learning Blender, I gave it a try. And what came out was interesting, but somewhat encouraging:

Drag your mouse across that ^, to spin it around.

There’s something very odd about the way that is rendering. After a few seconds of staring at it, I realized that it’s showing the BACK of every face in the models. How inconvenient. And odd looking. But, using what I’ve learned about Blender so far, not so difficult to fix. Just get every face selected and “flip the normals.” (“Flip the normals” – such a loaded phrase…)

That looks somewhat better – at least they look solid, rather than ghostly, inside-out and haunted. I tried any number of “materials” for these – but the only things that came through in the .wrl files were the actual geometries. The camera and light for these, as well as the orbit control, is in the three.js – none of that is exported with the VRML exporter. Neither, it would appear, are any properties of the materials.

What was in the code was this:

Shape {
 appearance Appearance {
  material Material {
  }
 }
...



Ooo, VRML. Rather than continue to try to egg Blender into exporting something in a material, I just fired some values in via my text editor, the old-fashioned way:

Shape {
 appearance Appearance {
  material Material {
   ambientIntensity 0.35
   ambientColor 0.2 0.67 0.00
   diffuseColor 0.05 0.2 0.00
   specularColor 0.21 0.60 0.26
   shininess 0.05
   }
  }
...

and after tweaking my colours to suit my tastes, wound up with this: (drag your mouse across it to spin it)

Which is kinda cool. It is the models I made in Blender, and it is rendering in real time, using nothing but a bit of javascript and OpenGL. Though, it certainly does look crude in this context, compared to how it looked when I gave it whole minutes to render from a single perspective.

I’ve learned two things from this experiment – that the three.js VRMLLoader prefers VRML that was exported by Blender in 2016 to VRML that was exported by 3DSmax in 1998 – and that exporting to VRML and then loading the VRML with three.js is a pretty limited (and Goldbergian) way to get Blender stuff onto a web page.

 

 

Tweet about this on TwitterShare on Google+Share on LinkedInShare on FacebookEmail this to someone

Author: Pete

Editor-in-Chief, Lead Software Developer and Artistic Director @ 3dspace.com