Is it possible to import 3D models in Codea?

Can’t do wireframe (thinking of a way to do it, true wireframe vs. a triangle pair texture mesh). See http://twolivesleft.com/Codea/Talk/discussion/1964/draw-a-mesh-as-wireframes#Item_6

Also, read the file from an external source instead of loading it as a big string…yes, Codea editor tends to crash the way you did it, which is why I wrote a file loader long ago :slight_smile:

@reefwing to draw a mesh as a wireframe i have 2 methods:
.1. Draw all the ines in a trnsparent texture image, and use it.
.2. Use a small texture image with a triangle drawn, und apply the textCoords of the 3 corners to all the triangles of the mesh.
Here is some parts of code for method1:


-- first create image
        self.img = image(1000,500)
        setContext(self.img) pushStyle()
        background(0,0,0,0)
        setContext() popStyle()
-- then apply this to all triangles:
function MeshTexturer:createWireFrame(k,ms,w,h,img)
    -- prepares the shadow image
    local v1,v2,v3
        -- get triangle vertices
        v1 = ms:texCoord(k+1)
        v2 = ms:texCoord(k+2)
        v3 = ms:texCoord(k+3)
        -- draw lines
        line(v1.x*w, v1.y*h, v2.x*w, v2.y*h)
        line(v1.x*w, v1.y*h, v3.x*w, v3.y*h)
        line(v3.x*w, v3.y*h, v2.x*w, v2.y*h)
end

Make sure you use ms:texCoords() and not ms.texCoords[] to read it, because y is 1-y in the memory.

@Reefwing, I have tried models with 900 triangles up to 69.000 triangles and were done with PLYs inside a LUA source. I can’t edit them, but I just copied them into the project with my PC. Have a look here at the screenshots and code:

http://twolivesleft.com/Codea/Talk/discussion/1723/3d-model-loading-from-blender-ply-and-suggestion%3A-need-to-load-local-files#Item_43

I use blender, because I can create lightmaps there and don’t need lighting calculation for the model. Will work for sure with other modellers too, but I got used to it :wink: I have implemented lighting calculation too, but it takes pretty long for the 69k triangles model.

The PLY loader is very simple, it can only load triangles, but it was enough for me. I hope, that Codea will implement a model loader in the next versions. There is also a discussion about future model loading in Codea and about the formats to be used in that post.