当我移动引用three.js的html文件时,three.js停止工作

three.js stops working, when I move my three.js-referring html-file

本文关键字:three js 文件 停止工作 html 引用 移动      更新时间:2023-09-26

这很奇怪。。

我在我的目录"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.htm中的three.min.js引用时,brick/webagl_geometry_cube.html不起作用-当我在firefox中打开它时,不会显示任何多维数据集。

让我更具体地介绍一下webgl_geometry_cube.html中的three.min.js引用brick/three.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中似乎没有任何其他依赖于路径的引用

Github 上的webgl_geometry_cube.html

另外,我该如何调试它?我可以对代码进行一些逐步了解吗,看看这两个文件在执行中的分歧在哪里?

该示例使用纹理,因此您也需要调整JavaScript中的路径textures/crate.gif,否则找不到纹理。

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

three.js/examples/textures/crate.gif

这个解决方案是由用户maenu提供的。谢谢你,伙计。