Skip to content

Commit

Permalink
'gltf'
Browse files Browse the repository at this point in the history
  • Loading branch information
foglabs committed Jan 26, 2021
1 parent 4eaf216 commit a01fc49
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 23 deletions.
3 changes: 1 addition & 2 deletions lib/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import {
Vector3,
VectorKeyframeTrack,
sRGBEncoding
} from "../../../build/three.module.js";
} from "./three.module.js";

var GLTFLoader = ( function () {

Expand Down Expand Up @@ -137,7 +137,6 @@ var GLTFLoader = ( function () {
onError( e );

} else {

console.error( e );

}
Expand Down
2 changes: 1 addition & 1 deletion lib/MusicPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class MusicPlayer extends Character {
this.album = droppedChar
}
}
this.tray = new Component( this, trayoffset, traygeo, [255,255,255], traymat, null, trayAction )
this.tray = new Component( this, trayoffset, traygeo, [150,0,150], traymat, null, trayAction )
scene.add(this.tray.mesh)

this.idle = true
Expand Down
76 changes: 65 additions & 11 deletions lib/RelaxingRain.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { Sound } from "./Sound.js"
import { MusicPlayer } from "./MusicPlayer.js"
import { GoBoard } from "./GoBoard.js"
import { Album } from "./Album.js"
import { util, textureLoader, scene } from "./main.js"
import { util, gltfLoader, textureLoader, scene } from "./main.js"

class RelaxingRain extends Place {
constructor(){

var backgroundHex = "#030312"
// var backgroundHex = "#FFFFFF"
// var backgroundHex = "#000000"
Expand Down Expand Up @@ -47,7 +48,8 @@ class RelaxingRain extends Place {
// spotlight2.shadow.mapSize.width = 1024*4
// spotlight2.shadow.mapSize.height = 1024*4
// spotlight2.position.set(-1,1.8,0)
// spotlight2.lookAt(1,-1,-2)
// spotlight2.lookAt(1,-1,2)
// scene.add(spotlight2)

// // light.shadow.mapSize.width = 512; // default
// // light.shadow.mapSize.height = 512; // default
Expand Down Expand Up @@ -297,14 +299,14 @@ class RelaxingRain extends Place {
sound5.move(Math.random()*3, 3.4, Math.random()*3)
sounds[sound5.name] = sound5

// let sound6 = new Sound("", "/sounds/freerelax-thunder6.mp3", 1, false, false)
// sound6.grabbable = false
// sound6.pushable = false
// sound6.move(Math.random()*3, 3.4, Math.random()*3)
// sounds[sound6.name] = sound6

super(backgroundHex, characters, floorObjects, sounds)



this.plants = {}
// carries our RelaxingRain 'this' when passed in as callback to model load
this.plantHandler=this.plantHandler.bind(this);


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

Expand Down Expand Up @@ -499,6 +501,47 @@ class RelaxingRain extends Place {
this.createAlbums()

this.goBoard = char24xq7w9ca9

// expect to get the fuckin mesh when we call this as imDone() below



let depth, lat
for(var i=0; i<10; i++){
depth = 0.4 + Math.random()/6
lat = i/6 - 0.8
if(Math.random() > 0.5){
this.loadModel('/models/pottedplant.glb', new THREE.Vector3(lat,1,depth), 0.06, this.plantHandler)

} else {
this.loadModel('/models/plant2.glb', new THREE.Vector3(lat,1.04,depth), 0.005, this.plantHandler)
}
}
}

plantHandler(mesh, position, scale){
console.log( 'I have received the payload?', mesh )

mesh.material.needsUpdate = true
mesh.material.color = new THREE.Color("#ffffff")
this.plants[mesh.id] = mesh
// this.plant.material = new THREE.MeshLambertMaterial({color: '#ffffff'})
scene.add(this.plants[mesh.id])

let sizeDiff = 1 + Math.random()/10
this.plants[mesh.id].scale.x = scale * sizeDiff
this.plants[mesh.id].scale.y = scale * sizeDiff
this.plants[mesh.id].scale.z = scale * sizeDiff
this.plants[mesh.id].position.set(position.x, position.y, position.z)
}


loadModel(path, position, scale, imDone){
// same pattern as Sound#loadSound - pass in callback so that we can use our Place scope after we get da model BITCH
gltfLoader.load(path, function(gltf){
let mesh = gltf.scene.children[0]
imDone(mesh, position, scale)
})
}

createAlbums(){
Expand Down Expand Up @@ -609,12 +652,23 @@ class RelaxingRain extends Place {

// change rainspin amount by random factor
if(Math.random() > 0.799){
this.rainSpinAmount += Math.random() * 0.000005 - 0.00000025
}

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

} else {
// normal speed change
this.rainSpinAmount += Math.random() * 0.000005 - 0.00000025
}
}
}

customHandle(){

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

this.clouds.forEach(p => {
p.rotation.z -= p.rotationSpeed
})
Expand Down
14 changes: 8 additions & 6 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { JunkPiece } from '/lib/JunkPiece.js'
import { Game } from '/lib/Game.js'
import { Pointer } from '/lib/Pointer.js'
// import { GLTFLoader } from '/v3/lib/GLTFLoader.js';
import { GLTFLoader } from '/lib/GLTFLoader.js';

var container
var camera, camGroup, scene, renderer
Expand All @@ -31,7 +31,8 @@

const textureLoader = new THREE.TextureLoader()
const audioLoader = new THREE.AudioLoader()
const listener = new THREE.AudioListener();
const gltfLoader = new GLTFLoader()
const listener = new THREE.AudioListener()

var markerJunkTimer = new Timer()
markerJunkTimer.start()
Expand Down Expand Up @@ -90,13 +91,15 @@
camx = camera.position.x
camy = camera.position.y
camz = camera.position.z
camera.lookAt(0,FLOOR,100)

camera.add( listener )

camGroup = new THREE.Group()
camGroup.add(camera)
scene.add(camGroup)

var plant
place = createPlace(RELAXINGRAIN)

// scene.background = new THREE.Color( '#330203' );
Expand Down Expand Up @@ -240,15 +243,14 @@
// just put da pointa where the controller is
pointer.move(controller.position.x, controller.position.y, controller.position.z)


if(pointer.grabbedId) {
// if its grabbed, carry it with the pointer
let conPos = controller.getWorldPosition()
place.characters[ pointer.grabbedId ].move(conPos.x, conPos.y, conPos.z)
// and rotate it
let objRot = controller.rotation
objRot.z *= 2
objRot.x *= 2
objRot.z *= 1.3
objRot.x *= 1.3
place.characters[ pointer.grabbedId ].mesh.setRotationFromEuler( objRot )


Expand Down Expand Up @@ -492,4 +494,4 @@

}

export { util, textureLoader, audioLoader, listener, pointer, scene, camGroup, place, game, controller }
export { util, gltfLoader, textureLoader, audioLoader, listener, pointer, scene, camGroup, place, game, controller }
5 changes: 5 additions & 0 deletions lib/plant class
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
plant class
generates a plantchunk
grows according some rules
dies according to some rules

Binary file added models/plant2.glb
Binary file not shown.
Binary file added models/pottedplant.glb
Binary file not shown.
11 changes: 8 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,25 @@ app.get('/lib/three.module.js', function(req, res){
})
app.get('/lib/:filename', function(req, res){
res.header('Content-Type', 'text/javascript')
console.log("filenammeme", req.params.filename)
console.log("libbo", req.params.filename)
res.sendFile(path.join(__dirname, 'lib', req.params.filename))
})
app.get('/textures/:filename', function(req, res){
res.header('Content-Type', 'image/jpg')
console.log("filenammeme", req.params.filename)
console.log("texture", req.params.filename)
res.sendFile(path.join(__dirname, 'textures', req.params.filename))
})

app.get('/sounds/:filename', function(req, res){
res.header('Content-Type', 'audio/mp3')
console.log("filenammeme", req.params.filename)
console.log("sound", req.params.filename)
res.sendFile(path.join(__dirname, 'sounds', req.params.filename))
})
app.get('/models/:filename', function(req, res){
res.header('Content-Type', 'model/gltf+json')
console.log("model", req.params.filename)
res.sendFile(path.join(__dirname, 'models', req.params.filename))
})



Expand Down
Binary file modified textures/stereo-tray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a01fc49

Please sign in to comment.