@SugarRay
I assume you mean stuff like objects keeping their current world position when changing parents. That shouldn’t be too hard, I just need to update the local transform whenever a parent change occurs to keep it in the same place
I have got support for animation import and skinned meshes:
https://twitter.com/johntwolives/status/1517814624225095680?s=20&t=cCcJo4FSx6ZzE7FJFF_GXA
I also did an experiment to blend between idle and walking animations (i.e. a blend tree):
function setup()
scn = scene.default3d()
scn.camera:add(camera.rigs.orbit)
cam = scn.camera:get(camera)
msh = mesh.read(asset.Idle)
anims = msh.animations
idle = anims[1]
walking = mesh.read(asset.Walking).animations[1]
running = mesh.read(asset.Running).animations[1]
model = scn:entity()
model.y = -0.5
model:add(msh)
model.meshMaterial.emissive = vec4(0,0,0,0)
local zero = vec3(0, 0, 0)
local x = vec3(1, 0, 0) * .25
local y = vec3(0, 1, 0) * .25
local z = vec3(0, 0, 1) * .25
-- Draw joints
function model.draw(entity)
style.stroke(255).strokeWidth(5)
matrix.push().reset()
entity:visitPreOrder(function(b)
local v = b:transformPoint(zero)
local vx = b:transformPoint(x)
local vy = b:transformPoint(y)
local vz = b:transformPoint(z)
style.stroke(255, 0, 0)
gizmos.line(v, vx)
style.stroke(0, 255, 0)
gizmos.line(v, vy)
style.stroke(0, 0, 255)
gizmos.line(v, vz)
end)
matrix.pop()
end
parameter.number("Speed", 0, 1, 0)
-- Basic Animation Blending
local t1 = 0
local t2 = 0
function model:update(dt)
local d1 = walking.duration
local d2 = running.duration
local d3 = math.lerp(d1, d2, Speed)
local r1 = d3 / d1
local r2 = d3 / d2
walking:apply(self, t1 % d1)
running:apply(self, t2 % d2, Speed)
t1 = t1 + dt / r1
t2 = t2 + dt / r2
end
ground = scn:entity("Ground")
ground:add(mesh.box(1,0.1,5))
ground.y = -0.6
end
function draw()
scn:draw()
matrix.ortho()
style.fontSize(30)
style.fill(255).stroke(6).strokeWidth(4)
style.textAlign(CENTER | TOP)
text("Codea Animation Blending Test", WIDTH/2 + 100, HEIGHT - 50)
end
Also experimenting with the ability to create animations directly:
function setup()
-- Do your setup here
anim = animation()
ch = anim:addChannel("path/to/entity<transform>.position", 1)
ch:addKey(0, 0.0)
ch:addKey(1, 1.0)
ch:addKey(2, 0.0)
ch:addKey(3, 0.5)
ch:addKey(5, 0.0)
print(ch.length)
print(ch.duration)
print(ch:evaluate(1.0, true))
end
Entity has forward
which returns the world space forward vector:
https://johntm.github.io/Codea4-Docs/api/entity.html