VidyaBharati Posted September 22, 2016 Share Posted September 22, 2016 Hello, I want to crop 3d model (.obj) and place another 3d model (.obj) there. I have tried it with CSG but it works for only standard 3d model and i want to do it with custom models. Can someone help me out? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 22, 2016 Share Posted September 22, 2016 Hey this should work from any kind of mesh: https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.csg.ts#L285 Quote Link to comment Share on other sites More sharing options...
VidyaBharati Posted September 23, 2016 Author Share Posted September 23, 2016 Thanks deltakosh, I tried it. its converting my mesh to CSG but the operations (union, subtract) not showing any result. I have placed one obj on loading of scene and on drag event of second obj, placing it on first but instead subtracting or union its just getting placed on that position. can you give me any example of operations on custom mesh? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 23, 2016 Share Posted September 23, 2016 The thing is I see no difference (from CSG POV) between a box or a custom mesh. Everything is custom mesh Do you mind sharing a sample repro on the Playground? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted September 24, 2016 Share Posted September 24, 2016 Hi guys, and welcome, @VidyaBharati! I have a CSG playground (modified from CSG demo in docs) that might make the task easier. http://playground.babylonjs.com/#UUXLX#21 Vidya... CSG is... different. This playground attempts to help understand it... using good variable names and some comments. One of the objectives of this PG demo... was to show all CSG result mesh, AND the source mesh used to create them. If I remember correctly, this took some work. None of the mesh in this playground scene... are set updatable = true, and I don't know if THAT parameter is important - when working with CSG. Maybe. Maybe not. Perhaps none of the original mesh... needed to be updated. (It has been a long time since I played with this demo. I forgot everything I learned about it.) Good luck with your two .obj-importing, and CSG playground demo. Start with publishing your .obj files (and .mtl files?) in a public place (possibly your free github acct), and get the two objects displayed in a playground scene, yeah? http://playground.babylonjs.com/#3TDZD#0 That's a decent .obj loading playground. When using the playground, objectLoader.js extension is already included. Yay! After you get your (simple?) .objects loaded and displaying, then we will attack them with CSG... and see what trouble we can cause. Sound good? Got playground search, docs search, and forum search links bookmarked? Obj-loading and CSG... here we come! Quote Link to comment Share on other sites More sharing options...
VidyaBharati Posted September 26, 2016 Author Share Posted September 26, 2016 Hello All, when scene loads I am loading my first obj as house and converting each mesh into CSG. myHouse = loader.addMeshTask("myHouse", "", "objHouse/", "generic-houses-1.obj"); myHouse.onSuccess = function(c) { c.loadedMeshes.forEach(function(b) { b.position.x = 0; b.position.y = 0; b.position.z = 0; b.checkCollisions = true; if(b.name == "Roof") roofCSG = BABYLON.CSG.FromMesh(b); else if(b.name == "Floor") floorCSG = BABYLON.CSG.FromMesh(b); else if(b.name == "Walls") wallsCSG = BABYLON.CSG.FromMesh(b); }); }; loader.onFinish = function() { engine.runRenderLoop(function () { scene.render(); }); }; loader.load(); and on drag and canvas drop event i am dropping door on wall and want to crop it and place door there. canvas drop event code : ...... var loader1 = new BABYLON.AssetsManager(scene); var pickResult = scene.pick(evt.offsetX, evt.offsetY); if(pickResult.hit) { myDoor = loader1.addMeshTask("myDoor", "", "objDoor/", "door.obj"); myDoor.onSuccess = function(c) { c.loadedMeshes.forEach(function(b) { doorCSG = BABYLON.CSG.FromMesh(b); b.position.x = pickResult.pickedPoint.x; b.position.z = pickResult.pickedPoint.z; b.position.y = pickResult.pickedPoint.y; }); }; loader1.onFinish = function() { engine.runRenderLoop(function () { scene.render(); }); mergeObj(); }; ..... ///Function mergeObj() .... var myObjx = wallsCSG.operationOfCSG(doorCSG); var newMesh = myObjx.toMesh("csg", scene); newMesh.position = new BABYLON.Vector3(12, 50, 50); .... i tried with operationOfCSG ( like subtract, union, unionInPlace etc ) but its only getting placed on that position rather than cropping it. Also var newMesh = myObjx.toMesh("csg", new BABYLON.StandardMaterial("mat", scene), scene, true); this is giving an invalid arguments error. Please help... Quote Link to comment Share on other sites More sharing options...
VidyaBharati Posted September 27, 2016 Author Share Posted September 27, 2016 I tried the same with box also its giving me an invalid arguments issue for the following toMesh() function... var newMesh = myObjx.toMesh("csg", new BABYLON.StandardMaterial("mat", scene), scene, true); i am not getting where i am wrong.....please help me out. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 28, 2016 Share Posted September 28, 2016 Please provide a playground to repro this issue Quote Link to comment Share on other sites More sharing options...
VidyaBharati Posted September 28, 2016 Author Share Posted September 28, 2016 Hi, Please check this simple example with box. http://playground.babylonjs.com/#1JWV0M At our end its giving an Type error : invalid arguments for box as well as obj also Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 28, 2016 Share Posted September 28, 2016 Yes but this PG works I need a PG that illustrates your issue Quote Link to comment Share on other sites More sharing options...
VidyaBharati Posted September 28, 2016 Author Share Posted September 28, 2016 I am using the same code. I am not getting what is issue but I am using following CSG file https://github.com/CraigFeldspar/BabylonCSG and babylon.js. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 28, 2016 Share Posted September 28, 2016 I understand but please help us helping you. Please reproduce the bug with your files in the playground. (by the way are you using bjs 2.5 locally?) Quote Link to comment Share on other sites More sharing options...
VidyaBharati Posted September 29, 2016 Author Share Posted September 29, 2016 Hi, I am checking why its giving an error at my end. For now i got to know that In babylon.js in the following code s.prototype.createVertexBuffer = function(e) { var t = this._gl.createBuffer(); return this.bindArrayBuffer(t), e instanceof Float32Array ? this._gl.bufferData(this._gl.ARRAY_BUFFER, e, this._gl.STATIC_DRAW) : this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(e), this._gl.STATIC_DRAW), this._resetVertexBufferBinding(), t.references = 1, t } this return statement giving an error. you can see the attached file also. 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.