Xav Posted April 24, 2017 Share Posted April 24, 2017 Hi, I am trying to find out if it is possible to adapt this 'sphere.applyDisplacementMap ("/ assets / amiga.jpg", 0, 1.5);' of this example https://www.babylonjs.com/demos/displacementmap/ on an object create in blender with the adapted uvs. To make it simple I would like to be able to change the shape of my object with a heightmap. I do not need to animate it. I do not find a track to create this effect so I ask the question as to whether it is really possible. Thank you Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 24, 2017 Share Posted April 24, 2017 Hey, unless I do not understand your point, what you describe is clearly the goal of the displacementMap can you tell me what you want to do which is not supported by the current API? Quote Link to comment Share on other sites More sharing options...
Xav Posted April 25, 2017 Author Share Posted April 25, 2017 Ok sorry, An exemple on picture exemple.jpg. It works very well with: var sphere = BABYLON.Mesh.CreateSphere("Sphere", 32, 3, scene, true); sphere.applyDisplacementMap("Assets/test.jpg", 0, .2); When i want to apply this on an obj create in blender it no longer works... Is my question clearer? Thanks Quote Link to comment Share on other sites More sharing options...
Xav Posted April 25, 2017 Author Share Posted April 25, 2017 I continued my research on this subject. The problem would not it come that my mesh is not Updatable? As specified In the doc: "The mesh must be set as updatable. Its internal geometry is directly modified, no new buffer are allocated." I found this post : Is it possible to make a mesh updatable if it was created in an external softaware, to modify its mesh with a Heigth map? Thanks Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 25, 2017 Share Posted April 25, 2017 It should work Do you mind creating a playground repro? It's gonna be easier to fix it then Quote Link to comment Share on other sites More sharing options...
Xav Posted April 26, 2017 Author Share Posted April 26, 2017 Hello, Like this: http://www.babylonjs-playground.com/index.html#WS3Z9A Thanks. Quote Link to comment Share on other sites More sharing options...
Xav Posted April 27, 2017 Author Share Posted April 27, 2017 Hello, I found the solution: var obj = scene.getMeshByName("piece001"); var positions = obj.getVerticesData(BABYLON.VertexBuffer.PositionKind); var vb = obj.getVertexBuffer(BABYLON.VertexBuffer.PositionKind); vb._buffer._updatable = true; obj.applyDisplacementMap("test/test.jpg", 0, 10 , function() { obj.updateVerticesData(vb); console.log("OK!"); }); Babylon.js is PERFECT :)!!!! I think is now possible to export this mesh to an .obj file with the updatable shape ? Thanks. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Xav Posted April 27, 2017 Author Share Posted April 27, 2017 Is possible to rotate and translate the displacement map inside the obj.applyDisplacementMap() ? thanks Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 27, 2017 Share Posted April 27, 2017 Hi Xav, good to see you again. I know of ONE way... perhaps the WRONG way... https://www.babylonjs-playground.com/#P9UZG#12 In the BJS framework, applyDisplacementMap uses a helper func called applyDisplacementMapFromBuffer. BOTH have been "hijacked" into that playground... but... ...it is likely hijacked from OLD version of BJS. You might wish to get fresher versions from here. Take a look at lines 31-43 (a save/restore wrapping, there, worth studying someday). But most important... rotation, translation, and scaling of the IMAGE used-for the displaceMap... can be done there. Not sure about continuously-updating the context2d image, in a renderloop. I think a bit of custom code could do it. Hope this helps. Others will comment soon, I'm sure. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 27, 2017 Share Posted April 27, 2017 Thanks:) you can export to .obj with this: https://github.com/BabylonJS/Babylon.js/blob/master/dist/preview release/serializers/babylon.objSerializer.js Quote Link to comment Share on other sites More sharing options...
Xav Posted April 28, 2017 Author Share Posted April 28, 2017 Hello Thanks Wingnut I had actually started looking at this. I will continue to develop this idea in parallel and obviously if I get something convincing I would share it ;). Thanks Deltakosh actually I saw this especially that there is a post on this subject that runs on the forum: http: //www.html5gamedevs.com/topic/29587-babylon-objects-to-obj-file/ Again thank you for the time you give us to answer. Babylon.js is really a great tool very polyvalent Thank you for everything ! Quote Link to comment Share on other sites More sharing options...
Xav Posted June 28, 2017 Author Share Posted June 28, 2017 Hello, I found time to explore this idea a bit more. Sorry but I can not get the script to export a mesh to .obj extension for the playground. This works perfectly on my local machine. https://www.babylonjs-playground.com/#P9UZG#14 My question is how to save everything in a file mesh.obj and mesh.mtl? If possible locally at the moment. If anyone has an idea or a track to do that. Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.