简体   繁体   English

THREE.js 不使用 .mtl 渲染 .obj - 为 THREE.js 导出文件

[英]THREE.js not rendering .obj with .mtl - exporting files for THREE.js

***UPDATE***This has to be an issue with the files and the way they are exported, i just don't know what that issue is. ***更新***这一定是文件及其导出方式的问题,我只是不知道那个问题是什么。 I have downloaded some more example models and they all render just fine.我下载了更多示例模型,它们都渲染得很好。

I am experiencing an issue with Three.js when loading .obj and .mtl files.我在加载 .obj 和 .mtl 文件时遇到 Three.js 问题。

I have a bunch of objects and their corresponding material files exported from 3ds.我有一堆从 3ds 导出的对象及其相应的材质文件。 I am not the one who has exported these files, I am not a 3d modeler however if this turns out to be an issue with the files I can ask the modeler to export them again.我不是导出这些文件的人,我也不是 3d 建模师,但是如果结果证明文件存在问题,我可以要求建模师再次导出它们。

I have used THREE.js a few times and never come across this issue, I am loading the .mtl and .obj file using the following:我已经使用了 THREE.js 几次,但从未遇到过这个问题,我正在使用以下内容加载 .mtl 和 .obj 文件:

mtlLoader.load("stands/objects/Table&Chairs.mtl", function(materials){

            materials.preload();
            var objLoader = new THREE.OBJLoader();
            objLoader.setMaterials(materials);

            objLoader.load("stands/objects/Table&Chairs.obj", function(object){

                scene.add(object);
                object.position.set(-5, 0, 4);
            });

        });

My problem is the object loads fine, there are no errors, however nothing is shown.我的问题是对象加载正常,没有错误,但没有显示任何内容。 The object is not being rendered to the scene.对象没有被渲染到场景中。

If i download some example assets from other sources and switch out the files that are being uploaded, without changing anything else, the object renders.如果我从其他来源下载一些示例资产并切换正在上传的文件,而不更改任何其他内容,则对象会呈现。

This leads me to believe it could be an issue with the way in which the files are being exported.这让我相信这可能是文件导出方式的问题。

screen showing of my .obj being rendered正在渲染我的 .obj 的屏幕显示

正在渲染我的 .obj 的屏幕显示

Screen showing the example .obj being rendered显示正在呈现的示例 .obj 的屏幕

显示正在呈现的示例 .obj 的屏幕

Any help as to what could be causing this would be much appreciated.任何有关可能导致这种情况的帮助将不胜感激。

I have uploaded the objects and materials here .我已经在这里上传了对象和材料。

Mine are the Table&Chairs, the example ones are the Tent_Poles_01 files.我的是桌椅,示例是 Tent_Poles_01 文件。

The great thing about .OBJ files is that you can just open them up in the text editor of your choice and see what is inside. .OBJ 文件的好处在于您可以在您选择的文本编辑器中打开它们,看看里面有什么。 This will give you a rough idea of position and scale:这将使您大致了解位置和比例:

  • Looking at the vertices in your tent model, it seems to have a size of about 2 units in each dimension, centered around the origin.查看帐篷模型中的顶点,似乎每个维度的大小约为 2 个单位,以原点为中心。
  • Looking at the vertices in the Table & Chairs model, they have a size of a couple of hundred/thousand units, and start near (+6000,0,-2000).查看Table & Chairs模型中的顶点,它们的大小为几十/千个单位,并从 (+6000,0,-2000) 附近开始。

In other words, the first suspect would be your model being rendered somewhere far outside the visible viewport.换句话说,第一个怀疑是你的模型被渲染在可见视口之外的某个地方。

Usually, when you work together with a 3D artist, you discuss the scale you want to work at beforehand, and have them nicely align the model with the origin.通常,当您与 3D 艺术家合作时,您会事先讨论要使用的比例,并让他们将模型与原点很好地对齐。

You can (sort of) correct this in code, but it will not be as practical.您可以(某种程度上)在代码中更正此问题,但它不会那么实用。

  1. mesh.geometry.center() will recenter the geometry around (0, 0, 0)... but do note that is usually not what you want . mesh.geometry.center()将围绕 (0, 0, 0) 重新调整几何图形...但请注意,这通常不是您想要的 For example, a table will then be half-way through the floor in it's default centered position.例如,一张桌子将在它的默认居中位置穿过地板的一半。

  2. to scale the geometry to an absolute size, use something like (pseudocode)要将几何图形缩放到绝对大小,请使用类似(伪代码)

     var currentSize = new THREE.Box3().setFromObject(model).getSize(); mesh.geometry.scale( targetWidth / currentSize.X, targetHeight / currentSize.Y, targetDepth / currentSize.Z)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM