materials properties
/*
* Textures
*/
const textureLoader = new THREE.TextureLoader()
const doorColorTexture = textureLoader.load('')
const doorAlphaTexture = textureLoader.load('')
const doorAmbientOcclusionTexture = textureLoader.load('')
const doorHeightTexture = textureLoader.load('')
const doorNormalTexture = textureLoader.load('')
const doorMetalnessTexture = textureLoader.load('')
const doorRoughnessTexture = textureLoader.load('')
const matCapTexture = textureLoader.load('')
// Most of properties can be written like this
// 写法1:
const material = new THREE.MeshBasicMaterial({
map: doorColorTexture, // 纹理贴图
wireframe: true, // show the triangles that compose the geometry
})
// 写法2:
const material = new THREE.MeshBasicMaterial()
material.map = doorColorTexture
material.wireframe = true
// Color
// 写法1:
const material = new THREE.MeshBasicMaterial({
color: 'pink'
})
// 写法2:
const material = new THREE.MeshBasicMaterial()
console.log(material.color); // 打印出一个Color类
material.color.set('#ff0000')
// 写法3:
const material = new THREE.MeshBasicMaterial()
material.color = new THREE.Color(0xff0000)
// Opacity
// 使用opacity属性时,需要同时设置 transparent为true
// 使用alphaMap属性时,也需要搭配 transparent = true
const material = new THREE.MeshBasicMaterial({
color: 'pink'
transparent: true,
opacity: 0.5
})
// Side - decide whitch side of a face is visible
const material = new THREE.MeshBasicMaterial({
color: 'pink',
side: THREE.FrontSide, // 默认
// side: THREE.BackSide,
// side: THREE.DoubleSide,
})
-
MeshNormalMaterial - shares common properties width
MeshBasicMaterial
like wireframe
、transparnt
、opacity
and side
,通常可用于调试法线,使用法线向量计算物体表面的颜色
const material = new THREE.MeshNormalMaterial({
flatShading: true // 使用平面着色进行渲染
})
const material = new THREE.MeshMatCapMaterial({
matcap: matCapTexture
})
-
MeshDepthMaterial - simply color the geometry in white if it's close to the near and in black if it's close to the far value of the camera
-
MeshLamberMaterial - have new properties related to lights
const material = new THREE.MeshLambertMaterial()
/*
* Lights
*/
// 环境光
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5)
scene.add(ambientLight)
// 点光源
const pointLight = new THREE.PointLight(0xffffff, 0.5)
pointLight.position.set(2, 3, 4)
scene.add(pointLight)