Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

javascript - Threejs UV协调纹理超出尺寸问题(Threejs UV coordinated texture out of size problem)

I am creating texture with canvas.

(我正在用画布创建纹理。)

I am using UV algorithm and I found at stack overflow.

(我正在使用UV算法,却发现堆栈溢出。)

But i think, this uv algorithm creating faces like box geometry and my texture look like this photo.

(但是我认为,这种uv算法可以创建类似盒子几何形状和我的纹理的面孔,就像这张照片一样。)

How can i write this text to dragged area ?

(我如何将此文本写到拖动的区域?)

在此处输入图片说明

UV code:

(紫外线代码:)

assignUVs(object) {
      object.geometry.computeBoundingBox();

      const {max, min} = object.geometry.boundingBox;

      const offset = new THREE.Vector2(0 - min.x, 0 - min.y);
      const range = new THREE.Vector2(max.x - min.x, max.y - min.y);

      object.geometry.faceVertexUvs[0] = object.geometry.faces.reduce(
          (acc, val) => {
              const v1 = object.geometry.vertices[val.a];
              const v2 = object.geometry.vertices[val.b];
              const v3 = object.geometry.vertices[val.c];

              acc.push([
                  new THREE.Vector2(
                      (v1.x + offset.x) / range.x,
                      (v1.y + offset.y) / range.y
                  ),
                  new THREE.Vector2(
                      (v2.x + offset.x) / range.x,
                      (v2.y + offset.y) / range.y
                  ),
                  new THREE.Vector2(
                      (v3.x + offset.x) / range.x,
                      (v3.y + offset.y) / range.y
                  )
              ]);

              return acc;
          },
          []
      );

      object.geometry.uvsNeedUpdate = true;
  }
  ask by Ahmet emre CETIN translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...