Howdy, Stranger!

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

Codea Craft 2.5 (84) Beta - Updated 8/9/2017

24

Comments

  • Posts: 69
    I've run into a problem. In the Voxel words examples I cant get block from imventory and therfore cant place any. Is this a bug or is it no coded in the example?
  • JohnJohn Admin Mod
    Posts: 616

    @GR00G0
    You might have to select a slot on the bottom bar first then select something from the inventory

  • Posts: 175

    @John That makes sense, I am using an iPad2 :D

    Is it possible to attach a callback / event or something so we can be notified when the scene/world/physics/voxel generation is ready? It would also be useful for tasks like indicating progress of loading a level.

  • Posts: 71

    @John @Simeon Pretty sure I just found another bug. (or maybe just an unfinished feature) I tried running a Codea Craft project while using Air Code and it spat out all sorts of errors like

    Main:8: attempt to index a nil value (global 'craft')
    

    I'm 100% sure this isn't a problem with the project itself, as I've run it without Air Code without a problem before. Hope you can look into this for the next release!

  • dave1707dave1707 Mod
    edited May 2017 Posts: 8,401

    @Attila717 I don't use air code, but that error usually means that Craft isn't checked as a dependency.

  • Posts: 71

    @dave1707 Nope, its definitely checked as a dependency. I have noticed that you cannot set dependencies in Air Code, but dependencies that you have previously set in the Codea app stay on the project when run in Air Code.

  • edited May 2017 Posts: 175

    Talking of dependencies, I noticed for the craft examples I have to scroll down quite a bit to see their dependencies. Although probably not as far as I imagine @dave1707 might have to ;)

    Perhaps a way to show only the project's current dependencies would be helpful? I think either separately showing them again at the top of the list or a swipe gesture to switch to a filtered view could work well.

    Edit: Also just found a bug. Whilst scrolling in the list it froze briefly then suddenly changed to the light theme.

    Edit2: To replicate open dependencies list with the onscreen keyboard open then close the keyboard.

    image.png 375.6K
  • dave1707dave1707 Mod
    Posts: 8,401

    @XanDDemoX I don't use dependencies, so it's not a big problem. For the craft examples, I did have a lot of scrolling to do to see what was checked. Maybe an easy way to show the checked dependencies is just have any checked dependency sorted at the beginning of the list.

  • Posts: 71

    I put the new beta update in this discussion as well as there didn't seem to be a lot of enormous changes, just bug fixes and improvements.

  • Posts: 1,729

    Hi All,

    Anyone running air code and coding in a browser with 2.5/74/75/76 can't seem to get it running on my pad and mac!!!

  • Posts: 71

    @Bri_G That's a known bug, @John is probably already working on it.

  • Posts: 71

    @John @Simeon I realize it may be a bit early to ask this question, but how does Codea import textures when it loads obj files? I've successfully gotten a texture to load when the mtl, obj, and image were all in my Dropbox, but it seems like the mtl can only use one image or else it doesn't work. Could you clarify how this all works? Thanks

  • JohnJohn Admin Mod
    Posts: 616

    @Attila717
    Normally the obj loader tries to grab the mtl and images from the same directory as the model but I haven't tested the obj loader with more than one texture. Can you send me an obj that has this problem (with the mtl and textures as well).

  • Posts: 71

    @John This is the file that was giving me problems. It shows up all right, besides being completely black. I did rename both the obj file and the mtl file to be the same. (Besides the .mtl and .obj file extensions) https://www.dropbox.com/s/m8akcffvygs5xw4/Futuristic_Car_2.0_Cgtrader_obj.zip.zip?dl=0

  • Posts: 71

    @John Also, can different parts of obj files be treated as separate components of one entity? Or can they be treated as different entities? I guess I'm looking for a way to make characters or other objects move their arms/wheels/etc...

  • JohnJohn Admin Mod
    Posts: 616

    @Attila717
    This is something I've been considering (allowing each object to be loaded as children of the parent mesh). One of the issues is that the obj format does not support transformations, so each sub-object mesh will have the middle of the object as its center. Later on I will be adding support for collada and fbx which have proper support for transform hierarchies.

  • JohnJohn Admin Mod
    Posts: 616

    @Attila717 I managed to get the model working (there were a few bugs in texture loading). The .mtl file itself had some issues, such as extra slashes in path names. Also the obj loader we are using doesn't seem to like spaces in names either. I also removed a dummy object that was obscuring the main model.

  • Posts: 71

    @John Oh cool! I had kind of given up on that model ever working. Thanks for figuring that out, it looks great.

  • Posts: 534

    if i duplicate an example project, to use as the basis of new project, it seems i cannot replace the project icon with a new icon. i think this is a longstanding issue not connected with the new version.

  • JohnJohn Admin Mod
    Posts: 616

    @piinthesky I'll have a look into this

  • Posts: 71

    @piinthesky @John I think this may just be a problem with your device. It works perfectly fine on my Codea.

  • dave1707dave1707 Mod
    Posts: 8,401

    @Attila717 Can you show the syntax of how you set the project icon.

  • edited May 2017 Posts: 71

    @dave1707 I'm not entirely sure how or even if you can do it in code, but I've always just pressed the camera icon then pressed set icon.

    Edit: never mind, this should work

    img = image(WIDTH, HEIGHT)
    saveImage("Project:Icon", img)
    
  • Posts: 534

    i confirm if i copy a demo project i cannot change the icon of the copy via the camera method. it does work for a new project.

  • dave1707dave1707 Mod
    edited May 2017 Posts: 8,401

    @piinthesky @John I tried changing the project icons again. Using a copy of one of the demos, I was able to change the icon using the saveImage command, but not the copy via the camera method. I must have used a normal project when I did the icons earlier when I thought they were demo copies.

  • edited May 2017 Posts: 71

    @piinthesky @dave1707 @John Now I'm getting the same problem everyone else is. It only happens with regular demos, not Codea Craft demos though.

  • dave1707dave1707 Mod
    Posts: 8,401

    @John @Simeon This has nothing to do with Craft, but I think it should be changed. The variable for parameter.text can be updated until the text area is touched. After that, the variable can't be changed by the program. What I was trying to do was input something in the parameter.text area and after processing what was there, I would then clear the text area for the next input. But it doesn't clear once it's used. In the example below, the text area is allowed to be changed until just touching the text area prevents it.

    function setup()
        t=0
        parameter.text("txt","")
        fill(255)
    end
    
    function draw()
        background(40, 40, 50)
        t=t+1
        txt=string.format("%s%d","value  ",t)
        text(txt,WIDTH/2,HEIGHT/2)
    end
    
  • SimeonSimeon Admin Mod
    Posts: 5,364

    @piinthesky thank you for finding this bug, will have it fixed in the next build.

  • SimeonSimeon Admin Mod
    Posts: 5,364

    @dave1707 interesting problem, but the behaviour could be tricky to get right.

    parameter.text is user editable, so if you are setting it every frame, then go to edit it, do we ignore the setting of it programatically? And then continue to allow it to be set programatically after editing has finished?

    I'll have to think on it. Your use case is a good one, though. I think you could use parameter.clear to clear and re-create the text parameter to get the cleared value.

  • dave1707dave1707 Mod
    Posts: 8,401

    @Simeon Setting it every frame from within the program was just an example to show that the parameter.text variable can be updated until you touch the parameter.text area. After that, the variable can no longer be updated from within the program. What I'm after is to use the text area as an input, have the user press a parameter.action button, process what was entered in the text area, then set the parameter.text variable to "" for the next input. Right now, you have to tap the text area and backspace what's in the text area to clear it before you enter something else. The other parameter variables, (number, integer, boolean) allow you to alter their values from within the program. I don't understand why the text variable can't be altered after it's first use. I can use parameter.clear, but if I have several other parameter variables being used, it also clears them.

  • SimeonSimeon Admin Mod
    Posts: 5,364

    @dave1707 I agree with you, I think your use case is a pretty good one. Just trying to think about how to implement it :)

  • edited May 2017 Posts: 175

    @John @Simeon I've just found that Codea crashes if I supply incorrect parameters to craft.rigidbody functions in update specifically. The same code in setup, touched or draw halts with an error message as normal.

    function update() 
       local body = entity:get(craft.rigidbody)
       body:applyForce()
       body:applyImpulse(vec3(0,0,0))
       body:applyTorque("crash")
    end
    
  • JohnJohn Admin Mod
    Posts: 616

    The new beta build (B77) is out! There are a number of bug-fixes and changes to example projects as well as a few new ones.

    BETA NOTES
    - After installing a new version you should be prompted to restore examples, please make sure to press the restore button
    - For feedback / questions please visit codea.io/talk (PM simeon or john for access to the beta thread)
    
    NEW FEATURES - Craft
    - A new advanced feature-set with support for 3D environments, lighting, physics, voxels and more!
    - OBJ model loading (support for other formats coming in future updates)
    - Directional, point and spot lights
    - Advanced material system with support for physically based rendering
    - Voxel rendering and collisions with support for fully custom block types and scripting
    - Advanced noise system for terrain generation and other procedural content
    - 3D physics, with support for spheres, boxes, capsules and mesh shapes
    New Examples
    New Assets
    
    CHANGE LOG
    
    28/05/2017
    Examples
    - Added new example: Stacker
    - Added new example: Models
    - Added support for fog in Voxel Terrain
    Assets
    - Added new asset pack: Racing Kit by Kenney
    Runtime
    - rendering
        - Added support for fog
        - Added fog options to craft.scene (fogEnabled, fogColor, forNear, fogFar)
        - Added fog to voxel material
        - Changed fog distance calculation to radial
        - Obj model materials should load more consistently now
    - voxels
        - Reused chunks are no longer visible before being meshed for the first time
        - Fixed crashes related to setting and getting properties on dynamic blocks
    - physics
        - Dynamic rigidbodies now ignore their parent transforms when being simulated (unless the parent is moving)
        - Static and Kinematic rigidbodies now take their parent world space transforms into account when being simulated
    
  • Posts: 69
    @John or @Simeon Can you help me with this really quickly please. I just cant figure it out. How can i map a surface texture around a icoSphere, and how can I increase the farClipping plane beyond 400?
  • dave1707dave1707 Mod
    edited May 2017 Posts: 8,401

    @John @Simeon Nothing to do with Craft, but still an existing issue in the current code. If you do a long press on a project, then export, then copy project, if the code contains --# Main or any --# tab name, when you paste into project, multiple tabs are created for each --# in the new project.

    EDIT: If I edit a project then do a select all and copy, then do a paste into project, the new project doesn't have the --# Main line of code. The --# are removed.

  • JohnJohn Admin Mod
    Posts: 616

    @GR00G0 The best way to map a texture onto an ico sphere would be to use a cube map (as regular 2D texture mapping won't work due to seams and distortion). I'm working on an example that uses a thing called a quad cube to achieve this, however rendering the custom cube map isn't supported at the moment and the current materials do not allow cube maps to be used for this purpose.

    There's a nice article on this subject that goes into a lot of depth on how to achieve planet rendering at multiple scales: https://acko.net/blog/making-worlds-1-of-spheres-and-cubes/ which should be possible to do in Codea soon.

  • edited May 2017 Posts: 175

    @John, @Simeon I was extending quat to rotate vec3 via multiply and found something strange. The following error occurs if I attempt to compare a vec3 metatable to a quat metatable or equivocally quat.___class.

    print(getmetatable(quat(1,0,0,0)) == getmetatable(quat(1,0,0,0)))
    print(getmetatable(quat(1,0,0,0)) == getmetatable(vec3(0,0,0))) -- error
    
    Main:43: expect userdata, got table
    stack traceback:
        [C]: in metamethod '__eq'
        ...
    

    Also now with build 77, Codea crashes for seemingly any assert or similar error during setup with Craft enabled. It appears to happen only when Craft is loading because causing an error later in touched halts and prints as normal and Codea doesn't crash when Craft is disabled. Also wrapping the code in an xpcall prevents the crash.

    In case anyone is interested I extended quat to rotate vec3 with the following code in the end. The equation is from https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-quaternion.

    function hook(base,func)
        return function(...) return func(base,...) end
    end
    
    function setup()
        local types = {}
        types[vec3] = getmetatable(vec3())
        types[quat] = quat.___class
        quat.___class.__mul = hook(quat.___class.__mul,function(base,left,right)
    
            local mt = getmetatable(right)
            local result, isQuat = xpcall(function() return mt == types[quat] end,
            function() end)
            isQuat = result and isQuat 
    
            if isQuat then
               return base(left,right)
            elseif mt == types[vec3] then
               local u = vec3(left.x,left.y,left.z)
               local s = left.w
               return 2 * u:dot(right) * u + (s*s - u:dot(u)) * right + 2 * s * right:cross(u) 
            end
        end)
    end
    
  • Posts: 69
    @John Ok thank you. Thats kind of how I already do it, but just not woth craft.
  • Posts: 1,729

    Hi All,

    Thanks for the update - looking at the craft demos:

    First 3D Planet - looks great but ran into couple of snags - first zooming into planet goes below surface to show clear sky and all the dark-side objects, not sure but they may be facing upward - shouldn't we see inside of sphere? Seems to lock on the z(y?) axis can zoom out but not further in.

    Also when running step 1 just zooms into surface and doesn't show the models or allow movement - am I missing something?

    Second assets - I've seen blank items in the resources list but they are obviously there as we can see them in the demo. The only one that shows icons is the UI resource. Do we need to install/sync these in some way?

    Thirdly Voxel Terrain - works fine on my iPad Pro but partially runs then bombs out to iOS on my iPad 2. Is there a memory limitation or clash with OpenGL?

  • dave1707dave1707 Mod
    Posts: 8,401

    @Bri_G Voxel Terrain works just fine on my 16GB iPad Air. I'm on iOS 10.3.1 and I haven't uploaded version 10.3.2 yet. I usually wait a week or so before I update to the latest iOS just to see if anyone reports problems.

  • Posts: 1,729

    @dave1707

    iPad Pro (9.7). iOS 10.3.2 128GB
    iPad 2 iOS 9.3.5 32GB

  • dave1707dave1707 Mod
    Posts: 8,401

    @Bri_G Maybe there's a difference in the iOS. It seems to work OK on the 10.3 versions. If you haven't run into any problems with iOS 10.3.2, maybe I'll update both my iPads.

  • JohnJohn Admin Mod
    edited May 2017 Posts: 616

    @XanDDemoX Nice. I'll have to look into those bugs. Do you have a minimal project that causes the crash? The metatable equality check is probably having issues as the metatable is its own metatable (so it's actually trying to do the quat equality check :open_mouth:).
    I can add native support for multiplying quats and vec3's though.

    @GR00G0 Fair enough. Craft is still in beta and a lot of these features are still in development so certain things just aren't possible at the moment.

    @Bri_G The Planet3D demo definitely has a few issues like that. You can't see the inside purely because the material it renders with is one-sided. Two-sided materials are something I'll add in future if anyone needs it.
    The 'steps' feature is supposed to allow you to view different progressive examples, but it's broken at the moment as you can't reset the whole scene at once.
    The Voxel Terrain demo is very memory intensive, however I think it is using more than it should so I'll look into that. I wouldn't expect it to run any better than Minecraft does as it's not nearly as optimised.

  • edited May 2017 Posts: 175

    @John Ahhh I should have guessed :D Native support for multiplying to rotate vec3s by quat would certainly be handy.

    It could also be useful for building/generating meshes to be able to obtain a rotation matrix directly from a quat. Although currently there is already a couple of options, obtain with matrix.rotate and quat.angles or directly as below.

    -- http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/geometric/orthogonal/index.htm
    -- http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/
    function quaternionToMatrix(q)
        local x,y,z,w = q.x,q.y,q.z,q.w
    
        local xs2 = 2*(x*x)
        local ys2 = 2*(y*y)
        local zs2 = 2*(z*z)
    
        local xy2 = 2*(x*y)
        local xz2 = 2*(x*z)
        local yz2 = 2*(y*z)
    
        local wx2 = 2*(w*x)
        local wy2 = 2*(w*y)
        local wz2 = 2*(w*z)
    
        return matrix(
            1-ys2-zs2,xy2-wz2,xz2+wy2,0,
            xy2+wz2,1-xs2-zs2,yz2-wx2,0,
            xz2-wy2,yz2+wx2,1-xs2-ys2,0,
            0,0,0,1
        )
    end
    

    I think the crash is another occurrence of invalid parameters in update although it shouldn't even be called in the following situation. A print is not output suggesting it isn't but I can affect whether the crash happens by changing variable initialisation to before or after the assert.

    Crashing code

    function setup()
        assert(false)
        angle = 0
    end
    
    function update()
        print("print")
        local q = quat.eulerAngles(0,0,angle)
    end
    

    Working code

    function setup()
        angle = 0
        assert(false)
    end
    
    function update()
        local q = quat.eulerAngles(0,0,angle)
    end
    

    I also noticed that Codea doesn't halt immediately when an assert is in update.

    function setup()
    end
    
    function update()
        print("once not twice")
        assert(false)
    end
    

    Output

    once not twice
    Main:11: assertion failed!
    stack traceback:
        [C]: in ?
        [C]: in function 'assert'
        Main:11: in function 'update'
    once not twice
    Main:11: assertion failed!
    stack traceback:
            [C]: in ?
        [C]: in function 'assert'
        Main:11: in function 'update'
    

    Edit: Just found another strange one. The entity instance returned by a raycast result doesn't work as a key to lookup a value in a table.

    function setup()
        entity = craft.entity()
        local size = vec3(20,1,20)
        local renderer = entity:add(craft.renderer,craft.mesh.cube(size))
        renderer.material = craft.material("Materials:Standard")
        renderer.material.map = readImage("Blocks:Brick Red")
    
        entity.position = vec3(0,0,0)
    
        local body = entity:add(craft.rigidbody,STATIC)
        entity:add(craft.shape.box, size, vec3(0,0,0))
        craft.scene.camera.rotation = quat.eulerAngles(45,0,180)
        craft.scene.camera.position = vec3(0,40,25)
    
        tbl = {}
        tbl[entity] = entity
    end
    
    function update()
    
    end
    
    function touched(touch)
        if touch.state ~= BEGAN then return end
        local pos,dir = craft.camera.main:screenToRay(vec2(touch.x,touch.y))
        local result = craft.physics:raycast(pos,dir,100)
        if not result then return end
        print(result.entity == entity) -- ok
        print(tbl[entity]) -- ok
        print(tbl[result.entity]) -- nil, should be entity.
        for k,v in pairs(tbl) do
            print(k == entity) -- ok
            print(v == entity) -- ok 
            print(k == result.entity) -- ok
            print(v == result.entity)  -- ok
        end
    end
    
  • dave1707dave1707 Mod
    Posts: 8,401

    @GR00G0 I'm not sure what you were after in the other discussion, but here's your program from there where I modified it a little.

    displayMode(FULLSCREEN)
    
    function setup()
        craft.scene.camera.position = vec3(0,0,5)
        craft.scene.camera.rotation = quat.eulerAngles(0,0,180)
    
        sphere = craft.entity()
        renderer = sphere:add(craft.renderer,craft.mesh.icoSphere(1,5,true))
        renderer.material = craft.material("Materials:Standard")
    
        for i = 0, renderer.mesh.vertexCount-1 do
            if noise(renderer.mesh:position(i)) <-.2 then
                renderer.mesh:color(i,0,0,255,255)
            elseif noise(renderer.mesh:position(i)) <.4 then
                renderer.mesh:color(i,255,0,255,255)
            else
                renderer.mesh:color(i,0,255,0,255)
            end
            renderer.mesh:position(i,getpos(renderer.mesh:position(i)))
        end
    end
    
    function update()
        sphere.rotation = quat.eulerAngles(10*ElapsedTime,20*ElapsedTime,10*ElapsedTime)
    end
    
    function getpos(x,y,z)
        return vec3(x,y,z)
    end
    
  • Posts: 534

    Grrrrrrrr, Codea just deleted many of the tabs in my current project! (of course i had not made a backup). I've reported this before, once there are a lot of tabs there is a risk that the ones on the right disappear. @Simeon this really needs to be fixed urgently or at least limit the number of tabs allowed to a safe number.

  • dave1707dave1707 Mod
    Posts: 8,401

    @piinthesky Was this just using an iPad or were you using Aircode when it happened.

  • Posts: 534

    ipad pro 12.9 directly without aircode

  • dave1707dave1707 Mod
    Posts: 8,401

    @piinthesky Thanks for the info. Apparently they haven't figured out why it's happening or fixed it yet. Back in Sept 2016 you had a similar problem and posted about it, but you still didn't create backups. It doesn't take a lot of time to long press a project and create a duplicate before making changes, but it's a little late now. I'll let @Simeon or @John respond to this to see if they have any idea why, but my suggestion to everyone is to make backups of any project you're updating until a fix is found.

  • Posts: 237

    @piinthesky that started happening to me, and I got close to chucking my iPad at the wall, but what I do now is make everything safer by using dependencies. Make different projects that have some classes, and just declare them as dependencies in your master project. Also, I would add buffer tabs called "zzzz","zzzzzz", etc. which were blank, so that they would be the ones to go if anything got wiped out. Also, as @dave1707 said, its not that hard to back up your projects, better safe than sorry.

Sign In or Register to comment.