logs in console, caching in getAgentProps, console createAgent independent of GUI
This commit is contained in:
@@ -2,8 +2,7 @@ class KeyframeView extends WindozDomContent {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
Object.assign(this, app.helpers.activeAttributes)
|
||||
Object.assign(this, app.helpers.formBuilder)
|
||||
Object.assign(this, app.helpers.activeAttributes, app.helpers.formBuilder, app.helpers.kfConsole)
|
||||
}
|
||||
|
||||
DOMContentFocused(options) {
|
||||
@@ -65,67 +64,6 @@ class KeyframeView extends WindozDomContent {
|
||||
this.currentlySelectedAid = null
|
||||
}
|
||||
|
||||
async execCommand(event){
|
||||
console.log('cmd:', this.outputs.commands)
|
||||
if(this.outputs.commands.value.trim()=='\\help'){
|
||||
this.outputs.results.innerHTML += await app.Assets.loadHtml({ name: 'help/KFconsoleHelp.html' })
|
||||
} else if(this.outputs.commands.value.trim()=='\\clear'){
|
||||
this.outputs.results.innerHTML = ''
|
||||
} else {
|
||||
this.outputs.results.innerHTML += await this.evalCmd(this.outputs.commands.value)
|
||||
}
|
||||
const lines = this.outputs.results.querySelectorAll('div.line')
|
||||
if(lines.length > 100) {
|
||||
for(let i=0; i<(lines.length-100); i++) lines[i].remove()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async evalCmd(code){
|
||||
const api = {
|
||||
newAgent: async (type, properties) => {
|
||||
if(Array.from(this.outputs.agentsSelector.options).find(item => item.value==type)){
|
||||
this.outputs.agentsSelector.value = type
|
||||
await this.onChangeAgent()
|
||||
const defaultValues = this.getFieldsValues('div[data-output="agentProperties"]')
|
||||
return(await this.newAgent(type, { ...defaultValues, ...properties })) //TODO: deepMerge
|
||||
} else {
|
||||
throw(`Invalid agent type: ${type}`)
|
||||
}
|
||||
},
|
||||
removeAgent: (aid) => {
|
||||
|
||||
},
|
||||
updateAgent: (aid, properties) => {
|
||||
|
||||
},
|
||||
}
|
||||
try {
|
||||
const fn = new Function(...Object.keys(api), `
|
||||
return(
|
||||
(async () => {
|
||||
const logs = []
|
||||
const log = (item) => { logs.push(item) }
|
||||
${code}
|
||||
return(logs)
|
||||
})()
|
||||
)
|
||||
`)
|
||||
|
||||
const res = await fn(...Object.values(api))
|
||||
return(
|
||||
'<div class="line">'+
|
||||
res.map(item => {
|
||||
if(typeof(item) == 'object') return(JSON.stringify(item))
|
||||
return(item)
|
||||
}).join('</div><div class="line">')
|
||||
+'</div>'
|
||||
)
|
||||
} catch (err) {
|
||||
return(`<div class="error">${err.name}: ${err.message}</div>`)
|
||||
}
|
||||
}
|
||||
|
||||
async onChangeAgent(event){
|
||||
if(this.outputs.agentsSelector.value) this.agentPreview.setAgent(this.outputs.agentsSelector.value)
|
||||
if(!this.outputs.agentsSelector.value) return
|
||||
@@ -134,7 +72,7 @@ class KeyframeView extends WindozDomContent {
|
||||
|
||||
} else {
|
||||
this.currentAgentType = await this.models.agents.getProperties(this.outputs.agentsSelector.value)
|
||||
this.fillAgentProperties('', this.currentAgentType.atp_props)
|
||||
this.fillAgentProperties('', this.currentAgentType)
|
||||
// Deselect any on-scene selection
|
||||
if(this.currentlySelectedAid){
|
||||
this.kfArena.clearHighlight3DObj(this.kfArena.scene.getObjectByName(this.currentlySelectedAid), this.kfArena.scene)
|
||||
@@ -191,9 +129,10 @@ class KeyframeView extends WindozDomContent {
|
||||
this.kfArena.removeAgent(this.currentlySelectedAid)
|
||||
}
|
||||
|
||||
newAgent(aType, AgentValues){
|
||||
async newAgent(aType, AgentValues){
|
||||
const aid = crypto.randomUUIDv7()
|
||||
this.kfArena.addAgent(aType, aid, this.currentAgentType.atp_props , AgentValues)
|
||||
const agentProps = await this.models.agents.getProperties(aType)
|
||||
this.kfArena.addAgent(aType, aid, agentProps, AgentValues)
|
||||
return(aid)
|
||||
}
|
||||
|
||||
@@ -291,3 +230,19 @@ class KeyframeView extends WindozDomContent {
|
||||
|
||||
app.registerClass('KeyframeView', KeyframeView)
|
||||
|
||||
//TODO :
|
||||
/*
|
||||
|
||||
API update
|
||||
API remove
|
||||
API listAgentTypes
|
||||
if unsavec changes in scene => confirm before reloading
|
||||
|
||||
|
||||
Bugs
|
||||
|
||||
=> reselect same scene resets it
|
||||
=> Added with API = non-selectable
|
||||
=> loaded from KF => loosing internal props
|
||||
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as THREE from 'three'
|
||||
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
|
||||
import * as TWEEN from 'three/examples/jsm/libs/tween.module.js'
|
||||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
||||
|
||||
export class kfArena{
|
||||
|
||||
@@ -21,7 +22,7 @@ export class kfArena{
|
||||
initScene(){
|
||||
// Scene
|
||||
this.scene = new THREE.Scene()
|
||||
|
||||
|
||||
// Camera
|
||||
this.camera = new THREE.PerspectiveCamera(75, this.canvasEl.clientWidth / this.canvasEl.clientHeight, 0.1, 1000)
|
||||
this.camera.position.set(3, 3, 5)
|
||||
@@ -30,11 +31,16 @@ export class kfArena{
|
||||
this.camera.layers.enable(2)
|
||||
|
||||
// Lights
|
||||
const light = new THREE.DirectionalLight(0xffffff, 1)
|
||||
light.position.set(5, 5, 5)
|
||||
this.scene.add(light)
|
||||
this.scene.add(new THREE.AmbientLight(0xffffff, .4))
|
||||
const dLight1 = new THREE.DirectionalLight(0xffffff, 1.5)
|
||||
dLight1.position.set(5, 5, 5)
|
||||
this.scene.add(dLight1)
|
||||
const dLight2 = new THREE.DirectionalLight(0xffffff, 1.5)
|
||||
dLight2.position.set(-5, -5, 5)
|
||||
this.scene.add(dLight2)
|
||||
|
||||
this.scene.add(new THREE.AmbientLight(0xffffff, 1))
|
||||
|
||||
|
||||
this.grid = new THREE.GridHelper(this.sceneSize.x, this.sceneSize.x, 0x8888AA, 0x8888AA)
|
||||
this.grid.layers.set(1)
|
||||
this.scene.add(this.grid)
|
||||
@@ -57,10 +63,6 @@ export class kfArena{
|
||||
this.scene.add(this.axes)
|
||||
|
||||
this.renderer = new THREE.WebGLRenderer({ antialias: true, canvas: this.canvasEl, stencil: true })
|
||||
// this.renderer.physicallyCorrectLights = true
|
||||
// this.renderer.outputColorSpace = THREE.SRGBColorSpace
|
||||
// this.renderer.toneMapping = THREE.ACESFilmicToneMapping
|
||||
// this.renderer.toneMappingExposure = 1
|
||||
|
||||
this.canvasEl.addEventListener('click', this.onSceneClick.bind(this))
|
||||
}
|
||||
@@ -74,6 +76,7 @@ export class kfArena{
|
||||
TWEEN.update()
|
||||
this.animateHighlight3DObj()
|
||||
const resized = this.resizeRendererToDisplaySize()
|
||||
|
||||
this.renderer.render(this.scene, this.camera)
|
||||
requestAnimationFrame(this.render.bind(this))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user