math - How to normal-scale using threejs to make objects 'thicker' or 'thinner' -
i'm trying figure out how extrude loaded .obj object make "thicker". think i'm looking way scale object not anchor point scaling each polygon normal.
a classic example take "ring" object. if scale normal scale methods gets bigger center want ring become thicker/thinner. called 'normal scale' in cinema 4d.
here's example code of have, , isn't giving me expected result.
var objloader = new three.objloader(); var material = new three.meshlambertmaterial({color:'yellow', shading:three.flatshading}); objloader.load('objects/gun/m1911.obj', function (obj) { obj.traverse(function (child) { if (child instanceof three.mesh) { child.geometry.computevertexnormals(); child.material = material; } }); obj.material = material; obj.scale.set(7, 7, 7); scene.add(obj); });
scalegeo: function (geo, ratio) { (var = 0; < geo.faces.length; i++) { var facei = geo.faces[i]; var vertexarr = [facei.a, facei.b, facei.c]; (var j = 0; j < vertexarr.length; j++) { var vertexj = geo.vertices[vertexarr[j]]; var normalj = facei.vertexnormals[j]; if (vertexj.hasscale) continue; vertexj.x += normalj.x * ratio; vertexj.y += normalj.y * ratio; vertexj.z += normalj.z * ratio; vertexj.hasscale = true; } } return geo; },
Comments
Post a Comment