gpt4 book ai didi

javascript - Three.js 添加多个几何体

转载 作者:行者123 更新时间:2023-12-02 14:03:12 25 4
gpt4 key购买 nike

大家好,我从 Three.js 开始,我不知道为什么我的第二个几何图形不显示。如果我错过了什么,请帮助我。我添加了第一个几何体和所有 Material 并添加到场景中,但我的第二个几何体不想出现。这里需要一点帮助,非常感谢!

// Scene and Camera
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000);

// Renderer
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

// Firt geometry with material and added to the scene.
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh(geometry, material);
scene.add( cube );

// Seconde geometry with material and added to the scene as well.
var mysphere = new THREE.SphereGeometry(5, 32, 32);
var color = new THREE.Color('#ee7800');
var hex = color.getHex;
var sphereMaterial = new THREE.MeshLambertMaterial( { color: hex } );
var sphere = new THREE.Mesh(mysphere, sphereMaterial);
sphere.position.y = 10;
scene.add( sphere );

// Better camera position
camera.position.z = 5;


// Render all and move the cube
function render() {
requestAnimationFrame( render );

cube.rotation.x += 0.03;
cube.rotation.y += 0.01;

renderer.render( scene, camera);
};

render();

最佳答案

只是为了澄清。您的控制台日志中有任何错误消息吗?

var hex = color.getHex();

因为 getHex() 是一个方法。

另外,为什么不呢

var sphereMaterial = new THREE.MeshLambertMaterial( { color: 0xee7800} );

Color 的构造函数看起来很奇怪。应该是这样的:

var color = new THREE.Color( 0xee7800 );

关于javascript - Three.js 添加多个几何体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40249499/

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