1.场景 (Scene) 相关属性
1.1 基础属性
scene.background = new THREE.Color(0x87CEEB);
scene.background = new THREE.TextureLoader().load('sky.jpg');
// 线性雾
scene.fog = new THREE.Fog(0xffffff, 10, 100)
// 指数雾
scene.fog = new THREE.FogExp2(0xffffff, 0.01)
console.log(scene.children);
2.相机 (Camera) 相关属性
2.1 透视相机 (PerspectiveCamera)
camera.fov = 60
camera.aspect = window.innerWidth / window.innerHeight
camera.updateProjectionMatrix()
camera.near = 0.1
camera.far = 1000
camera.position.set(0, 5, 10);
2.2 正交相机 (OrthographicCamera)
- left/right/top/bottom: 视口边界
const width = 10;
const height = width * (window.innerHeight / window.innerWidth);
camera = new THREE.OrthographicCamera(
width / -2,
width / 2,
height / 2,
height / -2
);
3.渲染器 (Renderer) 相关属性
renderer.shadowMap.enabled = true
renderer.shadowMap.type = THREE.PCFSoftShadowMap
renderer.setPixelRatio(window.devicePixelRatio);
renderer.outputEncoding = THREE.sRGBEncoding
renderer.toneMapping = THREE.ACESFilmicToneMapping
renderer.toneMappingExposure = 1.0
4.几何体 (Geometry) 通用属性
4.1 BufferGeometry 核心属性
geometry.attributes.position
geometry.attributes.normal
geometry.attributes.uv
- boundingBox/boundingSphere: 边界框/边界球
geometry.computeBoundingBox()
console.log(geometry.boundingBox)
4.2 常用几何体参数
new THREE.BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments);
new THREE.SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength);
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded);
5.材质 (Material) 通用属性
5.1 基础材质属性
material.color = new THREE.Color(0xff0000)
material.wireframe = true
material.transparent = true
material.opacity = 0.5
material.side = THREE.FrontSide
material.side = THREE.BackSide
material.side = THREE.DoubleSide
5.2 光照相关属性
- emissive/emissiveIntensity: 自发光
material.emissive = new THREE.Color(0x00ff00)
material.emissiveIntensity = 0.5
- roughness/metalness: PBR材质参数
material.roughness = 0.5
material.metalness = 0.5
5.3 纹理映射属性
material.map = new THREE.TextureLoader().load('texture.jpg')
material.normalMap = new THREE.TextureLoader().load('normal.jpg')
material.normalScale = new THREE.Vector2(1, 1)
- roughnessMap/metalnessMap: PBR纹理
material.roughnessMap = new THREE.TextureLoader().load('roughness.jpg')
material.metalnessMap = new THREE.TextureLoader().load('metalness.jpg')
6.灯光 (Light) 通用属性
6.1 所有灯光共有属性
light.color = new THREE.Color(0xffffff)
light.intensity = 1.0
6.2 特定灯光属性
light.shadow.camera.near = 0.5
light.shadow.camera.far = 500
light.shadow.mapSize.width = 1024
light.distance = 100
light.decay = 1
light.angle = Math.PI / 4
light.penumbra = 0.5
7.网格 (Mesh) 相关属性
- position/rotation/scale: 变换属性
mesh.position.set(0, 1, 0);
mesh.rotation.set(Math.PI/2, 0, 0);
mesh.scale.set(2, 1, 1);
- castShadow/receiveShadow: 阴影设置
mesh.castShadow = true
mesh.receiveShadow = true
mesh.userData = { id: 1, name: 'player' }
8.动画相关属性
const clock = new THREE.Clock();
function animate() {
const delta = clock.getDelta();
const elapsed = clock.getElapsedTime();
}
const mixer = new THREE.AnimationMixer(model)
const action = mixer.clipAction(gltf.animations[0])
action.play()
9.性能优化属性
mesh.frustumCulled = true
transparentMesh.renderOrder = 1
geometry.dispose()
material.dispose()
texture.dispose()
10.高级渲染属性
- depthTest/depthWrite: 深度测试
material.depthTest = true
material.depthWrite = true
material.blending = THREE.NormalBlending
material.blending = THREE.AdditiveBlending
material.alphaTest = 0.5