ageent preview & select in KF editor

This commit is contained in:
STEINNI
2025-10-16 20:39:09 +00:00
parent 078f60ef51
commit 3912523b0a
14 changed files with 223 additions and 111 deletions
+6 -43
View File
@@ -1,10 +1,11 @@
import * as THREE from './three.module.js'
import { OrbitControls } from './OrbitControls.module.js'
import * as TWEEN from './tween.module.js'
import * as THREE from '../Three/three.module.js'
import { OrbitControls } from '../Three/OrbitControls.module.js'
import * as TWEEN from '../Three/tween.module.js'
export class Threetobus{
constructor(options){
Object.assign(this, app.helpers.helpers3D)
this._curEventsMapping = []
this._stagedEventsMapping = options.eventsMapping
this.sceneSize = options.sceneSize
@@ -214,47 +215,9 @@ export class Threetobus{
return(renderEngine)
}
agentFromJSON(id, desc){
let obj
if(desc.type === 'Mesh') {
const geom = new THREE[desc.geometry.type](...(desc.geometry.args || []))
const matType = desc.material.type
const matProps = { ...desc.material }
for (const key in matProps) {
if (key === 'type') continue
if (typeof matProps[key] === 'string' && THREE[matProps[key]] !== undefined) {
matProps[key] = THREE[matProps[key]]
}
}
// convert color strings like "0xffffaa" to numbers
if (typeof matProps.color === 'string' && matProps.color.startsWith('0x')) {
matProps.color = parseInt(matProps.color)
}
const mat = new THREE[matType](matProps)
obj = new THREE.Mesh(geom, mat)
} else if(desc.type === 'Group') {
obj = new THREE.Group()
} else {
throw new Error("Unknown type: " + desc.type)
}
// Apply transforms
if(desc.position) obj.position.set(...desc.position)
if(desc.rotation) obj.rotation.set(...desc.rotation)
if(desc.scale) obj.scale.set(...desc.scale)
// Recursively add children
if(desc.children) {
desc.children.forEach(childDesc => {
const childId = (childDesc.childSuffix) ? `${id}_${childDesc.childSuffix}` : ''
obj.add(this.agentFromJSON(childId, childDesc))
})
}
obj.name = id
createAgent(id, desc){
this.tweensRegistry[id] = { 'move': null, 'rotate': null }
return obj
return(this.agentFromJSON(id, desc))
}
smoothMove(options){