Howdy, Stranger!

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

Loading 3D without Craft

edited September 28 in Codea Craft Posts: 3

Hello!

I would like to know if it’s possible to load and render 3D models from the built in assets library in my project without using the Craft library. I am using tiny-ecs and I constructed a little 2D game but I would like for my next project to continue to use tiny-ecs and be able to load models without having to call any Craft code. Any idea of how I’d do this?

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 7,810

    @ambientocclusion Here’s an example of 3D without Craft.

    displayMode(STANDARD)
    
    function setup()
        print("Slide output window down")
        parameter.integer("R",-360,360, -170)
        parameter.number("x",0,1,.5)
        parameter.number("y",0,1,.5)
        parameter.number("z",0,1,.5)
        parameter.integer("sizex", 0, 50, 20)
        parameter.integer("sizey", 0, 50, 20)
        parameter.integer("sizez", 0, 50, 20)
        c = { color(255, 0, 0, 255), color(0, 255, 0, 255), 
              color(255, 243, 0, 255), color(0, 0, 255, 255), 
              color(255, 255, 255, 255), color(255, 0, 189, 255)}                    
        colors = {}
        for i = 1, 6 do
            for j = 1, 6 do
            table.insert(colors,c[i])
            end
        end    
    end
    
    function draw()
        background(0, 0, 0, 255)
        perspective(50)
        camera(-500,0,0,0,0,0,0,1,0)
        rotate(R,x,y,z)
        cube(0,0,0,sizex,sizey,sizez)
    end
    
    function cube(x,y,z,w,h,d)
        local cube = mesh()    
        local v = { vec3(x-w,y-h,z+d),vec3(x-w,y+h,z+d),
                    vec3(x+w,y-h,z+d),vec3(x+w,y+h,z+d),
                    vec3(x-w,y-h,z-d),vec3(x-w,y+h,z-d),
                    vec3(x+w,y-h,z-d),vec3(x+w,y+h,z-d) 
                  }       
        local faces = { v[1],v[2],v[3],v[2],v[3],v[4],v[2],v[4],v[6],v[4],v[6],v[8],
                        v[1],v[2],v[5],v[2],v[5],v[6],v[3],v[4],v[7],v[4],v[7],v[8],
                        v[1],v[3],v[5],v[3],v[5],v[7],v[5],v[6],v[7],v[6],v[7],v[8] 
                      }                     
        cube.vertices = faces
        cube.colors = colors
        cube:draw()
    end
    
  • Right but my question is: is it possible to load one of the meshes from the assets and display that without Craft? I’d like to use one of the characters or environment models, or load my own.

  • dave1707dave1707 Mod
    Posts: 7,810

    @ambientocclusion Here’s a discussion I found, does this help. You can search the forum for more info.

    https://codea.io/talk/discussion/4200/how-to-import-fully-3d-objects-final-post/p1
    
Sign In or Register to comment.