2011-11-30 2 views

답변

40

예, 여러 옵션이 있습니다,의 종류 : 계층 구조를 통해

  1. 당신은 단순히 두 개의 기하학 오브젝트의 정점과 메시를 병합 GeometryUtil의 merge() 기능을 통해 add() 기능
  2. 를 사용하여 다른 하나의 메쉬를 추가 할 수 있습니다 메쉬 간 부울 연산을 지원하고 내보내는 기본 3D 편집기를 사용하여 하나의
  3. 으로 변환합니다. (16)을 반복

    var sphere = new THREE.Mesh(new THREE.SphereGeometry(100,16,12),new THREE.MeshLambertMaterial({ color: 0x2D303D, wireframe: true, shading: THREE.FlatShading })); 
           var cylinder = new THREE.Mesh(new THREE.CylinderGeometry(100, 100, 200, 16, 4, false),new THREE.MeshLambertMaterial({ color: 0x2D303D, wireframe: true, shading: THREE.FlatShading })); 
           cylinder.position.y = -100; 
           scene.add(sphere); 
           scene.add(cylinder); 
    

    공지 것을, 그래서 세분 한 메쉬 (괜찮은 모양을 위해) 다른 경기에서는 레벨

    방법 2.1 - 경유 :

방법 1 꽤 정직 GeometryUtils Lathe half-sphere 및 실린더 병합

//make a sphere 
       var sg = new THREE.SphereGeometry(100,16,12); 
       //make cylinder - ideally the segmentation would be similar to predictable results 
       var cg = new THREE.CylinderGeometry(100, 100, 200, 16, 4, false); 
       //move vertices down for cylinder, so it maches half the sphere - offset pivot 
       for(var i = 0 ; i < cg.vertices.length; i++) cg.vertices[i].position.y -= 100; 
       //merge meshes 
       THREE.GeometryUtils.merge(sg,cg); 
       var mesh = new THREE.Mesh(sg,new THREE.MeshLambertMaterial({ color: 0x2D303D, wireframe: true, shading: THREE.FlatShading })); 
       scene.add(mesh); 

방법 2.2

var pts = [];//points array 
       var detail = .1;//half-circle detail - how many angle increments will be used to generate points 
       var radius = 100;//radius for half_sphere 
       var total = Math.PI * .51; 
       for(var angle = 0.0; angle < total ; angle+= detail)//loop from 0.0 radians to PI (0 - 180 degrees) 
        pts.push(new THREE.Vector3(0,Math.cos(angle) * radius,Math.sin(angle) * radius));//angle/radius to x,z 
       var lathe = new THREE.LatheGeometry(pts, 16);//create the lathe with 12 radial repetitions of the profile 
       //rotate vertices in lathe geometry by 90 degrees 
       var rx90 = new THREE.Matrix4(); 
       rx90.setRotationFromEuler(new THREE.Vector3(-Math.PI * .5,0,0)); 
       lathe.applyMatrix(rx90); 
       //make cylinder - ideally the segmentation would be similar for predictable results 
       var cg = new THREE.CylinderGeometry(100, 100, 200, 16, 4, false); 
       //move vertices down for cylinder, so it maches half the sphere 
       for(var i = 0 ; i < cg.vertices.length; i++) cg.vertices[i].position.y -= 100; 
       //merge meshes 
       THREE.GeometryUtils.merge(lathe,cg); 
       var mesh = new THREE.Mesh(lathe, new THREE.MeshLambertMaterial({ color: 0x2D303D, wireframe: true, shading: THREE.FlatShading })); 
       mesh.position.y = 150; 
       scene.add(mesh); 

내가 현재 해결할 수없는 문제 중 하나는 메쉬 내부의 얼굴 때문입니다. 이상적으로는 노멀을 뒤집어 렌더링하지 않으려 고하지만,이를위한 빠른 해결책을 찾지 못했을 것입니다.

3 번째는 상당히 직설적입니다. 대부분의 3D 패키지는 메쉬에서 부울 연산을 허용합니다 (예 : 두 개의 메쉬를 ADD 연산 (meshA + meshB)과 병합). (무료, opensource)에 실린더와 구를 만들어보십시오.이 실린더에는 이미 three.js 내보내기가 있습니다. 또는 3d 편집기 나 선택 항목에서 병합 된 메쉬의 .obj 파일을 내보내고 convert_obj_three 스크립트를 사용할 수 있습니다.

업데이트

좀 더 직관적/쉬울 수 있습니다 또 다른 방법을 찾았습니다. 위에 언급 한 부울 연산을 기억하십니까?

는 멋진 JS 라이브러리는 단지에 대한이 밝혀 : Constructive Solid Geometry :

CSG library preview from owner's github page

챈들러 Prall가 CSG with three.js를 연결하는 몇 가지 편리한 기능을 썼다. 그래서 CSG 라이브러리와 three.js wrapper for it과 함께, 당신은 단순히이 작업을 수행 할 수 있습니다 당신에게 좋은 결과를 제공

var cylinder = THREE.CSG.toCSG(new THREE.CylinderGeometry(100, 100, 200, 16, 4, false),new THREE.Vector3(0,-100,0)); 
var sphere = THREE.CSG.toCSG(new THREE.SphereGeometry(100,16,12)); 
var geometry = cylinder.union(sphere); 
var mesh  = new THREE.Mesh(THREE.CSG.fromCSG(geometry),new THREE.MeshNormalMaterial()); 

(등 추가 얼굴/틀지 법선/아무 문제.) :

cylinder-sphere union with CSG and three.js

+0

나는 그 모든 것을 시도하고 있습니다, 해답을 주셔서 감사합니다! 나는 모양과 질감의 번호와 3D 꽃을 만들려고 이후이 질문을 물었다. 모양을 묶는 내 목적은 모든 모양을 하나의 모양으로 회전시키지 않고 전체 꽃 모양을 회전시키고 끌 수 있습니다. – BorisD

+0

[Hello Enjoy 's HelloFlower app] (http://helloenjoy.com/helloflower/)와 약간 같은 소리가납니다. 이 경우 꼭대기에 빈 '컨테이너'Object3D가 있고 그 다음에 그룹을 조작 할 수 있도록 꽃잎, 암술 등을'추가() '하십시오. 첫 번째 제안과 같은 것이지만, 장면에 곧바로 추가하는 대신 컨테이너 ('scene.add (container); container.add (flowerPartA); container.add (flowerPartB); // etc.')에 추가하십시오. –

+0

와우 ! 그것은 훌륭한 모범적 인 사람입니다 ... 정확히 내가 뭘 만들려고하는지는 모르지만 비슷한 것들이 있습니다. 지난 며칠 동안 나는 좋은 발전을했습니다. 내가 게시 할 최종 예가 Three.js의 초보자에게 도움이되어 작고 큰 문제를 해결할 수 있기를 바랍니다. 하지만 아직도 아직 익숙하지 않은 작은 것들이 있습니다 ... 어떻게 X 점에서 시작하여 Y 점으로 끝나는 실린더 모양과 같은 것을 만들 수 있습니까? 지금은 제가 알아낼 수있는 유일한 것은 실린더와 그것을 회전? – BorisD

관련 문제