Codea 3.1 (208)

@dave1707 @Simeon - thanks for the replies I have dependencies which contain lists of assets in tables, usually setting a path up like -


path = "Dropbox:folder/"
path = asset.documents.Dropbox

The latter is what I have tried recently, then examples of use are:


rabbit = craft.model(path..model[num])

Where model is a table of filename strings with object names in. The old system works well. The new one doesn’t seem to work. Using the new asset system errors keep getting fired up. Using a single complete asset path, no table, models load fine - note no file type in asset path. That’s the same with the old system, no file type. I managed to get one file to load by appending .obj to the file string in the table but all others failed.

The other files all use the underscore character - a feature of Wavefront files. They are OK with the single complete asset path but not with the table concatenation method. Could these characters be the cause?

@dave1707 - I’ll give your format a try.

p.s. - please ignore code formatting above, added this on my Android phone and seems format code on the forum differently.

@Bri_G you need the full filename, including extension, to use the syntax you describe

If you want to get all models in your Dropbox (or any) folder, you can do something like

1:

models = {}

for _,k in pairs(asset.documents.Dropbox.all) do
    if k.type == MODELS then
        table.insert(models, k)
    end
end

Later on to load a model…

rabbit = craft.model(models[num])

2:

Or if you wanted static analysis to ensure files exist, you could do something like:

models = {
    asset.documents.Dropbox.rabbit,
    asset.documents.Dropbox.anotherModel,
    asset.documents.Dropbox.andSoOn
}
rabbit = craft.model(models[1])

Then Codea will let you know in the editor if any of those files doesn’t exist before you run your code

3:

You shouldn’t really need the .. concatenation operator unless you want to create a file that doesn’t exist yet. If you want to load an existing file it’s likely you already have the asset key stored for it, so you can just load that. But if you really want to use the .. syntax you can do it like this (though I’d recommend the first way)

models = {}

for _,k in pairs(asset.documents.Dropbox.all) do
    if k.type == MODELS then
        -- Here we insert the file name instead of the key
        table.insert(models, k.name)
    end
end

Later on to load a model…

rabbit = craft.model(asset.documents.Dropbox .. models[num])

(I don’t recommend that way, just store the keys instead and load them directly)

@Simeon - back on my Mac and sensible editing of web code again.

Thanks for the reply - and thanks for outlining the options that we have for using the new asset path system. I will try them all out - should make my old systeem well and truly redundant.

Thanks again.

@Simeon I just ran across something that worked before the asset change, but doesn’t work now. At least I can’t get it to work. I have a program where I read an image from the Dropbox folder and display it. If the image doesn’t exist in Dropbox then I do an http request to get it and put it there. What happens now is if the image isn’t in the Dropbox folder, it gives an error and stops the program so it isn’t able to do the http request.

@dave1707 - I have tried with a number of my models with the code from you and @Simeon but have run into problems. I think the problems are a feature of model integrity.Many of the models I use loaded with the old system but not the new. To check I loaded a number of non-textured models from the following website:

A 3D Object Format

They all loaded successfully. I have built a loader using the method I found to load reproducibly below. I have a few issues with this - firstly the code needs to destroy one model before loading a second (otherwise they get superimposed) - my code doesn’t work - can you see my error?

Secondly, have you seen a reference within the forum for examining a model and reducing/increasing the size to comfortably fit in the screen on the centre of the iPad?


function setup()
    --
    ship = 1
    models = {}
    count = 0
    path = asset.documents.Dropbox.ModelWorkers
    for _,k in pairs(path.all) do
        if k.type == MODELS then
            table.insert(models, k)
            count = count+1
        end
    end
    print(count)
    print(#models)
    for lp = 1,#models do
        print(models[lp].name)
    end
    parameter.intesger("modl",1,#models)
    parameter.action("Load", function()
          --  e.entity:destroy()
            newModel(modl)
    end)

    scene = craft.scene()
    scene.camera.eulerAngles=vec3(ex,ey,ez)
    scene.sun.rotation = quat.eulerAngles(45,0,45)
    scene.ambientColor = color(90,90,90)

    skyMaterial = scene.sky.material
    skyMaterial.horizon = color(0, 203, 255, 255)  

    v=scene.camera:add(OrbitViewer, vec3(0,0,0), 10, 0, 100)
    e=scene:entity()

    pos = {x=0,y=0,z=0}
    rot = {x=0,y=0,z=0}
    tween(24,rot, {x=-0,y=360,z=0}, {easing = tween.easing.linear,loop = tween.loop.forever})
    e.rotation = quat.eulerAngles(-90,0,0)

end

function update(dt)
    scene:update(dt)
    e.rotation=quat.eulerAngles(rot.x,rot.y,rot.z)
    e.position=vec3(pos.x,pos.y,pos.z)
end

function draw()
    update(DeltaTime)
    scene:draw()
end

function newModel(num)
    -- delets old model and loads new
    if e.entity then
        e.entity:destroy()
        newModel(num)
    else
        e = scene:entity()
        e.model = craft.model(path .. models[num].name)
        e.position = vec3(0,0,0)
        e.scale = vec3(1,1,1)/20
    end
end

I am exploring the other options for loading these models to get used to the syntax and check they work OK. All my models were held on my Dropbox account in the folder called ModelWorkers as can be seen in the above code.

I tested the models I downloaded in the Mac default 3D viewer (think it’s in Xcode) many of my other models don’t seem to load properly in that viewer - do you know of any viewer that is ‘more tolerant’ to model format?

The models I used were cessna, trumpet, violin case, airboat, shuttle and minicooper.

I do have a couple of textured models that I have managed to load with this code still trying to figure out what’s wrong with the rest!!!

@Bri_G your line in newModel function reading:

e.model = craft.model(path .. models[num].name)

Could be changed to:

e.model = craft.model(models[num])

Keeping path is unnecessary as this is part of the asset key you are storing in the models table.

Are you saying that when changing the line to use the old-style asset string:

e.model = craft.model("Dropbox:ModelWorkers/ModelName")

It loads differently? Are you able to specify which models this happens with?

@Simeon - thanks for the response on that, should have realised that as I have printed out the list paths when checking the table contents.

I’ll see if I can find an example of a model that has issues with the addressing mode to post to you. Thanks.

@Bri_G to avoid the models overlapping you would need to give each one a different position. You can modify the scale property to set the size of a model.

@Bri_G Make this change to your above code.

function newModel(num)
    -- delets old model and loads new
    if e then
        e:destroy()
    end
    e = scene:entity()
    e.model = craft.model(path .. models[num].name)
    e.position = vec3(0,0,0)
    e.scale = vec3(1,1,1)/20
end