【问题标题】:ThreeJS, 3D object texture not working only onlineThreeJS,3D对象纹理不能仅在线工作
【发布时间】:2016-09-10 02:11:24
【问题描述】:

我在 AR 应用程序中使用 three.js,以在使用 JSARToolKit 检测到的标记上显示 3D 对象(使用 Maya 导出器从 Maya 导出到 threejs)。

在 localhost 上一切正常(我看到了纹理),但是当我将它上传到网上(github)时,我看到预览对象全黑,没有纹理(就像我移除灯光一样) .

// load the model
var loader = new THREE.JSONLoader;
var object;
//var geometry = new THREE.BoxGeometry(1, 1, 1);
loader.load('js/object3d.js', function(geometry, materials){
var material = new THREE.MeshFaceMaterial(materials);
object = new THREE.Mesh(geometry, material);

container.add(object);
});

var ambLight = new THREE.AmbientLight( 0x909090, 2.0 );
container.add( ambLight );

有什么想法吗?

【问题讨论】:

  • 在 chrome 中按 f12 并检查控制台部分中的错误。如果没有,则切换到网络选项卡并重新加载您的游戏以查看哪些资源正在加载,哪些没有。
  • 控制台中没有错误。一切都在加载中。
  • @Vig 你能发布一个演示链接吗?

标签: json 3d three.js textures maya


【解决方案1】:

我不确定这是否是问题所在,但可能是您的加载程序遇到了一些错误,但由于您没有为您的加载程序设置错误处理程序,因此您不会收到通知。

JSONLoader 加载方法采用四个参数(urlonLoadonProgressonError),如您所见 here in the class on line 40

尝试设置一个错误处理程序(onError 回调方法),看看你会得到什么。例如:

var onload = function(geometry, materials){
    var material = new THREE.MeshFaceMaterial(materials);
    object = new THREE.Mesh(geometry, material);
    container.add(object);
});
var onProgress = function(){
    // your optional on progress logic
}
var onError = function(error){
    console.log( error );
}

var loader = new THREE.JSONLoader;
loader.load('js/object3d.js', onLoad, onProgress, onError);

【讨论】:

  • 感谢您的建议!实际上我在控制台中遇到了这个错误:htmlpreview.github.io/:1 [.CommandBufferContext]GL ERROR :GL_INVALID_OPERATION : glGenerateMipmap: Can not generate mips ________________________________________________ (255)htmlpreview.github.io/:1 [.CommandBufferContext]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering. ________________________________________________ htmlpreview.github.io/:1 WebGL: too many errors, no more errors will be reported to the console for this context.
  • @Vig 错误消息给出了一些可能导致问题的提示。您的纹理大小是 2 的幂吗(例如 64x64、128x128、256x256 等)。
  • 阅读here:您收到此错误可能是因为“纹理在加载之前正在使用。也就是说,您应该在使用纹理之前等待 loadTexture 回调?”
  • @Vig 不知道,能想到几个原因。您应该尝试调试并找出答案。可能是它在 localhost 上加载得如此之快,以至于图像在第一次渲染调用之前加载。在这种情况下,它按预期工作。您可以在 chrome 中模拟本地主机上的慢速连接。检查here 以了解如何操作。您应该清空缓存,因为如果图像仍在缓存中,它也会快速加载。
猜你喜欢
  • 1970-01-01
  • 2020-03-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-16
  • 2018-04-28
  • 2016-05-31
  • 2015-06-17
  • 2012-11-16
相关资源
最近更新 更多