Writeups on Assets, Craft, AR, etc?

Are there any linear writeups, how-tos, documents, tutorials on Codea’s assets, craft, AR, and such?
I’m kind of an old-school RTFM kind of guy …


Bueller? Bueller?

@RonJeffries - very American Ron. Can’t help I’m afraid - slowly picking it up myself. I can put some simple code together but lack the depth to build anything useful. Having said that I can figure out code people have written have you checked out the examples?

Oh, by the way - what do you mean by linear?

thanks … how do non-americans do it? :smile:

as mentioned in another message, examples in the craft doc tab [mostly?] don’t actually do anything. i’m starting to fiddle with the example projects.

if i can nudge forward, maybe i’ll write what i need, hoping others need it too. i wonder how some of the examples came into being.

by linear i mean: begin at the beginning, go straight on to the end, and then stop. :smiley:

@RonJeffries - non Americans usually use help, Help!, HELP!!!

I’m assuming that your approach is like the sensible eating an elephant approach - one burger at a time!!

Have you any ideas on what you ultimately want to be able to do? We can work out the first step and then go from there.

@RonJeffries Did you see this link. It looks like it was a start for Craft documentation.


@RonJeffries - yeah, found that - have you seen the following two:


Early forum thread and updated documentation for Codea with the Craft included.

thanks, i’ll check those out and try to explain tomorrow what i plan to do … but mostly just looking for some cookbook stuff. thanks again.

yeah, well, the first example in the “manual” won’t compile… appears to be very out of date. maybe i can paste bits in from elsewhere. it might be what i’m looking for if it were correct. i’ll carry on …

Hey guys. That manual is out of date and somewhat superseded by the Codea documentation itself. I think the best format for this information will probably be a series of blog posts on how to use Craft effectively.

What would you say are the areas that the examples and documentation fail to cover/explain which makes it hard for you to learn to do what you want?

Well, today I started with the Learn Craft example, the Entities tab. It loads a robot, which for some reason needs to be set at y = -1. It rotates him with a parameter. This told me that I could surely move him around the floor by computing various x and y and rotation values. That’s good.

The ground is also created. It uses a cube, sets a material on it and a map. The map appears to be what I’d call a “texture”, a picture that paints on the material.

I’ve kind of deduced that much, and can probably drag more info out of the docs. But where did this robot come from? How did he get coloration built into him? Was he created in Codea, or in some 3D modeling language? Was the color baked into him in that other system?

There are magic built-in models. The example shows “cube” and I know there is an “icosphere” as well. The info in the docs on those lets me see how to scale and position them. I’m not clear how to texture them, especially with my own textures.

So, by fiddling, I begin to pick things up. I’m trying to write down what I learn, and what I learned today is that what I learned so far doesn’t really hang together, it’s a series of obviously related facts but the connections and gaps aren’t clear.

I’m hoping I’ll get a coherent picture after a while and that I’ll be able to write it down if I do. We’ll see.

@RonJeffries Craft is something that seems hard to grasp how everything fits. At some point in the past I asked if some kind of flow chart could be made that shows how all the Craft pieces fit together. So far the way I do it is to look at the examples and work off of them. I have a lot of Craft examples I wrote, but nothing that gets too involved. Mostly just variations on the existing examples.

Ok guys fair enough. There needs to be some concrete tutorials that go step by step through how the examples work and what each and every feature does.

@RonJeffries the robot is a model asset that is built-in to Codea. It’s exactly the same as any other type of asset. I assume you are familiar with the sprite() function?

Craft uses an entity component system somewhat similar to Unity (sans the editor of course). Every model you want to render needs to be attached to an entity, which takes care of things like transforms, physics and per-frame updates. Every entity is created from a scene via the scene:entity() method. Entities belong to the scene they were created with.

So the robot model is loaded by using an asset key, which can refer to things in pre-made asset packs, or the project / documents / dropbox folders. We support obj, stl, fbx and blend format at the moment. The loader tries to load an associated obj materials and any textures that the model refers to but this can fail sometimes if the filenames are incorrect, textures are missing or are some kind of unsupported format.

The cube, plane and isosphere functions are just convenience methods that automatically construct specific geometry. Setting model on an entity will just attach that model to it but won’t draw anything because you need to tell Craft how you want to treat the model’s surface (i.e. lighting, textures and other settings). Materials are a high-level way of managing shaders. There are several built-in material types, which can be found using the material picker. Once you have a material you can then attach it to the entity.

So the steps usually go:
myEntity = scene:entity() -- create entity
myEntity.position ... -- set position rotation etc
myEntity.model = craft.model("Asset Name") -- attach model
myEntity.material = craft.material("Materials:Standard") -- attach material

Each material does different things in terms of shading.

Materials:Basic is a simple unlit material (no lighting).

Materials:Standard uses a physically based lighting model and is the most complex in terms of options and render costs.

Materials:Specular uses a simple specular lighting model and is cheaper to render than standard.

Materials can be customised by changing their properties. These properties are derived from their shader and relate to various visual qualities.

For most of the materials there is a property called .map which is just a texture property that changes the diffuse color of the material.

You can use the method myMaterial:getProperties() to return a table of properties for a material where each entry has a name and type field which you can use to investigate what each property can do.

Standard uses roughness / metalness which vary from 0-1. Using these you can control most of the physical appearance. You can also use diffuse to set the color.

When I get a change I’ll try to explain some more and maybe do a series of blog posts to explain all this stuff in further detail.

delicious summary. where’s your blog, please?

Is there a useful write up anyone can point to, describing how a thing like the robot assets were created, including how they get painted? Thanks!

The following code prints nothing but about 15 tables named 1-15:

    ground.material = craft.material("Materials:Specular")
    ground.material.map = readImage("Blocks:Dirt")
    ground.material.specular = color(0, 0, 0, 255)
    ground.material.offsetRepeat = vec4(0,0,5,5)
    local props = ground.material:getProperties()
    for n,p in pairs(props) do
        print(n, " = ", p)

I’m trying to attach a shield to the robot, and to make it a child of the robot. Setting the shield’s parent to the robot doesn’t suffice: the shield no longer displays. How do I tell the robot that it has children? Thanks!

-- Craft Entities

function setup()
    -- Create a new craft scene
    scene = craft.scene()
    scene.sky.active = false

    -- Create a new entity
    myEntity = scene:entity()
    -- Set its model for drawing
    myEntity.model = craft.model("Blocky Characters:Robot")
    -- Adjust position and scale
    myEntity.y = -1
    myEntity.z = 0
    myEntity.scale = vec3(1,1,1) / 8
    ronEntity = scene:entity()
    ronEntity.model = craft.model("CastleKit:shieldRed")
    --ronEntity.parent = myEntity -- shield vanishes if this is uncommented
    ronEntity.x = 0
    ronEntity.y = 0
    ronEntity.z = -2
    ronEntity.scale = vec3(1,1,1) / 4
    -- Move camera back a little
    scene.camera.z = -4
    parameter.number("Rotate", 0, 360, 180)

OK, blindly tried table.insert(myEntity.children, .ronEntity), which works. The docs say myEntity.children is read-only. Apparently it isn’t.

Now positioning and scaling are odd but presumably that can be figured out.

once the shield is a child of the parent, it also inherits the scaling from the parent, so the shield becomes very small!

yes. i’m going to have to figure out how to know ahead of time how to scale and position things but worst case it’s cut and try.

now one of my big wonderments is how those painted objects are created.