gpt4 book ai didi

javascript - 向场景添加光没有效果

转载 作者:可可西里 更新时间:2023-11-01 02:21:50 25 4
gpt4 key购买 nike

我刚开始玩 Three.JS,但一开始就卡住了。当我向场景添加灯光时,它没有任何效果。

renderer = new THREE.WebGLRenderer()
camera = new THREE.PerspectiveCamera 45, # View Angle
800 / 640, # Aspect
0.1, # Near
10000 # Far

camera.position.z = 300

scene = new THREE.Scene()
renderer.setSize 800, 640

document.body.appendChild(renderer.domElement)

createSphere = (radius = 50, segments = 16, rings = 16) ->
sphere = new THREE.SphereGeometry(radius, segments, rings)
material = new THREE.MeshBasicMaterial {
color: 0xCC000F,
shading: THREE.SmoothShading,
ambient: 0x555555,
specular: 0xffffff
}

new THREE.Mesh sphere, material

light = new THREE.PointLight(0x0040ff)
light.position.x = 10
light.position.y = 50
light.position.z = 300
light.intensity = 0.1

object = createSphere()
scene.add new THREE.AmbientLight(0x0000F0)
scene.add light
scene.add object

draw = ->
time = new Date().getTime() * 0.0005;
light.position.x = Math.sin(time * 0.7) * 30
object.rotation.x += 0.02
renderer.render scene, camera
requestAnimationFrame draw

draw()

我还创建了一个 js fiddle与解析的js。

最佳答案

MeshBasicMaterial 不支持光照,你应该改变你的 Material 。支持照明的基本 Material 是 MeshLambertMaterial,我有 updated你的 jsfiddle。

更详细的例子: http://mrdoob.github.com/three.js/examples/canvas_lights_pointlights.html

关于javascript - 向场景添加光没有效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7703620/

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