1. <tfoot id='Uce7E'></tfoot>
      <i id='Uce7E'><tr id='Uce7E'><dt id='Uce7E'><q id='Uce7E'><span id='Uce7E'><b id='Uce7E'><form id='Uce7E'><ins id='Uce7E'></ins><ul id='Uce7E'></ul><sub id='Uce7E'></sub></form><legend id='Uce7E'></legend><bdo id='Uce7E'><pre id='Uce7E'><center id='Uce7E'></center></pre></bdo></b><th id='Uce7E'></th></span></q></dt></tr></i><div id='Uce7E'><tfoot id='Uce7E'></tfoot><dl id='Uce7E'><fieldset id='Uce7E'></fieldset></dl></div>
    2. <legend id='Uce7E'><style id='Uce7E'><dir id='Uce7E'><q id='Uce7E'></q></dir></style></legend>

      <small id='Uce7E'></small><noframes id='Uce7E'>

        • <bdo id='Uce7E'></bdo><ul id='Uce7E'></ul>

        三.js 生成UV坐标

        时间:2023-09-07

          <bdo id='7zU08'></bdo><ul id='7zU08'></ul>
          • <i id='7zU08'><tr id='7zU08'><dt id='7zU08'><q id='7zU08'><span id='7zU08'><b id='7zU08'><form id='7zU08'><ins id='7zU08'></ins><ul id='7zU08'></ul><sub id='7zU08'></sub></form><legend id='7zU08'></legend><bdo id='7zU08'><pre id='7zU08'><center id='7zU08'></center></pre></bdo></b><th id='7zU08'></th></span></q></dt></tr></i><div id='7zU08'><tfoot id='7zU08'></tfoot><dl id='7zU08'><fieldset id='7zU08'></fieldset></dl></div>

            <small id='7zU08'></small><noframes id='7zU08'>

              1. <legend id='7zU08'><style id='7zU08'><dir id='7zU08'><q id='7zU08'></q></dir></style></legend>
                  <tbody id='7zU08'></tbody>
                <tfoot id='7zU08'></tfoot>

                • 本文介绍了三.js 生成UV坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 THREE.js OBJ 加载器将模型导入场景.

                  I am working on importing a model into a scene using the THREE.js OBJ loader.

                  我知道我可以很好地导入几何图形,因为当我为它分配一个 MeshNormalMaterial 时,它显示得很好.但是,如果我使用任何需要 UV 坐标的东西,它会给我错误:

                  I know that I am able to import the geometry fine, because when I assign a MeshNormalMaterial to it, it shows up great. However, if I use anything that requires UV coordinates, It gives me the error:

                  [.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1 
                  

                  我知道这是因为加载的 OBJ 没有 UV 坐标,但我想知道是否有任何方法可以生成所需的纹理坐标.我试过了

                  I know this is because the loaded OBJ has no UV coordinates, but I was wondering if there was any way to generate the needed texture coordinates. I have tried

                  material.needsUpdate = true;
                  geometry.uvsNeedUpdate = true;
                  geometry.buffersNeedUpdate = true;
                  

                  ...但无济于事.

                  有没有办法使用three.js自动生成UV纹理,还是我必须自己分配坐标?

                  Is there any way to automagically generate UV textures using three.js, or do I have to assign the coordinates myself?

                  推荐答案

                  据我所知,没有自动计算 UV 的方法.

                  To my knowledge there is no automatic way to calculate UV.

                  你必须自己计算.计算平面的 UV 非常简单,这个网站解释了如何:计算纹理坐标

                  You must calculate yourself. Calculate a UV for a plane is quite easy, this site explains how: calculating texture coordinates

                  对于一个复杂的形状,我不知道怎么做.也许你可以检测平面.

                  For a complex shape, I don't know how. Maybe you could detect planar surface.

                  编辑

                  这是一个平面的示例代码(x, y, z) where z = 0:

                  Here is a sample code for a planar surface (x, y, z) where z = 0:

                  geometry.computeBoundingBox();
                  
                  var max = geometry.boundingBox.max,
                      min = geometry.boundingBox.min;
                  var offset = new THREE.Vector2(0 - min.x, 0 - min.y);
                  var range = new THREE.Vector2(max.x - min.x, max.y - min.y);
                  var faces = geometry.faces;
                  
                  geometry.faceVertexUvs[0] = [];
                  
                  for (var i = 0; i < faces.length ; i++) {
                  
                      var v1 = geometry.vertices[faces[i].a], 
                          v2 = geometry.vertices[faces[i].b], 
                          v3 = geometry.vertices[faces[i].c];
                  
                      geometry.faceVertexUvs[0].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)
                      ]);
                  }
                  geometry.uvsNeedUpdate = true;
                  

                  这篇关于三.js 生成UV坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:输入模型在更改时从 Integer 更改为 String 下一篇:如何在html页面中画圆圈?

                  相关文章

                  最新文章

                • <legend id='pzrjG'><style id='pzrjG'><dir id='pzrjG'><q id='pzrjG'></q></dir></style></legend>
                    <bdo id='pzrjG'></bdo><ul id='pzrjG'></ul>
                  <tfoot id='pzrjG'></tfoot>

                  <small id='pzrjG'></small><noframes id='pzrjG'>

                • <i id='pzrjG'><tr id='pzrjG'><dt id='pzrjG'><q id='pzrjG'><span id='pzrjG'><b id='pzrjG'><form id='pzrjG'><ins id='pzrjG'></ins><ul id='pzrjG'></ul><sub id='pzrjG'></sub></form><legend id='pzrjG'></legend><bdo id='pzrjG'><pre id='pzrjG'><center id='pzrjG'></center></pre></bdo></b><th id='pzrjG'></th></span></q></dt></tr></i><div id='pzrjG'><tfoot id='pzrjG'></tfoot><dl id='pzrjG'><fieldset id='pzrjG'></fieldset></dl></div>