我现在一直在照顾这个。我只是找不到任何解决方案。我正在尝试在气缸(2个盖子和侧面)上应用3种不同的纹理,但我绝对不知道如何实现这一目标。你能定向我吗?这是我现在正在做的事情:

var coin1_geo = new THREE.CylinderGeometry( 100, 100, 10, 100, 100, false );
var coin1_texture = THREE.ImageUtils.loadTexture("./assets/avers.png");
var coin1_mat = new THREE.MeshLambertMaterial({map:coin1_texture});
var coin1 = new THREE.Mesh( coin1_geo, coin1_mat );
coin1.rotation.x = 20;
coin1.position.set(0,0,0);
coin1.castShadow = true;
coin1.receiveShadow = false;
scene.add( coin1 );

正如您在这里看到的那样,我只在所有面孔上都应用一个纹理。但是即使在帽子上,它并没有真正显示出来,我只有一块整个圆圈。请帮忙,如果您不知道,我正在实现硬币。即使您只是给我一个指导教程的链接,我也会非常感谢。我什么都找不到,我在3D/OpenGL编程中的知识非常有限。非常感谢。

有帮助吗?

解决方案

编辑]三个圆柱体没有工作,因为帽子紫外线是伪造的。您需要滚动自己的帽几何形状。没有很多工作,只是烦人。这是用自定义帽进行无上限的圆柱体的方法:

var coin_sides_geo =
  new THREE.CylinderGeometry( 10.0, 10.0, 1.0, 100.0, 10.0, true );
var coin_cap_geo = new THREE.Geometry();
var r = 10.0;
for (var i=0; i<100; i++) {
  var a = i * 1/100 * Math.PI * 2;
  var z = Math.sin(a);
  var x = Math.cos(a);
  var a1 = (i+1) * 1/100 * Math.PI * 2;
  var z1 = Math.sin(a1);
  var x1 = Math.cos(a1);
  coin_cap_geo.vertices.push(
    new THREE.Vertex(new THREE.Vector3(0, 0, 0)),
    new THREE.Vertex(new THREE.Vector3(x*r, 0, z*r)),
    new THREE.Vertex(new THREE.Vector3(x1*r, 0, z1*r))
  );
  coin_cap_geo.faceVertexUvs[0].push([
    new THREE.UV(0.5, 0.5),
    new THREE.UV(x/2+0.5, z/2+0.5),
    new THREE.UV(x1/2+0.5, z1/2+0.5)
  ]);
  coin_cap_geo.faces.push(new THREE.Face3(i*3, i*3+1, i*3+2));
}
coin_cap_geo.computeCentroids();
coin_cap_geo.computeFaceNormals();

var coin_sides_texture =
  THREE.ImageUtils.loadTexture("./coin_sides.png");
var coin_cap_texture =
  THREE.ImageUtils.loadTexture("./coin_face.png");

var coin_sides_mat =
  new THREE.MeshLambertMaterial({map:coin_sides_texture});
var coin_sides =
  new THREE.Mesh( coin_sides_geo, coin_sides_mat );

var coin_cap_mat = new THREE.MeshLambertMaterial({map:coin_cap_texture});
var coin_cap_top = new THREE.Mesh( coin_cap_geo, coin_cap_mat );
var coin_cap_bottom = new THREE.Mesh( coin_cap_geo, coin_cap_mat );
coin_cap_top.position.y = 0.5;
coin_cap_bottom.position.y = -0.5;
coin_cap_top.rotation.x = Math.PI;

var coin = new THREE.Object3D();
coin.add(coin_sides);
coin.add(coin_cap_top);
coin.add(coin_cap_bottom);

其他提示

Typescript函数变体,可创建具有3个网格的Object3D:侧面,topcap和底部模式。
使用LIB版本:
“三”:“ 0.102.1”

 import capTop from './textures/capTopTexture.png';
 import capBottom from './textures/capBottomTexture.png';
 import capSide from './textures/sideTexture.png';

 function createCylinder (
        radiusTop: number,
        radiusBottom: number,
        height: number,
        radialSegments: number,
        heightSegments: number,
    ): Object3D {
        const cylinder = new THREE.Object3D();

        const sidesGeo = new THREE.CylinderGeometry(
            radiusTop,
            radiusBottom,
            height,
            radialSegments,
            heightSegments,
            true,
        );
        const sideTexture = new THREE.TextureLoader().load(capSide, this.reRender);
        const sidesMat =
            new THREE.MeshLambertMaterial({map: sideTexture});
        const sidesMesh =
            new THREE.Mesh( sidesGeo, sidesMat );
        cylinder.add(sidesMesh);

        const capTopGeo = new THREE.CircleGeometry(radiusTop, radialSegments);
        const capTopTexture = new THREE.TextureLoader().load(capTop, this.reRender);
        const capTopMat =
            new THREE.MeshLambertMaterial({map: capTopTexture});
        const capTopMesh =
            new THREE.Mesh( capTopGeo, capTopMat );
        capTopMesh.position.y = height / 2;
        capTopMesh.rotation.x = - Math.PI / 2;
        cylinder.add(capTopMesh);

        const capBottomGeo = new THREE.CircleGeometry(radiusBottom, radialSegments);
        const capBottomTexture = new THREE.TextureLoader().load(capBottom, this.reRender);
        const capBottomMat =
            new THREE.MeshLambertMaterial({map: capBottomTexture});
        const capBottomMesh =
            new THREE.Mesh( capBottomGeo, capBottomMat );
        capBottomMesh.position.y = -height / 2;
        capBottomMesh.rotation.x = Math.PI / 2;
        cylinder.add(capBottomMesh);

        return cylinder;
    };


许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top