【发布时间】:2016-07-04 22:53:36
【问题描述】:
我只是在搞乱three.js,遇到了以下示例HERE。我看到以下初始化函数(我没有发布整个函数,而只是其中的一部分):
function init() {
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( fov, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 100;
camera.target = new THREE.Vector3();
controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.minDistance = 50;
controls.maxDistance = 200;
scene.add( new THREE.AmbientLight( 0x443333 ) );
var light = new THREE.DirectionalLight( 0xffddcc, 1 );
light.position.set( 1, 0.75, 0.5 );
scene.add( light );
var light = new THREE.DirectionalLight( 0xccccff, 1 );
light.position.set( -1, 0.75, -0.5 );
scene.add( light );
//..... more code
}
现在在几个地方我看到使用了以下代码行:
scene.add( new THREE.AmbientLight( 0x443333 ) );
当我浏览函数 AmbientLight 的文档时,我得到以下信息:
AmbientLight 文档,
环境光(颜色,强度)
color — 颜色的 RGB 分量的数值。强度 - 光强度/强度的数值。
但是 0x443333 到底是什么,我从来没有遇到过这样的事情。有人能解释一下0x443333 到底是什么意思吗?
【问题讨论】:
-
This:
0x443333与十六进制的#443333相同(例如在 CSS 或 Photoshop 中) - 只是用0x表示,表示该数字是以 16 为基数编写的,所以 javascript 可以正确解析这些。 (这也是为什么你不能在javascript中写数字01,因为它会被标记为不正确)
标签: javascript three.js