I found that the mesh increase in Codea 4 supports a lot of file types, so I tried gltf. However, in this routine there is only a simple load and no animation, because I know very little about gltf. hopefully @John will provide some sample code, such as to get the roles moving.
These gltf are from the app: Anima Toon, it is very easy to control the character`s actions.
The code is very short, However, I suggest you download the project file, because it includes the GLTF file.
function setup()
-- 使用基本场景的默认镜头
scn = scene.default3d()
scn.sky = nil
-- scn.camera.farPlane =5000
cam = scn.camera:get(camera)
cam.farPlane = 50000
print("cam: ", cam.farPlane)
-- create a sun entity and add a directional light to it
sunEntity = scn:entity("sun")
sun = sunEntity:add(light.directional(vec3(-1,-1,-1)))
sun.color = color(233, 150, 80)
-- sun.clearColor = color(233, 150, 80)
sun.intensity = 0.05
-- sun.direction =vec3(-100,-100,-100)
sun.castShadows = false
rig = scn.camera:add(camera.rigs.orbit)
rig.distance = 50
rig.angles.x = 25
rig.angles.y = 75
-- 用于地面:新建 material.lit() 会自动打开 阴影,如何关闭?
checkers = material.lit()
checkers.map = image.read(asset.builtin.Blocks.Brick_Grey)
checkers.color = color(243, 243, 242)
checkers.scaleOffset = vec4(0.125, 0.125, 0.0, 0.0)
checkers.roughness = 0.5
-- 地面
ground = scn:entity("ground")
ground:add(mesh.box(50, 0.1, 50))
ground.y = -0.05
ground.material = checkers
robot = scn:entity("robot")
robot:add(mesh.read(asset.builtin.Blocky_Characters.Robot))
robot.scale = vec3(.5,.5,.5)
robot.position = vec3(10,0,-10)
robot.material = checkers
-- load Run.gltf (1 action)
myChar = scn:entity("myChar")
myChar:add(mesh.read(asset.run))
-- myChar.material = checkers
myChar.position = vec3(0,0.5,0)
for k,v in pairs(myChar.mesh.animations) do
print(k,v)
end
-- load DogWalk.gltf (1 action)
myPet = scn:entity("myPet")
myPet:add(mesh.read(asset.DogWalk))
-- myPet.material = checkers
myPet.position = vec3(0,0.5,-10)
-- load DogWalk.gltf (3 actions)
myPet1 = scn:entity("myPet1")
myPet1:add(mesh.read(asset.ExportDog))
-- myPet.material = checkers
myPet1.position = vec3(-5,0.6,-12)
scene.main = scn
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
rig.angles.y = time.elapsed*30
end
C4AnimationGltf.zip (404.7 KB)
The demo video:
The original animation: