speed vectors move with aagent
This commit is contained in:
@@ -180,24 +180,30 @@ app.helpers.helpers3D = {
|
||||
return obj
|
||||
},
|
||||
|
||||
createArrow(origin, vector, name='', color = 0xffaa00, headLength = 0.25, headWidth = 0.1) {
|
||||
createArrow(origin, vector, options){
|
||||
options.name = options.name || ''
|
||||
options.color = options.color || 0xffaa00
|
||||
options.headLength = options.headLength || 0.25
|
||||
options.headWidth = options.headWidth || 0.1
|
||||
options.scale = options.scale || 1
|
||||
//const from = new THREE.Vector3(origin.x, origin.y, origin.z)
|
||||
const dir = new THREE.Vector3(vector.x, vector.y, vector.z).normalize()
|
||||
const length = Math.sqrt(vector.x**2 + vector.y**2 + vector.z**2)
|
||||
let length = Math.sqrt(vector.x**2 + vector.y**2 + vector.z**2)
|
||||
if(length==0) return(null)
|
||||
const arrow = new THREE.ArrowHelper(dir, origin, length, color, headLength, headWidth)
|
||||
length *= options.scale
|
||||
const arrow = new THREE.ArrowHelper(dir, origin, length, options.color, options.headLength, options.headWidth)
|
||||
|
||||
// Optional: add a subtle tube body for style
|
||||
const shaftGeo = new THREE.CylinderGeometry(0.02, 0.02, length - headLength, 16)
|
||||
const shaftMat = new THREE.MeshStandardMaterial({ color, metalness: 0.3, roughness: 0.2 })
|
||||
const shaftGeo = new THREE.CylinderGeometry(0.02, 0.02, length - options.headLength, 16)
|
||||
const shaftMat = new THREE.MeshStandardMaterial({ color: options.color, metalness: 0.3, roughness: 0.2 })
|
||||
const shaft = new THREE.Mesh(shaftGeo, shaftMat)
|
||||
shaft.position.copy(origin.clone().add(dir.clone().multiplyScalar((length - headLength) / 2)))
|
||||
shaft.position.copy(origin.clone().add(dir.clone().multiplyScalar((length - options.headLength) / 2)))
|
||||
shaft.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), dir)
|
||||
|
||||
const group = new THREE.Group()
|
||||
group.add(arrow)
|
||||
group.add(shaft)
|
||||
if(name) group.name = name
|
||||
if(options.name) group.name = options.name
|
||||
this.scene.add(group)
|
||||
return group
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user