Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

3D issue

in Codea Craft Posts: 1,865

All,

Anyone know why the following code displays an error but textures the model, whereas if you omit the *scale from the buildModel() no error is shown but the model is not textured?


function setup() -- scale = vec3(0.1,0.1,0.1) mod = { asset.builtin.Blocky_Characters.Man } scene = craft.scene() -- Setup camera and lighting scene.ambientColor = color(61, 61, 61, 255) scene.sun:get(craft.light).intensity = 1.0 scene.sun.rotation = quat.eulerAngles(-45, 125, 0) scene.sky.active = false viewer = scene.camera:add(OrbitViewer, vec3(0,0,0), 75, 10, 200) buildModel() end function update(dt) -- scene:update(dt) end function draw() -- This sets a dark background color update(DeltaTime) scene:draw() collectgarbage() end function buildModel() -- -- output.clear() ent=scene:entity() ent.model = craft.model(mod[1]) ent.scale = vec3(1,1,1)*scale ent.material = craft.material(asset.builtin.Materials.Standard) ent.position=vec3(0,0,0) end
Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 8,671

    I don’t know why scale causes an error, but the below code works. I change scale to .1 instead of a vec3 and commented out the material line.

    function setup()
        --
        scale = .1      --vec3(0.1,0.1,0.1)
        mod = {
        asset.builtin.Blocky_Characters.Man
        }
        scene = craft.scene()
        -- Setup camera and lighting
        scene.ambientColor = color(61, 61, 61, 255)
        scene.sun:get(craft.light).intensity = 1.0
        scene.sun.rotation = quat.eulerAngles(-45, 125, 0)
        scene.sky.active = false
        viewer = scene.camera:add(OrbitViewer, vec3(0,0,0), 75, 10, 200)
        buildModel()
    end
    
    function update(dt)
        --
        scene:update(dt)
    end
    
    function draw()
        -- This sets a dark background color
        update(DeltaTime)
        scene:draw()
        collectgarbage()
    end
    
    function buildModel()
        --  --
        output.clear()
        ent=scene:entity()
        ent.model = craft.model(mod[1])
        ent.scale = vec3(1,1,1)*scale
        --ent.material = craft.material(asset.builtin.Materials.Standard)
        ent.position=vec3(0,0,0)
    end
    
  • Posts: 565

    @Bri_G in buildModel the ent.scale is already a vec3, so scale should be just a single number not a vec3.

    The model already has multiple materials assigned. when you use ent.material you override those with a single material that does not have any colour assigned.

  • edited October 27 Posts: 1,865

    @dave1707 @piinthesky - thanks for the feedback, I tried scale set at 1 and 0.1 before switching to the vec3() but there were other issues firing up errors. The main problem was the ent.material issue. Thanks for that.

    Another problem I have must be related to the viewer setup for the camera. Using the corrected code above it still exists. I use the slider to scale the model but you can pinch and expand to change scale - I get touch errors sometimes when I do that. Have you experienced that?

    I’m going to try the other camera option to see if that eliminates it. Thanks again.

Sign In or Register to comment.