简体   繁体   English

在three.js中看不到obj

[英]can't see obj in three.js

I have a 3D model that i exported from meshlab and want to load it in three.js like this: 我有一个从Meshlab导出的3D模型,并希望将其加载到three.js中,如下所示:

var scene = new three.Scene();
scene.background = new THREE.Color( 0xffffff );
var camera = new three.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);

var renderer = new three.WebGLRenderer({ alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);

document.body.appendChild(renderer.domElement);
var mesh = null;
var material = new THREE.MeshBasicMaterial({color: 'yellow', side: THREE.DoubleSide});
function initMesh() {
    var loader = new THREE.OBJLoader();
    loader.load('merged.obj', function(obj) {

        obj.traverse(function (child) {

            if (child instanceof THREE.Mesh) {
                child.material = material;
            }

        });
    mesh = new THREE.Mesh(obj);
    mesh.name = 'mesh1';
    scene.add(mesh);
    });
}

But i cannot see the model. 但是我看不到模型。 I tried changing back ground colors and the color of the mesh, but i'm not sure the object is in the scene. 我尝试更改背景色和网格的颜色,但不确定对象是否在场景中。

The camera in Meshlab has the following viewpoint: Meshlab中的相机具有以下观点:

<!DOCTYPE ViewState>
<project>
 <VCGCamera TranslationVector="13.2236 38.6958 -15.7741 1" 
LensDistortion="0 0" ViewportPx="1280 611" PixelSizeMm="0.0369161 
0.0369161" CenterPx="640 305" FocalMm="19.5338" 
RotationMatrix="0.86925 -0.494334 0.00615375 0 -0.0132438 -0.0108413 
0.999853 0 -0.494195 -0.869204 -0.0159706 0 0 0 0 1 "/>
 <ViewSettings NearPlane="1.03109" TrackScale="0.0390212" 
FarPlane="13.0311"/>
 <Render Lighting="0" DoubleSideLighting="0" SelectedVert="0" 
ColorMode="3" SelectedFace="0" BackFaceCull="0" FancyLighting="0" 
DrawMode="2" TextureMode="0"/>
</project>

Do i have to change the settings of my camera? 我是否需要更改相机的设置?

EDIT: the OBJ file can be found at: https://files.fm/u/e5n2u4dq 编辑:OBJ文件可以在以下位置找到: https : //files.fm/u/e5n2u4dq

More debugging showed that loader.load() is never executed, but i can't figure out what's wrong 更多的调试表明loader.load()从未执行,但我不知道出了什么问题

There isn't enough information to answer your question, but off the top of my head, I would guess your model is coming in too large. 没有足够的信息来回答您的问题,但是我想不到的是,您的模型太大了。

Try setting doing a mesh.scale.multiplyScalar(0.01) after you set the name, and see if it shows up. 设置名称后,尝试设置为mesh.scale.multiplyScalar(0.01),然后查看它是否显示。

If that doesn't work.. using the chrome debugger, set a breakpoint on the line after you create the mesh, and do a mesh.geometry.computeBoundingBox()... then inspect the mesh.geometry.boundingBox to find the min/max bounds of your mesh. 如果那不起作用..使用chrome调试器,在创建网格后在行上设置一个断点,然后执行mesh.geometry.computeBoundingBox()...然后检查mesh.geometry.boundingBox以找到最小/网格的最大边界。 Make sure that that size and centerpoint falls somewhere near zero and size falls within the .near and .far of your camera range. 确保大小和中心点在零附近,并且大小在相机范围的.near和.far之内。 You could automate this centering in code if necessary, but that's a bit complicated. 您可以根据需要自动以代码为中心,但这有点复杂。 hth! hth!

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

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