Skip to content

Commit

Permalink
'rain stars fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
foglabs committed Mar 9, 2021
1 parent 6040f3b commit 20c4732
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 90 deletions.
92 changes: 48 additions & 44 deletions lib/MusicPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class MusicPlayer extends Character {

super(null, bbox, [255,255,255], null, null, null, place.models["/models/stereo.glb"] )

this.buttonTimer = new Timer()
this.buttonTimer.start()


let playButtonBump = textureLoader.load('/textures/playButtonBumpB.png')
playButtonBump.wrapS = THREE.RepeatWrapping
Expand All @@ -39,13 +42,18 @@ class MusicPlayer extends Character {
let prevmat = new THREE.MeshStandardMaterial( { color: "#ffff00", bumpMap: prevTex, bumpScale: 0.008 })
let prevoffset = new THREE.Vector3(0.005,-0.015,0.1)
let prevClick = () => {
if(this.state == CLOSED){
if(this.album){
this.prevTrack()
if(this.buttonTimer.time() > 800){
this.buttonTimer.reset()

if(this.state == CLOSED){
if(this.album){
this.prevTrack()
}
} else {
this.showText("TRAY OPEN! ")
}
} else {
this.showText("TRAY OPEN! ")
}

}

this.prevButton = new Component( this, prevoffset, prevgeo, [100,0,100], prevmat, prevClick )
Expand Down Expand Up @@ -113,16 +121,18 @@ class MusicPlayer extends Character {
let stopoffset = new THREE.Vector3(0.045,-0.015,0.1)

let stopClick = () => {
if(this.state == CLOSED){
if(this.album){
this.stopSong(this.currentTrack)
this.showText("STOP ")
}
if(this.buttonTimer.time() > 800){
this.buttonTimer.reset()
if(this.state == CLOSED){
if(this.album){
this.stopSong()
this.showText("STOP ")
}

} else {
this.showText("TRAY OPEN! ")
} else {
this.showText("TRAY OPEN! ")
}
}

}

this.stopButton = new Component( this, stopoffset, stopgeo, [100,0,100], stopmat, stopClick )
Expand All @@ -136,7 +146,8 @@ class MusicPlayer extends Character {
let playOffset = new THREE.Vector3(0.085,-0.015,0.1)

let pbClick = (id) => {
if(this.album && this.state == CLOSED){
if(this.buttonTimer.time() > 800 && this.album && this.state == CLOSED){
this.buttonTimer.reset()
this.playSong(this.currentTrack)

let title = ""
Expand All @@ -159,7 +170,8 @@ class MusicPlayer extends Character {
let nextoffset = new THREE.Vector3(0.125,-0.015,0.1)

let nextClick = () => {
if(this.state == CLOSED){
if(this.buttonTimer.time() > 800 && this.state == CLOSED){
this.buttonTimer.reset()
if( this.album ){
this.nextTrack()
}
Expand All @@ -178,20 +190,22 @@ class MusicPlayer extends Character {
let ejectoffset = new THREE.Vector3(0.005,0.059,0.1)

let ejClick = () => {

console.log( 'hey fuckface' )
if(this.state == OPEN){
console.log( 'open' )
this.insert()
this.showText("CLOSING ")
} else if(this.state == CLOSED) {
console.log( 'closed' )
// no alubm just opens tray

this.eject()
this.showText("OPENING ")
if(this.buttonTimer.time() > 800){
this.buttonTimer.reset()

if(this.state == OPEN){
console.log( 'open' )
this.insert()
this.showText("CLOSING ")
} else if(this.state == CLOSED) {
console.log( 'closed' )
// no alubm just opens tray

this.eject()
this.showText("OPENING ")
}
}

// having issues with this being deflagged, uh probably
// so kill it explicitly
this.ejectButton.clicked = false
Expand Down Expand Up @@ -238,7 +252,7 @@ class MusicPlayer extends Character {
this.components.push( this.tray )

// display
this.displayDefaultText = "WELCOME TO SONANT Sound SYSTEM BY FOG LABS - FEEL X-Class Dimensional Audio "
this.displayDefaultText = "WELCOME... SONANT Sound SYSTEM BY FOG LABS... FEEL X-Class Dimensional Audio... EXPLORE Sensitive Sound Circuitry... "
this.displayText = this.displayDefaultText
this.createDisplay()
this.displayTextIndex = 0
Expand Down Expand Up @@ -447,10 +461,10 @@ class MusicPlayer extends Character {
setDisplay(){
// set in anim lloop
// only if theres text to display
let subtext = this.displayText.substring(this.displayTextIndex, this.displayTextIndex + 18)
let subtext = this.displayText.substring(this.displayTextIndex, this.displayTextIndex + 19)

if(subtext.length < 18){
let numNeeded = 18 - subtext.length
if(subtext.length < 19){
let numNeeded = 19 - subtext.length
subtext += this.displayText.substring(0, numNeeded - 1)
}

Expand Down Expand Up @@ -502,7 +516,6 @@ class MusicPlayer extends Character {
for(var i=0; i<this.tracks.length; i++){
// should dispose of sound as well
if(this.tracks[i].mesh){
console.log( 'soundmesh',this.tracks[i].mesh )
// this.tracks[i].mesh.context.close()
this.tracks[i].remove()
}
Expand All @@ -511,11 +524,7 @@ class MusicPlayer extends Character {
}

playSong(songIndex){

if( this.playing && this.currentTrack != songIndex ){
console.log( 'stopping ', this.currentTrack )
this.tracks.forEach( (t) => { t.stop() } )
}
this.stopSong()

this.currentTrack = songIndex
console.log( 'playing ', this.currentTrack )
Expand Down Expand Up @@ -581,12 +590,7 @@ class MusicPlayer extends Character {
// inc looping around
this.currentTrack = util.incInRange(this.currentTrack, inc, 0, this.tracks.length-1)
console.log( 'current track now inc to ', this.currentTrack )

if(this.playing){
// if already playing, stop current song and play new now
this.stopSong()
this.playSong(this.currentTrack)
}
this.playSong(this.currentTrack)
}

customAnimation(){
Expand Down
87 changes: 41 additions & 46 deletions lib/RelaxingRain.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ class RelaxingRain extends Place {
// var lighter = new THREE.HemisphereLight("#ffffff", "#000000", 0.006)
// scene.add(lighter)

var spotlight2 = new THREE.SpotLight("#ddddaa", 0.0008)
// spotlight2.castShadow = true
spotlight2.shadow.mapSize.width = 1024*4
spotlight2.shadow.mapSize.height = 1024*4
spotlight2.position.set(-1.06,1,0.4)
spotlight2.lookAt(-1,-5,0)
scene.add(spotlight2)
spotlight2.shadow.camera.near = 0.5; // default
spotlight2.shadow.camera.far = 500; // default
spotlight2.shadow.focus = 1; // default
scene.add(spotlight2)

let wallMap = textureLoader.load('/textures/rain-wall-text.png')
wallMap.wrapS = THREE.RepeatWrapping
wallMap.wrapT = THREE.RepeatWrapping
Expand All @@ -80,7 +68,17 @@ class RelaxingRain extends Place {

let characters = {}


var doorlight = new THREE.SpotLight("#ddddaa", 0.0008)
// doorlight.castShadow = true
doorlight.shadow.mapSize.width = 1024*4
doorlight.shadow.mapSize.height = 1024*4
doorlight.position.set(-1.06,1,0.4)
doorlight.lookAt(-1,-5,0)
scene.add(doorlight)
doorlight.shadow.camera.near = 0.5; // default
doorlight.shadow.camera.far = 500; // default
doorlight.shadow.focus = 1; // default
scene.add(doorlight)

let doorMap = textureLoader.load('/textures/door.png')
doorMap.wrapS = THREE.RepeatWrapping
Expand All @@ -92,7 +90,7 @@ class RelaxingRain extends Place {
doorBump.repeat.set(1,1)

var door = new Character( new THREE.BoxGeometry( 0.02,0.8,0.3 ), new THREE.Box3(new THREE.Vector3(), new THREE.Vector3()), [255,255,255], new THREE.MeshPhysicalMaterial( { map: doorMap, bumpScale: 0.01, bumpMap: doorBump }) )
door.move(spotlight2.position.x+0.05,spotlight2.position.y+0.354,spotlight2.position.z-0.08)
door.move(doorlight.position.x+0.05,doorlight.position.y+0.354,doorlight.position.z-0.08)
door.mesh.rotation.set(0,0,0)
// door.mesh.castShadow = true
// door.mesh.receiveShadow = true
Expand Down Expand Up @@ -196,27 +194,23 @@ class RelaxingRain extends Place {
charqfgf20fm3nd2.mesh.receiveShadow = true
scene.add( charqfgf20fm3nd2.mesh )
characters[charqfgf20fm3nd2.mesh.id] = charqfgf20fm3nd2
console.log( 'its ', charqfgf20fm3nd2.mesh.id )


// da blox
var box
var boxPositions = []
let bp


for(var a=0; a<7;a++){
for(var b=0; b<7;b++){
for(var c=0; c<7;c++){
bp = {}
bp["a"] = a * 0.1 - 0.092
bp["b"] = b * 0.1 + 0.4 + FLOOR
bp["c"] = c * 0.1 - 1.042
boxPositions.push( bp )
}
}
}

// // da blox
// var box
// var boxPositions = []
// let bp

// for(var a=0; a<7;a++){
// for(var b=0; b<7;b++){
// for(var c=0; c<7;c++){
// bp = {}
// bp["a"] = a * 0.1 - 0.092
// bp["b"] = b * 0.1 + 0.4 + FLOOR
// bp["c"] = c * 0.1 - 1.042
// boxPositions.push( bp )
// }
// }
// }

// table
var charctw2g1t5rg5 = new Character( new THREE.BoxGeometry( 0.3100000000000002,0.39000000000000026,0.34000000000000025 ), new THREE.Box3(new THREE.Vector3(), new THREE.Vector3()), [110,110,110], new THREE.MeshStandardMaterial( { map: tableMap, bumpScale: 0.8, bumpMap: tableMapB}) )
Expand Down Expand Up @@ -387,19 +381,19 @@ class RelaxingRain extends Place {
let brightness = 1
// reused for rain
let pt,x,y,z
for(var q=0; q<12; q++){

for(var q=0; q<16; q++){

starsGeo = new THREE.Geometry();
numStars = 500 + Math.floor( Math.random() * 500)
numStars = 200 + Math.floor( Math.random() * 200)
for(let i=0;i<numStars;i++) {
// x = Math.random() * 200 - 100
// y = Math.random() * 200 - 100
// z = Math.random() * 200 - 100

pt = util.randomPointAway(128,4)

star = new THREE.Vector3( pt[0],pt[1],pt[2] )
starsGeo.vertices.push(star);
starsGeo.vertices.push(star)
}
let starsMaterial = new THREE.PointsMaterial({
color: util.rgbToHex(starColor[0],starColor[1],starColor[2]),
Expand All @@ -426,7 +420,8 @@ class RelaxingRain extends Place {
for(var i=0; i<16; i++){
pg = new THREE.SphereGeometry(0.1+Math.random()/2, 32, 32)

pc = util.randomHex(180)
pc = util.randomHex(99)
// pm = new THREE.MeshStandardMaterial({emissive: pc, color: pc})
pm = new THREE.MeshBasicMaterial({color: pc})

p = new THREE.Mesh(pg,pm)
Expand All @@ -438,17 +433,16 @@ class RelaxingRain extends Place {
// p.position.set(0,0,0)
pgroup.add(p)


gpscale = Math.random() * 1.8
gpopac = 0.8/gpscale

pm = new THREE.MeshBasicMaterial({blending: THREE.AdditiveBlending, transparent: true, opacity: gpopac, color: util.randomHex(255) })
pc = util.randomHex(99)
pm = new THREE.MeshBasicMaterial({color: pc})
gp = new THREE.Mesh(pg, pm)
gp.scale.set(gpscale,gpscale,gpscale)
gp.position.set(p.position.x,p.position.y,p.position.z)
// p.position.set(0,0,0)
pgroup.add(gp)

}

this.planets = pgroup
Expand All @@ -475,7 +469,7 @@ class RelaxingRain extends Place {
}

let rainMaterial = new THREE.PointsMaterial({
color: "#777799",
color: "#111122",
size: 0.05,
// opacity: 0.2
})
Expand Down Expand Up @@ -605,7 +599,7 @@ class RelaxingRain extends Place {


// needs to be laoded here because it uses musicPlayer in its click actions
let rempos = new THREE.Vector3(-0.082,FLOOR+0.5,-0.98)
let rempos = new THREE.Vector3(-0.082,FLOOR+0.5,-0.88)
this.remote = new Remote(rempos)
this.characters[this.remote.mesh.id] = this.remote
scene.add(this.remote.mesh)
Expand Down Expand Up @@ -923,12 +917,13 @@ class RelaxingRain extends Place {

if(this.stars){
// slowly rotate the star field, just like mom used to make!
// this.stars.rotation0.x += 0.00001
// this.stars.rotation.x += 0.00001

for(var i=0; i<this.stars.length; i++){
// this.stars[i].rotation.x += 0.00001
this.stars[i].rotation.x += 0.00006 * this.starSpeed
}
// this.stars.rotation.x += 0.00006 * this.starSpeed
}
if(this.planets){
this.planets.rotation.x += 0.00008 * this.starSpeed
Expand All @@ -946,7 +941,7 @@ class RelaxingRain extends Place {
if(Math.random() > 0.9995){
this.thunderTimer.reset()
let randomThunderName = this.randomThunderName()
console.log( 'thunder now' )
// console.log( 'thunder now' )
// reposition each time
this.sounds[randomThunderName].move(Math.random()*3, 3.4, Math.random()*3)

Expand Down

0 comments on commit 20c4732

Please sign in to comment.