Skip to content

Commit

Permalink
✨ Add google home leds
Browse files Browse the repository at this point in the history
  • Loading branch information
brunosimon committed Aug 31, 2021
1 parent d49eb8f commit a7c081d
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"stats.js": "^0.17.0",
"style-loader": "^3.0.0",
"three": "^0.130.1",
"tweakpane": "^3.0.5",
"webpack": "^5.42.1",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2",
Expand Down
12 changes: 12 additions & 0 deletions src/Experience/Experience.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as THREE from 'three'
import { Pane } from 'tweakpane'

import Time from './Utils/Time.js'
import Sizes from './Utils/Sizes.js'
import Stats from './Utils/Stats.js'
Expand Down Expand Up @@ -36,6 +38,7 @@ export default class Experience
this.sizes = new Sizes()
this.setConfig()
this.setStats()
this.setDebug()
this.setScene()
this.setCamera()
this.setRenderer()
Expand Down Expand Up @@ -90,6 +93,15 @@ export default class Experience
this.stats = new Stats(true)
}
}

setDebug()
{
if(this.config.debug)
{
this.debug = new Pane()
this.debug.containerElem_.style.width = '320px'
}
}

setScene()
{
Expand Down
100 changes: 100 additions & 0 deletions src/Experience/GoogleLeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import Experience from './Experience.js'

import * as THREE from 'three'

export default class GoogleLeds
{
constructor()
{
this.experience = new Experience()
this.resources = this.experience.resources
this.debug = this.experience.debug
this.scene = this.experience.scene
this.time = this.experience.time

// Debug
if(this.debug)
{
this.debugFolder = this.debug.addFolder({
title: 'googleLeds',
expanded: true
})
}

this.setModel()
}

setModel()
{
this.model = {}

this.model.items = []

const colors = ['#196aff', '#ff0000', '#ff5d00', '#7db81b']

// Texture
this.model.texture = this.resources.items.googleHomeLedMaskTexture

// Children
const children = [...this.resources.items.googleHomeLedsModel.scene.children]
children.sort((_a, _b) =>
{
if(_a.name < _b.name)
return -1

if(_a.name > _b.name)
return 1

return 0
})

console.log(children)

let i = 0
for(const _child of children)
{
const item = {}

item.index = i

item.color = colors[item.index]

item.material = new THREE.MeshBasicMaterial({
color: item.color,
transparent: true,
alphaMap: this.model.texture
})

item.mesh = _child
item.mesh.material = item.material
this.scene.add(item.mesh)

this.model.items.push(item)

// Debug
if(this.debug)
{
this.debugFolder
.addInput(
item,
'color',
{ view: 'color' }
)
.on('change', () =>
{
item.material.color.set(item.color)
})
}

i++
}
}

update()
{
for(const _item of this.model.items)
{
_item.material.opacity = Math.sin(this.time.elapsed * 0.002 - _item.index * 0.5) * 0.5 + 0.5
}
}
}
4 changes: 2 additions & 2 deletions src/Experience/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class Navigation
this.view.target.smoothing = 0.005
this.view.target.limits = {}
this.view.target.limits.x = { min: - 4, max: 4 }
this.view.target.limits.y = { min: 1, max: 4 }
this.view.target.limits.y = { min: 1, max: 6 }
this.view.target.limits.z = { min: - 4, max: 4 }

this.view.drag = {}
Expand Down Expand Up @@ -85,7 +85,7 @@ export default class Navigation
{
_event.preventDefault()

this.view.drag.alternative = _event.button === 2 || _event.ctrlKey || _event.shiftKey
this.view.drag.alternative = _event.button === 2 || _event.button === 1 || _event.ctrlKey || _event.shiftKey

this.view.down(_event.clientX, _event.clientY)

Expand Down
9 changes: 9 additions & 0 deletions src/Experience/World.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as THREE from 'three'
import Experience from './Experience.js'
import GoogleLeds from './GoogleLeds.js'

export default class World
{
Expand All @@ -16,6 +17,7 @@ export default class World
{
// this.setDummy()
this.setRoom()
this.setGoogleLeds()
}
})
}
Expand Down Expand Up @@ -56,12 +58,19 @@ export default class World
this.scene.add(directionalLight)
}

setGoogleLeds()
{
this.googleLeds = new GoogleLeds()
}

resize()
{
}

update()
{
if(this.googleLeds)
this.googleLeds.update()
}

destroy()
Expand Down
2 changes: 2 additions & 0 deletions src/Experience/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export default [
data: {},
items:
[
{ name: 'googleHomeLedMaskTexture', source: '/assets/googleHomeLedMask.png', type: 'texture' },
{ name: 'googleHomeLedsModel', source: '/assets/googleHomeLeds.glb', type: 'model' },
{ name: 'bakedTexture', source: '/assets/baked.jpg', type: 'texture' },
{ name: 'roomModel', source: '/assets/roomModel.glb' },
]
Expand Down
Binary file added static/assets/googleHomeLedMask.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 static/assets/googleHomeLeds.glb
Binary file not shown.

1 comment on commit a7c081d

@vercel
Copy link

@vercel vercel bot commented on a7c081d Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.