【问题标题】:three.js stops working, when I move my three.js-referring html-file当我移动我的three.js-referring html-file时,three.js停止工作
【发布时间】:2012-08-20 04:31:36
【问题描述】:

这很奇怪..

我在我的目录“brick”中下载了三个.js:

git 克隆https://github.com/mrdoob/three.js.git

这是一个子目录:

brick/three.js/

当我去

brick/three.js/examples

在 Firefox 中打开文件

brick/three.js/examples/webgl_geometry_cube.html

一个漂亮的旋转立方体出现了。然后当我将它(即brick/three.js/examples/webgl_geometry_cube.html)复制到目录'brick'并相应地更改新brick/webgl_geometry_cube.html中的three.min.js引用时,brick/webgl_geometry_cube。 html 不起作用 - 当我在 Firefox 中打开它时,没有立方体出现。

让我更具体地说明 webgl_geometry_cube.html 中的 three.min.js 引用。的顶部 砖/三个.js/examples/webgl_geometry_cube.html 看起来像这样:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>three.js webgl - geometry - cube</title>
        <meta charset="utf-8">
        <style>
            body {
                margin: 0px;
                background-color: #000000;
                overflow: hidden;
            }
        </style>
    </head>
    <body>

        <script src="../build/three.min.js"></script>

        <script>

            var camera, scene, renderer;
            var mesh;

当我把它复制到

brick/webgl_geometry_cube.html

我换行

<script src="../build/three.min.js"></script>

到:

<script src="three.js/build/three.min.js"></script>

我通过打开验证这个新参考确实有效

brick/webgl_geometry_cube.html

在 Firefox 中,选择“查看源代码”,并在源代码中遵循对 three.min.js 的引用。如果我看到了three.min.js(我就是)的源代码,我很高兴。

但是为什么在 Firefox 中打开移动的文件时没有立方体旋转呢?我很困惑。 webgl_geometry_cube.html 中似乎没有任何其他依赖于路径的引用。 webgl_geometry_cube.html的完整源代码可以在这里看到:

webgl_geometry_cube.html on Github

另外,我该如何调试呢?我可以对代码进行某种单步调试,看看这两个文件在执行过程中的不同之处吗?

【问题讨论】:

  • 你在 JavaScript 中调整了textures/crate.gif 吗?
  • 解决了 :) 非常感谢..

标签: javascript three.js


【解决方案1】:

示例中使用了纹理,所以需要在 JavaScript 中调整路径textures/crate.gif,否则找不到纹理。

【讨论】:

    【解决方案2】:

    原来在 webgl_geometry_cube.html 中还有一个我没有发现的引用:文件 crate.gif 在第 34 行被引用,这个引用当然也应该更新以反映 crate 的新相对位置.gif:

    three.js/examples/textures/crate.gif
    

    此解决方案由用户 maenu 提供。谢谢大佬。。

    【讨论】:

      猜你喜欢
      • 2021-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多