Jump to content

How to crop a 3d Model (.obj) and place another 3d model(.obj)


VidyaBharati
 Share

Recommended Posts

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?

 

Link to comment
Share on other sites

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! 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

issue.png

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...