我试图使用三个

发布于 2025-01-31 09:35:42 字数 2007 浏览 0 评论 0原文

我正在尝试将纹理添加到一个球体中,特别是通过使用TexturEloDoder将图像映射到其上。

但是,我可以完美地添加材料,而没有图像。例如,如果我删除了“映射:textureLoader()。负载(Earthuv)”并用“ color:0xff0000”代替它,则球体会在没有错误的情况下完全填充,但是对于纹理程序,我只是收到错误日志在下面找到。

请随时提出问题,因为我不知道我还应该提供什么来帮助解决此错误。

错误日志:

TypeError: Cannot set properties of undefined (setting 'manager')
    at Loader (three.module.js?5a89:34164:1)
    at TextureLoader (three.module.js?5a89:34947:1)
    at VueComponent.mounted (about.vue?9043:39:1)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1863:1)
    at callHook (vue.runtime.esm.js?2b0e:4235:1)
    at Object.insert (vue.runtime.esm.js?2b0e:3158:1)
    at invokeInsertHook (vue.runtime.esm.js?2b0e:6390:1)
    at Vue.patch [as __patch__] (vue.runtime.esm.js?2b0e:6538:1)
    at Vue._update (vue.runtime.esm.js?2b0e:3960:1)
    at Vue.updateComponent (vue.runtime.esm.js?2b0e:4075:1)

请在下面找到我的尝试:

<template>
  <div>
    <canvas ref="aboutCanvas"></canvas>
  </div>
</template>

<script>
import {
  Scene,
  PerspectiveCamera,
  WebGLRenderer,
  Mesh,
  SphereGeometry,
  MeshBasicMaterial,
  TextureLoader,
} from "three";

import earthUV from "~/assets/earthUV.jpg";
export default {
  mounted() {
    const scene = new Scene();
    const camera = new PerspectiveCamera(
      75,
      innerWidth / innerHeight,
      0.1,
      1000
    );

    const renderer = new WebGLRenderer({
      canvas: this.$refs.aboutCanvas,
    });
    renderer.setSize(innerWidth, innerHeight);
    document.body.appendChild(renderer.domElement);

    // Create a sphere
    const sphere = new Mesh(
      new SphereGeometry(5, 50, 50),
      new MeshBasicMaterial({
        map: TextureLoader().load(earthUV)
      })
    );

    // Add objects into scene
    scene.add(sphere);

    camera.position.z = 10;

    function animate() {
      requestAnimationFrame(animate);
      renderer.render(scene, camera);
    }
    animate();
  },
};
</script>

I am trying to add a texture to a sphere, specifically by mapping an image to it using TextureLoader.

However, I can add the material perfectly fine, without the image that is. For example, if I removed the line "map: TextureLoader().load(earthUV)" and replaced it with "color: 0xFF0000", the sphere would load perfectly fine with no errors, but with the TextureLoader I just receive the error log found below.

Please feel free to ask questions as I do not know what else I should provide to help fix this error.

Error Log:

TypeError: Cannot set properties of undefined (setting 'manager')
    at Loader (three.module.js?5a89:34164:1)
    at TextureLoader (three.module.js?5a89:34947:1)
    at VueComponent.mounted (about.vue?9043:39:1)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1863:1)
    at callHook (vue.runtime.esm.js?2b0e:4235:1)
    at Object.insert (vue.runtime.esm.js?2b0e:3158:1)
    at invokeInsertHook (vue.runtime.esm.js?2b0e:6390:1)
    at Vue.patch [as __patch__] (vue.runtime.esm.js?2b0e:6538:1)
    at Vue._update (vue.runtime.esm.js?2b0e:3960:1)
    at Vue.updateComponent (vue.runtime.esm.js?2b0e:4075:1)

Please find the code for my attempt below:

<template>
  <div>
    <canvas ref="aboutCanvas"></canvas>
  </div>
</template>

<script>
import {
  Scene,
  PerspectiveCamera,
  WebGLRenderer,
  Mesh,
  SphereGeometry,
  MeshBasicMaterial,
  TextureLoader,
} from "three";

import earthUV from "~/assets/earthUV.jpg";
export default {
  mounted() {
    const scene = new Scene();
    const camera = new PerspectiveCamera(
      75,
      innerWidth / innerHeight,
      0.1,
      1000
    );

    const renderer = new WebGLRenderer({
      canvas: this.$refs.aboutCanvas,
    });
    renderer.setSize(innerWidth, innerHeight);
    document.body.appendChild(renderer.domElement);

    // Create a sphere
    const sphere = new Mesh(
      new SphereGeometry(5, 50, 50),
      new MeshBasicMaterial({
        map: TextureLoader().load(earthUV)
      })
    );

    // Add objects into scene
    scene.add(sphere);

    camera.position.z = 10;

    function animate() {
      requestAnimationFrame(animate);
      renderer.render(scene, camera);
    }
    animate();
  },
};
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So要识趣 2025-02-07 09:35:42

创建纹理加载器时,您必须使用new关键字。您可以多次使用该单个纹理加载器来加载所需的多数纹理。

const texLoader = new TextureLoader();

const sphere = new Mesh(
  new SphereGeometry(5, 50, 50),
  new MeshBasicMaterial({
    map: texLoader.load(earthUV)
  })
);

When creating a TextureLoader, you have to use the new keyword. You can use that single TextureLoader multiple times to load as many textures as you need.

const texLoader = new TextureLoader();

const sphere = new Mesh(
  new SphereGeometry(5, 50, 50),
  new MeshBasicMaterial({
    map: texLoader.load(earthUV)
  })
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文