Update 3D Scene Programmatically to be Showed in Blend4Web WebPlayer (JSON) - json

I created a blender project, exported it as JSON+BIN files and showed it through the blend4web webplayer. Everything goes fine until my need to change the JSON file programmatically to add/remove a new 3D object (e.g. a cube or rectangle). I want to renderize the already showed 3D model adding or removing a 3D object. However, since the exportation of a project to blend4web generate a .bin file, if I change only the .json the model was not showed as expected. Considering this scenario, the unique way to change the model is modifing the .blend file and exports it again from Blender. But based on my need, I can't add a new 3D object in a Blender project programmatically considering the .json file. Additionally, the .json file which I am updating/using is considering data retrieved from a Database, such data indicates how and the position where the new 3D object will be displayed in the scene, which hinder me to use Blender to create a 3D Model modificated.
In this perspective, I need help to identify:
Which is the best way to change the scene and show it in blend4web programmatically and mainly considering a .json as an input for the model?
Is there any python script to user a blend4web .json file as an input to be compiled, without the Blender project and regenerate the .bin file, making it possible to show correctly my 3D model using the blend4web webplayer for JSON files?
Or, is there some (easy) way to modify a project from Blender considering data in JSON format, compile and generate the files to be shown programmatically by the blend4web webplayer (for JSON)?
Thanks in advance.

Related

Get a .tmx file from its .json

I've been using Tiled to create .tmx maps for one of my projects, maps that I export to JSON before using with Phaser.js.
Problem is, a few months ago I mistakenly deleted the .tmx file for the game first map. It's still working fine but now I can't change anything on the first map layout with Tiled because I only have the JSON for it.
I've been looking for an answer with no success so far, but is there a way to convert a .json Tiled map exported from a .tmx file, back to its original format ?
You should be able to simply open the JSON exported map in Tiled, and save it again as a TMX file. To be able to select the file, you may need to change the file type in the Open File dialog.
Btw, you should consider committing your project to a version control system (Git is a popular one), so that such mistakes will not generally lead to loss of data. You don't always get lucky.

How do you export a .OBJ file on blender WITHOUT mtl?

I am making a 3d game with Java LWJGL. I use .obj files to load the models into my game but i dont make it read a separate .mtl file because it is really hard and im struggling to do it. So im trying to make the obj files in blender then exporting it as an obj. BUT there is an extra file which pops up called "player.mtl" and when i try to read just the obj format file my game cant process it :(
This has been on my mind for a long time.
Go to File > Export > Wavefront (.obj).
In the Export OBJ menu in the lower left uncheck Write Materials.
Choose a file name and press Export OBJ.
Now you have only the obj without the mtl file.

exporting options for fbx objects created in Blender and used in libgdx

This is the options panel for FBX export in Blender. I have no animations, just an UV unwrapped object ready for export. What checkboxes should be checked to correctly export objects for libGDX use to FBX file format.
If you're not exporting all the objects in your Scene, checking "Selected objects" will only export those that you have selected.
For certain shaders, "Tangent Space" is also needed for UV exporting, if your materials look okay after import without tangent space included, you probably don't need it. But, it does increase file size.
If the mesh is not skinned, you can uncheck "Add leaf Bones".
You'll get a better idea of everything that is exported if you convert your fbx to .g3dj rather than .g3db. .g3dj is a JSON file, which you can open in a text editor and check everything out, and/or edit if need be. Play around with the settings in the exporter, convert, and see what you get!

3D solid file layers to three.js json

First of all: I'm a skilled developer and a total noob of 3D solid files/drawing.
I started playing with webgl and three.js. My task is to port a solid 3D file(i.e. STEP/IGES) to a web page(a sort of a cad viewer).
I started from this example:
http://www.johannes-raida.de/jnetcad/RadialEngine.htm
I want to obtain something like the above link with
a navigation tree and hide/show layers functionality.
The above link has sever json file, one for layer.
I want to obtain: a threejs-json file for each layer to get the hide/show functionality.
Now, I have a solid file (STEP format: .STP). That file contains layers. I want to obtain a json(three.js) file for each layer.
Questions are:
how to export to threejs-json using free software? I read that the best method could be: STEP > Wavefront OBJ [using freecad?] > treejs-json [using blender?]
Does the collada format is better than obj?
Shoud I have to manually export each single layer to json?
Is there an utility out there to generate all the layers(separated files)(json-threejs format) from a 3d file?
So, I did it by myself.
Three.js is a great library but it requires some 3d skills.
Here are my answers:
how to export to threejs-json using free software?
Well, my suggestion is to convert your solid file to DAE, use anything you want.
Then open DAE with Blender and use the exporter script of three.js:
https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender
Shoud I have to manually export each single layer to json?
No, the 3D file has all the informations about layers. So you can use a single file.
Is there an utility out there to generate all the layers?
I don't have found somethig good out there.
If you want to create single layers, you can split the json file created with blender.

Three.js (r64) - Blender JSON export miss normals for smooth shading

Using Three.js r64 I'd like to import from Blender an animated object with its smoothing groups, the file is exported as JSON through Three.js Blender exporter.
The animation part is working fine.
In Blender, the model looks fine (there is a small smoothing group around the central part).
Picture: http://www.defresne.fr/demo/so/three/smooth_shading/gears.png
I can achive to get the same result when exporting in OBJ with 'Smooth Groups' and 'Include Normals' options checked. However I can't get it working correctly while exporting a JSON file (with normals). Next are pictures of the scene, with a live demo.
Picture: (append next link with) three_gears.png
Live demo: http://www.defresne.fr/demo/so/three/smooth_shading/
I did intense lookup all over the web and couldn't find correct informations. Best is another question on SO which is a bit old (r55) and never got any accepted answer.
I did try to compute the object's normals with
geometry.computeFaceNormals();
geometry.computeVertexNormals();
but, obviously, it computes the whole object normals and result in a completly smoothed object.
So, what should be a correct approach to make JSON smoothing groups work in three.js ? Wait for a built-in function ? build it myself ? Modify the exporter ?
As three.js seems to load correctly OBJ and Collada models with smoothing groups, maybe I could borrow some of the code in these loaders to get the logic ?
Thanks for your help
[EDIT]
I just found something great !
In Blender, produce 2 exports of the model: first a JSON file, second an OBJ file. Load the second one with three.js online editor then convert it to get the geometry JSON...
I can collect the vertices, normals and faces of this freshly exported geometry and copy it to the first exported file.
It works fine ! I got nice shading groups. Even skinning works fine.
But it's a tedious way of processing and I wish I could save myself some extra conversions.
So does that mean there is a problem while exporting geometry from Blender ? Any idea why ?
Any help would be greatly appreciated !
Ok, I finally found what happens.
The r64 Three.js Blender exporter doesn't export smoothing groups so if you need to preserve these, there is no other solution than export the geometry to an OBJ file, then convert it with the python script 'convert_obj_three.py' avaible within Three.js repository. Converted file will have correct normals. (don't forget to check normal option while exporting the OBJ file)