3DNGuy Posted November 19, 2013 Share Posted November 19, 2013 Hey, i'm in the process of learning three.js. I am currently trying to merge two meshes together to to build a movable lego brick. I'm working inside the three.js editor Mr Doob created and using the brick.js module mattmatchell did. Below is some sample code of what i'm working with. I have tried many iterations of merging the component pieces and adding them to the scene but i'm just missing something. Any hints on how to set this up? If you need more info i'll be happy to add to this. Just need a nudge over this bump. Thanks for the help! BRICK.square=function(colorCode, w, d, h){w = w || 1;h = h || 3;d = d || 1;THREE.Object3D.call( this );var faceMaterial = new THREE.MeshLambertMaterial({color: BRICK.color(colorCode).face}); var mesh=new THREE.Mesh(new THREE.CubeGeometry(20*w,8*h,20*d), faceMaterial);mesh.position.y=(8*h)/2;mesh.matrixAutoUpdate = true;mesh.updateMatrix();this.add(mesh);for(var i=1; i<=w; i++){for(var j=1; j<=d; j++){var stud=new THREE.Mesh(new THREE.CylinderGeometry(6,6, 4, 32, 4), faceMaterial);stud.position.y=(8*h)+2;stud.position.x=(i*20)-((w*20)/2)-10;stud.position.z=(j*20)-((d*20)/2)-10;stud.matrixAutoUpdate = false;stud.updateMatrix();this.add(stud);}}} Quote Link to comment Share on other sites More sharing options...
Psychho Posted November 21, 2013 Share Posted November 21, 2013 Use the THREE.GeometryUtils.merge function, also simply searching 'threejs merge' on google gives this tutorial on merging http://learningthreejs.com/blog/2011/10/05/performance-merging-geometry/ Did you even try searching before posting here? Quote Link to comment Share on other sites More sharing options...
3DNGuy Posted November 22, 2013 Author Share Posted November 22, 2013 Yeah a number nights of searching Still having problems. Thanks though Quote Link to comment Share on other sites More sharing options...
Psychho Posted November 24, 2013 Share Posted November 24, 2013 Yeah a number nights of searching Still having problems. Thanks thoughWell what problems are you having? All you said in your post was that you are trying to merge two objects together. Quote Link to comment Share on other sites More sharing options...
Qazzian Posted March 22, 2017 Share Posted March 22, 2017 I know this is old but It's one of the top hits on google for merging geometries. As there wasn't an answer here I started messing around with the above code in a code pen. Open up the JS and try changing the brick sizes and the color. Mouse controls will move the scene around. Spankied 1 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.