speed vectors + better scene selection
This commit is contained in:
@@ -94,4 +94,10 @@ app.helpers.formBuilder = {
|
||||
return(result)
|
||||
},
|
||||
|
||||
getFieldValue(rootSel, name){
|
||||
const comp = document.querySelector(`${rootSel} .formbuilder-field[name="${name}"]`)
|
||||
if(comp) return(comp.value)
|
||||
else return(null)
|
||||
},
|
||||
|
||||
}
|
||||
@@ -111,6 +111,17 @@ app.helpers.helpers3D = {
|
||||
box.getCenter(center) // world coords
|
||||
return center
|
||||
},
|
||||
|
||||
getObjectTopCenter(object, offset = 0.1) {
|
||||
object.updateWorldMatrix(true, true)
|
||||
const box = new THREE.Box3().setFromObject(object)
|
||||
const center = new THREE.Vector3()
|
||||
box.getCenter(center)
|
||||
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(object.quaternion).normalize()
|
||||
const height = box.max.y - box.min.y
|
||||
const top = center.clone().addScaledVector(up, height / 2 + offset)
|
||||
return top
|
||||
},
|
||||
|
||||
init3DHighlighter(options){
|
||||
if (!this.composer) {
|
||||
@@ -168,4 +179,26 @@ app.helpers.helpers3D = {
|
||||
}
|
||||
return obj
|
||||
},
|
||||
}
|
||||
|
||||
createArrow(origin, vector, name='', color = 0xffaa00, headLength = 0.25, headWidth = 0.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)
|
||||
if(length==0) return(null)
|
||||
const arrow = new THREE.ArrowHelper(dir, origin, length, color, headLength, 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 shaft = new THREE.Mesh(shaftGeo, shaftMat)
|
||||
shaft.position.copy(origin.clone().add(dir.clone().multiplyScalar((length - 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
|
||||
this.scene.add(group)
|
||||
return group
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user