作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在vue中将Three.js动画作为组件运行。当我将纹理作为外部联机资源加载时,它工作正常,但是当我尝试在本地运行纹理时,它显示为黑色,没有错误消息。
this.myTexture = new THREE.TextureLoader().load(
"https://vuejs.org/images/logo.png"
// This doesnt work - why?
// "../assets/logo.png"
);
我在浏览器中使用插件允许cors,因此与cors问题无关...
<template>
<div id="app">
<HelloThreeBasic/>
</div>
</template>
<script>
import HelloThreeBasic from './components/HelloThreeBasic.vue'
export default {
name: 'App',
components: {
HelloThreeBasic
}
}
</script>
HelloThreeBasic.vue
<template>
<div>
<div id="container"></div>
</div>
</template>
<script>
import * as THREE from "three";
export default {
name: "HelloThree",
data() {
return {
cube: null,
renderer: null,
scene: null,
camera: null,
container: null,
myTexture: null,
};
},
methods: {
init: function () {
this.scene = new THREE.Scene();
this.camera = new THREE.PerspectiveCamera(75,window.innerWidth / window.innerHeight,0.1,1000);
this.renderer = new THREE.WebGLRenderer();
this.renderer.setSize(window.innerWidth, window.innerHeight);
this.container = document.getElementById("container");
this.container.appendChild(this.renderer.domElement);
const geometry = new THREE.BoxGeometry(1, 1, 1);
this.myTexture = new THREE.TextureLoader().load(
"https://vuejs.org/images/logo.png"
// This doesnt work - why?
// "../assets/logo.png"
);
const material = new THREE.MeshBasicMaterial({
color: 0xffffff,
map: this.myTexture,
transparent: false,
});
this.cube = new THREE.Mesh(geometry, material);
this.scene.add(this.cube);
this.camera.position.z = 2;
},
animate: function () {
requestAnimationFrame(this.animate);
this.cube.rotation.x += 0.01;
this.renderer.render(this.scene, this.camera);
},
},
mounted() {
this.init();
this.animate();
},
beforeDestroy() {
delete this.container;
},
};
</script>
<style >
#container {
width: 100%;
height: 100%;
top: 0;
position: absolute;
z-index: -10;
}
</style>
最佳答案
It works fine when I am loading the texture as an external onlineresource
Access to image at 'https://vuejs.org/images/logo.png' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
this.myTexture = new THREE.TextureLoader().load(
require( "../assets/logo.png" )
);
const material = new THREE.MeshBasicMaterial({
map: this.myTexture,
alphaTest: 0.5
});
关于javascript - 无法在Three.js中加载本地纹理,并在vue.js中将三个作为组件运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64099874/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!