Skip to content

Commit

Permalink
Use real entity height and width (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karang authored Feb 21, 2021
1 parent e4559d2 commit 9c53fc0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions viewer/lib/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ const THREE = require('three')

function getEntityMesh (entity) {
if (entity.type === 'player') {
const geometry = new THREE.BoxGeometry(0.6, 1.8, 0.6)
geometry.translate(0, 0.9, 0)
const geometry = new THREE.BoxGeometry(entity.width, entity.height, entity.width)
geometry.translate(0, entity.height / 2, 0)
const material = new THREE.MeshBasicMaterial({ color: 0x0000ff })
const cube = new THREE.Mesh(geometry, material)
return cube
} else if (entity.type === 'object') {
const geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2)
geometry.translate(0, 0.1, 0)
const geometry = new THREE.BoxGeometry(entity.width, entity.height, entity.width)
geometry.translate(0, entity.height / 2, 0)
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 })
const cube = new THREE.Mesh(geometry, material)
return cube
}
// g(entity.type)
const geometry = new THREE.BoxGeometry(1, 1, 1)
geometry.translate(0, 0.5, 0)
const geometry = new THREE.BoxGeometry(entity.width, entity.height, entity.width)
geometry.translate(0, entity.height / 2, 0)
const material = new THREE.MeshBasicMaterial({ color: 0xff00ff })
const cube = new THREE.Mesh(geometry, material)
return cube
Expand Down
4 changes: 2 additions & 2 deletions viewer/lib/worldView.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WorldView extends EventEmitter {
this.listeners = {
// 'move': botPosition,
entitySpawn: function (e) {
worldView.emitter.emit('entity', { id: e.id, type: e.type, pos: e.position })
worldView.emitter.emit('entity', { id: e.id, type: e.type, pos: e.position, width: e.width, height: e.height })
},
entityMoved: function (e) {
worldView.emitter.emit('entity', { id: e.id, pos: e.position })
Expand Down Expand Up @@ -49,7 +49,7 @@ class WorldView extends EventEmitter {
for (const id in bot.entities) {
const e = bot.entities[id]
if (e !== bot.entity) {
this.emitter.emit('entity', { id: e.id, type: e.type, pos: e.position })
this.emitter.emit('entity', { id: e.id, type: e.type, pos: e.position, width: e.width, height: e.height })
}
}
}
Expand Down

0 comments on commit 9c53fc0

Please sign in to comment.