Howdy, Stranger!

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

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 ...

Thanks!

Comments

  • Posts: 342

    Bueller? Bueller?

  • edited March 17 Posts: 1,185
    @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?
  • Posts: 342

    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:

  • Posts: 1,185

    @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.

  • dave1707dave1707 Mod
    Posts: 7,521

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

    https://twolivesleft.com/CodeaCraft/Manual/
    
  • Posts: 1,185

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


    https://codea.io/talk/discussion/7738/codea-craft-official-thread/p3 https://codea.io/reference/

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

  • Posts: 342

    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.

  • Posts: 342

    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 ...

  • JohnJohn Admin Mod
    Posts: 572

    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?

  • Posts: 342

    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.

  • dave1707dave1707 Mod
    Posts: 7,521

    @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.

  • JohnJohn Admin Mod
    Posts: 572

    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.

  • Posts: 342

    delicious summary. where's your blog, please?

  • Posts: 342

    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!

  • Posts: 342

    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) end
  • Posts: 342

    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
        createGround(-1.125)
    
        -- 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)
    end
    
  • Posts: 342

    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.

  • Posts: 384
    once the shield is a child of the parent, it also inherits the scaling from the parent, so the shield becomes very small!
  • Posts: 342

    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.

  • Posts: 384
    probably kenny assets, could be blender 3d objects in .obj .mtl format
  • Posts: 342

    yes. i guess i'll need to learn how to get textures onto blender objects ...

  • dave1707dave1707 Mod
    Posts: 7,521

    @RonJeffries This gets the shield attached to the robot, but I haven’t figured out how to turn the shield around so the white part shows.

    -- Craft Entities
    
    function setup()
        -- Create a new craft scene
        scene = craft.scene()
        scene.sky.active = false
        --createGround(-1.125)
    
        -- 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.x = 0
        ronEntity.y = 10
        ronEntity.z = 3
        ronEntity.scale = vec3(1,1,1)
    
        -- Move camera back a little
        scene.camera.z = -4
    
        ronEntity.parent=myEntity
    
        parameter.number("Rotate", 0, 360, 180)
    end
    
    function update(dt)
        myEntity.eulerAngles = vec3(0, Rotate, 0)
        scene:update(dt)
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()       
    end
    
  • dave1707dave1707 Mod
    edited March 21 Posts: 7,521

    @RonJeffries This one I got the shield turned the right way.

    PS. Made some changes for the shield size.

    -- Craft Entities
    
    function setup()
        -- Create a new craft scene
        scene = craft.scene()
        scene.sky.active = false
        --createGround(-1.125)
    
        -- 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.x = 0
        ronEntity.y = 7
        ronEntity.z = 3
        ronEntity.scale = vec3(3,3,.1)
        ronEntity.rotation=quat(0,1,0)
    
        -- Move camera back a little
        scene.camera.z = -4
    
        ronEntity.parent=myEntity
    
        parameter.number("Rotate", 0, 360, 180)
    end
    
    function update(dt)
        myEntity.eulerAngles = vec3(0, Rotate, 0)
        scene:update(dt)
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()       
    end
    
  • Posts: 342

    Weird, thanks, forced an insight. All I can figure out is that somewhere in my first example, where I just set parent, the relative coordinates hid the shield, and that by the time I tried the table insert, I'd made some other change to make it appear. So ... I conclude that setting parent does suffice, and I suppose if I look at the robot's children the shield will be in there.

    Today's mission, should I choose to accept it, is going to be to try to figure out how to import an asset. I made a little object in second life and exported it. Pointers on that will be welcome, but I'll start searching. Thanks!

  • dave1707dave1707 Mod
    Posts: 7,521

    @RonJeffries I added more thing to your robot. Slide the parameter window down to show all parameters.

    -- Craft Entities
    
    function setup()
        parameter.number("Rotate", 0, 360, 208)
        parameter.number("swx",-180,180,45)
        parameter.number("swy",-180,180,0)
        parameter.number("swz",-180,180,0)
        parameter.number("shx",-180,180,180)
        parameter.number("shy",-180,180,-30)
        parameter.number("shz",-180,180,30)
    
        scene = craft.scene()
        scene.sky.active = false
    
        ground = scene:entity()
        ground.model = craft.model.cube(vec3(10,.2,10))
        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,1,1)
        ground.y = -1
    
        robot = scene:entity()
        robot.model = craft.model("Blocky Characters:Robot")
        robot.y = -1
        robot.z = 0
        robot.scale = vec3(1,1,1) / 8
    
        shield = scene:entity()
        shield.model = craft.model("CastleKit:shieldRed")
        shield.x = -3
        shield.y = 7
        shield.z = 3
        shield.scale = vec3(2.5,2.5,.1)
    
        sword = scene:entity()
        sword.model = craft.model("CastleKit:sword")
        sword.x = 3.2
        sword.y = 6
        sword.z = 1
        sword.scale = vec3(1,1,1)*1.6
    
        scene.camera.z = -6
    
        shield.parent=robot
        sword.parent=robot
    end
    
    function update(dt)
        robot.eulerAngles = vec3(0, Rotate, 0)
        sword.eulerAngles=vec3(swx,swy,swz)
        shield.eulerAngles=vec3(shx,shy,shz)
        scene:update(dt)
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()       
    end
    
  • Posts: 342

    Super, I'll check that out. Good approach, better than my usual print and fiddle. Thanks!

  • Posts: 342

    Two interesting things. First, when I pasted that into the Learn Camera example, it totally breaks the example: no tabs work. I've not looked into that yet.
    Second, the z rotation of the sword confuses me. I'll have to think about that.
    Thanks!

  • Posts: 342

    Ah, OK, helps if you zero the others, then it's a bit more clear what z rotation does. Interesting ...

Sign In or Register to comment.