In Codea 4, mesh can load GLTF animation, here is a demo

Sure, the fbx version will probably work (it depends if the format can express double sided materials). Even if a model format doesn’t support some kind of feature like this, I’ve added a way to do this manually:

function setup()
    scn = scene.default3d()
    
    local orbit = scn.camera:add(camera.rigs.orbit)
    orbit.distance = 50
    orbit.angles.x = 45
    orbit.angles.y = 45
    
    local model = scn:entity()
    model:add(mesh.read(asset.Egypt))
    
    -- Set all materials to be double sided
    for i = 1, model.materialCount do
        model:getMaterial(i).doubleSided = true            
    end
    
    scene.main = scn 
end

So you can iterate through all the materials in a given model and change them to be double sided. This should be available in the next beta

Thanks so much, @John! I look forward to the next release.

Happy holidays and upcoming new year. :slight_smile:

oooh, does this mean we can set stuff for back vertices like…

mesh.backVertices = vertices2
mesh.backColors = colors2
mesh.backTexCoords = texCoords2
mesh.backTexture = texture2

??? I could really use that!

What would back vertices be? You could definitely create a custom shader with separate backface textures and colours. This isn’t built-in though.

oh…yeah, that doesn’t make sense.
that’s just me messing up because it was late and I wasn’t paying enough attention.
I’d really love if the other three were available per default though.
how to write shaders myself still eludes me.

Here’s an example of a double sided material using shader.builder, you could theoretically put anything on either side:

function setup()
    print("Hello World!")
    
    scn = scene.default3d()
    scn.camera:add(camera.rigs.orbit)
    scene.main = scn
    
    quad = scn:entity()
    quad:add(mesh.plane())
    
    -- Build a double sided material that shows a different color on each side
    doubleSided = material(
        shader.builder()
            :lit()
            :doubleSided(true)
            :material(
            [[
                material.baseColor = gl_FrontFacing ? vec4(0,0,1,1) : vec4(1,0,0,1);
            ]])
        :build())
    quad.material = doubleSided
end
1 Like

oh cool! thank you for the example!

wait but … there’s nothing in draw() yet this works!
just everything added to a scene is automatically updated and drawn?
can you also manually set when(and if) the scene is updated and drawn?
like what if you want to draw a scene to an image and draw that image in another scene or something…
oh…all of the camera code is elsewhere and that is doing the drawing step…right?

If you are using a scene for your drawing/updating you can just use scene.main = scn to auto draw/update everything. You can still have a draw() and update() method, but they are processed afterwards. You can do it either way, I just think this is cleaner. The camera.rigs.orbit is just a built-in script component you can use for a simple camera setup

I want to get around to updating the documentation to include all the hidden goodies, life is just busy sometimes you know?

@John - wow, from so little code, that’s amazing. V4 looks phenomenal.

Couple of questions - is the skybox you are using there part of the default scene ?
Can you add your own scene skybox as part of the camera setup in this?

I like the idea that you can build up the scene independently allowing the coder to concentrate on the action. Also the ease of definition of back faces.

@Bri_G Yes you can set the background to something else. Right now it supports HDRI images which you can download from the net for free (HDRIs • Poly Haven) from various sites. You can set the background using scn.sky= assetKey|image|color (scene - Codea 4.0 documentation). The default 3D scene comes with a camera, directional sun light and a HDRI background already set up. You can create your own scenes by adding those things

function setup()
    scn = scene()
    scene.main = scn

    scn:entity("Camera"):add(camera)
    scn:entity("Sun"):add(light.directional())
end

Lights can actually be used independently of scenes, so that’s why you construct a new one and add it to the entity. I might change the API if that’s too confusing. Spot and point lights are currently unavailable until the renderer supports them properly

@John - thanks for the feedback, I’ve actually used HDRI images before after reading one of your posts. Gives me the opportunity to play with V4 again. Thanks again.

@John, a member on a different forum gave me some more information on this problem. He suggested that the reason that some walls were invisible in one engine and not in other viewers is that some of the face normals were inverted. Sure enough, when I flipped some of the faces in blender and then imported the model, the walls appeared. It seems that when walls with normals are inverted and some engines “automatically” back-cull, they inadvertently end up not-rendering frontward facing walls. Perhaps Codea 3 also automatically back-culls? Blender’s default apparently is not to back-cull so the walls always show up even if the normals are inverted. I wonder if the reason Codea 4 shows them is that Codea 4 also defaults to no back-culling? Thanks.