speed vectors + better scene selection
This commit is contained in:
@@ -42,7 +42,7 @@ export class kfArena{
|
||||
// Base plane
|
||||
const planeGeo = new THREE.PlaneGeometry(100, 100)
|
||||
const planeMat = new THREE.MeshBasicMaterial({
|
||||
color: 0x8888aa,
|
||||
color: 0x000055,
|
||||
opacity: 0.3,
|
||||
transparent: true, // needed for opacity < 1 to take effect
|
||||
side: THREE.DoubleSide
|
||||
@@ -115,10 +115,14 @@ export class kfArena{
|
||||
normalizedPointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1
|
||||
this.raycaster.setFromCamera(normalizedPointer, this.camera)
|
||||
const intersects = this.raycaster.intersectObjects(this.scene.children, true)
|
||||
|
||||
if (intersects.length > 0) {
|
||||
const hit = this.getNamedParent(intersects[0].object)
|
||||
if(hit) this.onclickAgent(hit)
|
||||
let hit = null
|
||||
for(let i=0; i<intersects.length; i++){
|
||||
hit = this.getNamedParent(intersects[i].object)
|
||||
if((!hit) || (!hit.name)) continue
|
||||
if(Object.keys(this.agents).includes(hit.name)) break
|
||||
}
|
||||
if(hit && Object.keys(this.agents).includes(hit.name)) this.onclickAgent(hit)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,9 +136,17 @@ export class kfArena{
|
||||
const agentObj = this.agentFromJSON(aid, agentSprite.asp_3d)
|
||||
|
||||
agentObj.position.set(values.position.x, values.position.z, values.position.y )
|
||||
//TODO Speed vector
|
||||
this.scene.add(agentObj)
|
||||
|
||||
//Speed vector
|
||||
const objAboveHead = this.getObjectTopCenter(this.scene.getObjectByName(aid))
|
||||
this.createArrow(objAboveHead, {
|
||||
x: values.speed.x,
|
||||
y: values.speed.z,
|
||||
z:values.speed.y },
|
||||
`_speed_${aid}`,
|
||||
0xff0055)
|
||||
|
||||
|
||||
this.agents[aid] = {
|
||||
type: typeId,
|
||||
props: properties,
|
||||
@@ -143,16 +155,39 @@ export class kfArena{
|
||||
}
|
||||
|
||||
removeAgent(aid){
|
||||
const obj3d = scene.getObjectByName(aid)
|
||||
const obj3d = this.scene.getObjectByName(aid)
|
||||
this.scene.remove(obj3d)
|
||||
if(aid in this.agents) delete(this.agents[aid])
|
||||
}
|
||||
|
||||
moveAgent(aid, position){
|
||||
const obj3d = this.scene.getObjectByName(aid)
|
||||
new TWEEN.Tween(obj3d.position)
|
||||
.to({ x: Number(position.x),
|
||||
y: Number(position.z),
|
||||
z: Number(position.y),
|
||||
}, 500)
|
||||
.easing(TWEEN.Easing.Quadratic.InOut)
|
||||
.start()
|
||||
}
|
||||
|
||||
changeAgentSpeed(aid, speed){
|
||||
const objName = `_speed_${aid}`
|
||||
const obj3d = this.scene.getObjectByName(objName)
|
||||
if(obj3d) this.scene.remove(obj3d)
|
||||
const objAboveHead = this.getObjectTopCenter(this.scene.getObjectByName(aid))
|
||||
this.createArrow(objAboveHead, {
|
||||
x: speed.x,
|
||||
y: speed.z,
|
||||
z: speed.y },
|
||||
objName,
|
||||
0xff0055)
|
||||
}
|
||||
|
||||
reloadAgents(agents){
|
||||
for(const aid in this.agents){
|
||||
this.removeAgent(aid)
|
||||
}
|
||||
console.log('====>', agents)
|
||||
for(const agent of agents){
|
||||
this.addAgent(agent.ekfs_atp_id, agent.aid, agent.props, {...agent.gps_values, ...agent.store_values})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user