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
*/
// 環(huán)境光
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)