Skip to content

Commit

Permalink
'3 clouds depthwrite, slower rain rotation changes, fix random point …
Browse files Browse the repository at this point in the history
…away'
  • Loading branch information
foglabs committed Mar 12, 2021
1 parent 20c4732 commit 80e3924
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 40 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
BLACK = true
WHITE = false

DEG360 = 6.283185307179586
// DEG360 = 6.283185307179586
DEG360 = Math.PI*2
</script>

<script type="module">
Expand Down
23 changes: 16 additions & 7 deletions lib/Character.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class Character {
for(var i=0; i<mat.length; i++){
geo.faces[i].materialIndex = i
}
console.log( 'multi mat', geo.faces )

multi = true
}
Expand Down Expand Up @@ -113,7 +112,6 @@ class Character {
// she dont like she dont like shoe dont like... no scale
this.scalable = false


this.hitTimer = new Timer()
this.hitTimer.start()
this.raycasterTimer = new Timer()
Expand Down Expand Up @@ -550,7 +548,6 @@ class Character {
this.rotz = Math.random() * util.radian( 30 ) - util.radian( 15 )
}
}

}

handleRotation(){
Expand All @@ -571,17 +568,17 @@ class Character {
// rotate smoothly towards some rotation we've hcosen elsewhere
if(!setx){

let amtx = Math.random() * 0.08
let amtx = Math.random() * 0.06
setx = util.rotateToward(x, this.rotx, amtx)
}
if(!sety){

let amty = Math.random() * 0.08
let amty = Math.random() * 0.06
sety = util.rotateToward(y, this.roty, amty)
}
if(!setz){

let amtz = Math.random() * 0.08
let amtz = Math.random() * 0.06
setz = util.rotateToward(z, this.rotz, amtz)
}

Expand Down Expand Up @@ -742,7 +739,19 @@ class Character {
}

flatten(){
// handleRotation will subseq rotate us back to flat
// handleRotation will subseq rotate us back to flat

// if( !util.isWithin(this.rotx % this.flatRotx, 0, 0.02) ){
// this.rotx = util.nearestMultiple( this.mesh.rotation.x, this.flatRotx )
// }
// if( !util.isWithin(this.roty % this.flatRoty, 0, 0.02) ){
// this.roty = util.nearestMultiple( this.mesh.rotation.y, this.flatRoty )
// }
// if( !util.isWithin(this.rotz % this.flatRotz, 0, 0.02) ){
// this.rotz = util.nearestMultiple( this.mesh.rotation.z, this.flatRotz )
// }

// OG
this.rotx = this.flatRotx
this.roty = this.flatRoty
this.rotz = this.flatRotz
Expand Down
27 changes: 13 additions & 14 deletions lib/RelaxingRain.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class RelaxingRain extends Place {
floorBump.wrapT = THREE.RepeatWrapping
floorBump.repeat.set(30,4)

var floor = new JunkPiece(new THREE.BoxGeometry(1.8, 0.1, 2.2), new THREE.Box3(new THREE.Vector3(), new THREE.Vector3()), [255,255,255], new THREE.MeshPhysicalMaterial( { map: floorMap, bumpMap: floorBump, bumpScale: 0.0015 }) )
var floor = new JunkPiece(new THREE.BoxGeometry(1.8, 0.1, 2.2), new THREE.Box3(new THREE.Vector3(), new THREE.Vector3()), [255,255,255], new THREE.MeshPhysicalMaterial( { map: floorMap, bumpMap: floorBump, bumpScale: 0.0015 }), null, null, null, new THREE.Vector3(0,2,0))
// huh
floor.setPosition(-0.1,FLOOR,0)
floor.pushable = false
Expand Down Expand Up @@ -426,7 +426,7 @@ class RelaxingRain extends Place {

p = new THREE.Mesh(pg,pm)

pp = util.randomPointAway(64,16)
pp = util.randomPointAway(96,32)
// pp = util.randomPointAway(2,1)
pos = new THREE.Vector3( pp[0],pp[1],pp[2] )
p.position.set(pos.x,pos.y,pos.z)
Expand Down Expand Up @@ -474,7 +474,9 @@ class RelaxingRain extends Place {
// opacity: 0.2
})

this.rainSpinAmount = 0.0008
this.rainSpinChangeTimer = new Timer()
this.rainSpinChangeTimer.start()
this.rainSpinAmount = 0.0
this.rain = new THREE.Points(rainGeo,rainMaterial)
this.rain.castShadow = false
this.rain.receiveShadow = false
Expand All @@ -500,7 +502,7 @@ class RelaxingRain extends Place {
cloudTexture2.wrapT = THREE.RepeatWrapping
// cloudTexture2.repeat = 1
let cloudMaterial2 = new THREE.MeshBasicMaterial({
// depthTest: false,
depthWrite: false,
color: "#110011",
opacity: 0.22,
map: cloudTexture2,
Expand All @@ -522,7 +524,7 @@ class RelaxingRain extends Place {
let cloud, rando
y = 20

for(let p=0; p<1; p++) {
for(let p=0; p<3; p++) {
// rando = Math.random()
// if(rando<0.33){
// cloud = new THREE.Mesh(cloudGeo,cloudMaterial);
Expand All @@ -535,7 +537,7 @@ class RelaxingRain extends Place {


x = Math.random() * 20 - 10
y = y
y = y+1
z = Math.random() * 20 - 10

cloud.position.set(
Expand Down Expand Up @@ -884,15 +886,12 @@ class RelaxingRain extends Place {
this.rain.rotation.y += this.rainSpinAmount

// change rainspin amount by random factor
if(Math.random() > 0.799){

if( Math.abs( this.rainSpinAmount ) > 0.000004 ){

} else {
// normal speed change
this.rainSpinAmount += Math.random() * 0.000005 - 0.00000025
}
if(this.rainSpinChangeTimer.time() > 500){
this.rainSpinChangeTimer.reset()
let rainSpinChange = Math.random()*0.000002 - 0.000001
this.rainSpinAmount = util.incInRange( this.rainSpinAmount, rainSpinChange, -0.0008, 0.0008 )
}

}

customHandle(){
Expand Down
3 changes: 0 additions & 3 deletions lib/Remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ class Remote extends Character {
stereoBump.repeat.set(1,1)

let geo = new THREE.BoxGeometry(0.06,0.014,0.1)
// let geo = new THREE.BoxGeometry(3,3,3)
let bbox = new THREE.Box3(new THREE.Vector3(), new THREE.Vector3())
// let mat = new THREE.MeshBasicMaterial( { color: "#0000ff" })
let mat = new THREE.MeshPhysicalMaterial( { color: "#000000", reflectivity: 1, roughness: 0, clearcoat: 1.0, clearcoatRoughness: 0.1, map: stereoMap, bumpMap: stereoBump, bumpScale: 1 })

// scale back the bbox on z dimension
let bboxScale = new THREE.Vector3(1.0,1.0,0.40)
console.log( 'hi scale', bboxScale )
super(geo, bbox, [0,0,255], mat, null, null, null, bboxScale)

textureLoader.load('/textures/buttonGrain.png', (tex) => {
Expand Down
33 changes: 18 additions & 15 deletions lib/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,16 @@ class Util {
let x,y,z

// at least away away, random within amt range
if(Math.random() > 0.5){
x = this.randomInRange(0, amt) + away
} else {
x = this.randomInRange(-1*amt, 0) - away
}
if(Math.random() > 0.5){
y = this.randomInRange(0, amt) + away
} else {
y = this.randomInRange(-1*amt, 0) - away
}
if(Math.random() > 0.5){
z = this.randomInRange(0, amt) + away
} else {
z = this.randomInRange(-1*amt, 0) - away
}
x = this.randomInRange(-1*amt, amt) + this.awayFromOrigin(x,away)
y = this.randomInRange(-1*amt, amt) + this.awayFromOrigin(y,away)
z = this.randomInRange(-1*amt, amt) + this.awayFromOrigin(z,away)
return [x,y,z]
}

awayFromOrigin(pt,dist){
return Math.sign(pt) == 1 ? dist : -dist
}

randomRGB(max){
return [Math.floor(Math.random()*max), Math.floor(Math.random()*max), Math.floor(Math.random()*max)]
}
Expand Down Expand Up @@ -129,6 +121,17 @@ class Util {
return this.rotateInc(sign*amount, current)
}

nearestMultiple(val, multiple){
// if remainder is more than half multi, need to round up
if(val % multiple > (multiple/2)){
console.log( 'round up', Math.floor(val/multiple) + 1 )
return multiple * ( Math.floor(val/multiple) + 1 )
} else {
console.log( 'round down', Math.floor(val/multiple) )
return multiple * Math.floor(val/multiple)
}
}

isWithin(val, test, precision){
// I dont give two fucks!
precision = Math.abs(precision)
Expand Down

0 comments on commit 80e3924

Please sign in to comment.