Skip to content

Commit

Permalink
🎨 add Bronze texture
Browse files Browse the repository at this point in the history
  • Loading branch information
mkubdev committed Jul 20, 2023
1 parent ac9523e commit e13f205
Show file tree
Hide file tree
Showing 14 changed files with 1,126 additions and 187 deletions.
751 changes: 751 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
}
},
"dependencies": {
"drei": "^2.2.21",
"gsap": "^3.12.2",
"lil-gui": "^0.16.1",
"stats.js": "^0.17.0",
Expand All @@ -36,4 +37,4 @@
"husky": "^8.0.3",
"prettier": "^3.0.0"
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/textures/bronze/baseColor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/textures/bronze/bump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/textures/bronze/bump16bit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/textures/bronze/displacement.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/textures/bronze/metalness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/textures/bronze/normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/textures/bronze/roughness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
175 changes: 175 additions & 0 deletions sources/Experience/Bronze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import { gsap } from 'gsap'
import * as THREE from 'three'
import Experience from './Experience.js'


export default class Bronze {
constructor() {
console.log('Bronze')
this.experience = new Experience()
this.scene = this.experience.scene


this.setGeometry()
this.setGeometry()
this.setLoadingManager()
this.setMaterial()
this.setLights()
this.setMesh()
this.setGUI()
this.setFog()
}

setFog () {
this.scene.fog = new THREE.Fog(0x000000, 1, 100)
}

setGeometry () {
// this.geometry = new THREE.TorusKnotGeometry( 10, 3, 100, 16 );
// this.geometry = new THREE.BoxGeometry(1,1,1, 4, 4, 4)
this.geometry = new THREE.SphereGeometry(1, 64, 64)
console.log('UV =>', this.geometry.attributes.uv)
}

setGroup () {
console.log('setGroup', this)
}


setLoadingManager () {
const loadingManager = new THREE.LoadingManager()
loadingManager.onStart = () => {
console.log('loading started')
}
loadingManager.onLoad = () => {
console.log('loading finished')
}
loadingManager.onProgress = () => {
console.log('loading progressing')
}
loadingManager.onError = () => {
console.log('loading error')
}

this.texture = {}
const textureLoader = new THREE.TextureLoader(loadingManager)
this.texture.bronzeColor = textureLoader.load(
'/assets/textures/bronze/baseColor.png'
)
this.texture.bronzeBump = textureLoader.load(
'/assets/textures/bronze/bump.png'
)
this.texture.bronzeBump16Bit = textureLoader.load(
'/assets/textures/bronze/bump16bit.png'
)

this.texture.bronzeDisplacement = textureLoader.load(
'/assets/textures/bronze/displacement.png'
)
this.texture.bronzeDisplacement16Bit = textureLoader.load(
'/assets/textures/bronze/displacement16bit.png'
)
this.texture.bronzeMetalness = textureLoader.load(
'/assets/textures/bronze/metalness.png'
)
this.texture.bronzeNormal = textureLoader.load(
'/assets/textures/bronze/normal.png'
)
this.texture.bronzeRoughness = textureLoader.load(
'/assets/textures/bronze/roughness.png'
)

// this.texture.bronzeColor.wrapS = THREE.RepeatWrapping
// this.texture.bronzeColor.wrapT = THREE.RepeatWrapping

// this.texture.woodColor.repeat.set(2, 2)
}

/**
* Set the lights
* Surement une erreur de le faire ici, peux-etre mieux sur Experience?
*/
setLights () {
this.lights = {}
const keyLightColor = 0xffffed
const fillLightColor = 0xffffed
const rimLightColor = 0xffffed

// Create the key light
const keyLight = new THREE.DirectionalLight(keyLightColor, 1.0)
keyLight.position.set(-1, 2, 4)
this.scene.add(keyLight)

// Create the fill light
const fillLight = new THREE.DirectionalLight(fillLightColor, 0.5)
fillLight.position.set(1, -1, 2)
this.scene.add(fillLight)

// Create the rim light
const rimLight = new THREE.DirectionalLight(rimLightColor, 0.5)
rimLight.position.set(0, 1, -2)
this.scene.add(rimLight)
}

setMaterial () {
// this.material = new THREE.MeshBasicMaterial({ wireframe: true, color: this.colors.value, map: this.texture });
// this.material = new THREE.MeshBasicMaterial({ map: this.texture.waffleColor });
this.material = new THREE.MeshStandardMaterial({
map: this.texture.bronzeColor, // Base color texture
bumpMap: this.texture.bronzeBump16Bit, // Bump texture
bumpMap16Bit: this.texture.bronzeBump16Bit, // Bump texture
// displacementMap: this.texture.bronzeDisplacement,
metalnessMap: this.texture.bronzeMetalness,
normalMap: this.texture.bronzeNormal,
roughnessMap: this.texture.bronzeRoughness,
metalness: 0.8,
})
}

setMesh () {
this.mesh = new THREE.Mesh(this.geometry, this.material)
this.scene.add(this.mesh)
}

setGUI () {
const PARAMS = {
wireframe: false,
spin: () => {
gsap.to(this.mesh.rotation, {
duration: 1,
y: this.mesh.rotation.y + Math.PI * 2
})
},
autorotate: false
}

this.experience.debug
.addInput(PARAMS, 'wireframe')
.on('change', _event => {
this.material.wireframe = _event.value
})

this.experience.debug
.addInput(PARAMS, 'autorotate')
.on('change', _event => {
if (_event.value) {
gsap.to(this.mesh.rotation, {
duration: 8,
y: this.mesh.rotation.y + Math.PI * 2,
repeat: -1,
ease: 'none'
})
} else {
gsap.killTweensOf(this.mesh.rotation)
}
})

this.experience.debug
.addButton({ title: 'Spin' })
.on('click', PARAMS.spin)
}

update () {
this.material.uniforms.uTime.value = this.time
}
}
Loading

0 comments on commit e13f205

Please sign in to comment.