gpt4 book ai didi

javascript - 框的 "0"宽度呈现为 "1"宽度

转载 作者:行者123 更新时间:2023-11-30 13:57:52 25 4
gpt4 key购买 nike

创建框时

new THREE.BoxGeometry(opening.geometry.xLength, opening.geometry.yLength, opening.geometry.zLength)

当你制作一个 0 宽度的盒子时。

new THREE.BoxGeometry(0, 1, 1)

它以 1 为宽度在屏幕上呈现。我认为它不应该渲染任何东西。这是threejs的bug吗。

最佳答案

Three.js 的当前代码是这样编写的:0 = 使用默认大小 1

您可以通过制作大小为 1 的框并缩放几何来解决此问题

const geometry = new THREE.BoxGeometry(); // default is 1
geometry.applyMatrix(new THREE.Matrix4().makeScale(
opening.geometry.xLength, opening.geometry.yLength, opening.geometry.zLength));

'use strict';

/* global THREE */

function main() {
const canvas = document.querySelector('#c');
const renderer = new THREE.WebGLRenderer({canvas});

const fov = 75;
const aspect = 2; // the canvas default
const near = 0.1;
const far = 5;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.z = 2;

const scene = new THREE.Scene();
scene.background = new THREE.Color('white');

function addLight(...pos) {
const color = 0xFFFFFF;
const intensity = 1;
const light = new THREE.DirectionalLight(color, intensity);
light.position.set(...pos);
scene.add(light);
}
addLight(-1, 2, 4);
addLight( 2, 1, 4);

const geometry = new THREE.BoxGeometry();
geometry.applyMatrix(new THREE.Matrix4().makeScale(0, 1, 1));
const material = new THREE.MeshPhongMaterial({color:'red'});
const box = new THREE.Mesh(geometry, material);
scene.add(box);

function resizeRendererToDisplaySize(renderer) {
const canvas = renderer.domElement;
const width = canvas.clientWidth;
const height = canvas.clientHeight;
const needResize = canvas.width !== width || canvas.height !== height;
if (needResize) {
renderer.setSize(width, height, false);
}
return needResize;
}

function render(time) {
time *= 0.001;

if (resizeRendererToDisplaySize(renderer)) {
const canvas = renderer.domElement;
camera.aspect = canvas.clientWidth / canvas.clientHeight;
camera.updateProjectionMatrix();
}

box.rotation.x = time;
box.rotation.y = time;

renderer.render(scene, camera);

requestAnimationFrame(render);
}

requestAnimationFrame(render);
}

main();
body { margin: 0; }
#c { width: 100vw; height: 100vh; display: block; }
<canvas id="c"></canvas>
<script src="https://threejsfundamentals.org/threejs/resources/threejs/r105/three.min.js"></script>

关于javascript - 框的 "0"宽度呈现为 "1"宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56874578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com