Howdy, Stranger!

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

Texture building

in Codea Craft Posts: 2,361

Hi All,

Just a general question on modelling and texturing. I have played with many models with provided textures and, now with Craft, display is relatively straight forward. But, on building my own models in applications like MeshLab, Wingz3D and of course Blender I find really difficult. In particular the latter.

I have a few models with data in vertices and vertex colouring which I would like to transfer to full object/texture as these models suffer from distortion when rotated.

Does anyone know how to build a texture from a vertex cloud, unwrap a vertex coloured model to give a texture or even build a texture from a Codea mesh to apply to a model? Exporting vertices and UV would be handy for any model built with vertices and vertex colouring.

A big ask I know.


  • If you are talking about distortions when using Blender then you have to 'Apply' changes you did in object mode (like size or rotation) by pressing Ctrl + A.
    You do not have to do this when you are in 'Edit Mode'. You can change between object and edit mode by pressing Tab.

  • Posts: 2,361

    @TheMojoMan - thanks for the feedback. I’ve been loading vertice painted objects (obj and mtl) into Blender but the file format, whilst accepted by Blender, and displayed correctly distorts when added to Craft. Hence my interest in UV unwrapping to see if that resolves the problem. So far not able to export the texture satisfactorily. Thanks for the feedback, will persevere with Blender - it’s a marvellous package but daunting in use.

  • I'm not really clear on what you're asking, possibly since I don't use external tools to build models but rather define them programmatically in Codea. Then, since I design the models myself I can define their texture coordinates at the same time.

    What is your starting point, in Codea terms? By which I mean, once you have imported your object to Codea, what does it look like? Then what is missing from it?

  • edited December 2020 Posts: 2,361
    @loopspace - fairly simple models with each vertex given a colour.but of course each vertex can be included in several triangle/faces with different colours.

    My problem is taking the matrix of vertices and spreading it out onto a 2D plain with no overlaps. Connected at seams wherever possible to enable easy identification. In other words unwrapping the verices into a 2D mesh, saved in a png format which I could then edit in an external paint package.

    I have seen Codea models built in situ, like cubes. But it would be nice to export the texture then reload as an obj/mtl/texture model.
  • You can't always unwrap the vertices to well-defined texture coordinates.

    The simplest case is with a cylinder. When you unwrap the cylinder, you end up with a seam where a vertex will correspond to different texture coordinates depending on which triangle it is part of.

    It is best to think of it in the other direction: wrapping a texture onto your object.

    Also, when figuring out the texture coordinates you wouldn't get an actual image, like a png. The texture coordinates explain how to map an image onto your mesh but you have to provide the image yourself separate to the coordinates. Again, think of a cylinder - you can wrap an image around a cylinder and the texture coordinates explain how to do that, but you still have to provide the image to wrap.

  • dave1707dave1707 Mod
    edited December 2020 Posts: 9,429

    @Bri_G Don’t know if this is of any help, but @LoopSpace was talking about a texture on a cylinder. The below example will put a texture on a cylinder. You can change the variable “sides” from 3 to a higher number to create a smooth cylinder.
    You can change the Startup_Screen to some other texture. Are you trying to unwrap a model to get an image. I’m not sure how I’d unwrap the cylinder to get an image.

    PS. Just read your post again and if you just have colors per triangle instead of an image, that might be easier to unwrap. I’ll have to think about that. Currently watching football so I’m not concentrating on coding.

    function setup()  
        assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")        
        scene = craft.scene(),vec3(px,100,pz), 1000, 0, 10000)
        cm = craft.material(asset.builtin.Materials.Basic)  
        for a=359,0,-360/sides do
            x=math.cos(math.rad(a))*50  --1
            y=math.sin(math.rad(a))*50  --1
        for z=1,#pos-2,2 do
    function draw()
    function update(dt)
    function createTile(p1,p2,p3,p4,s1,s2)
        local c=color(255, 255, 255, 255)
        r.model = craft.model()
        r.material = cm
    function norm(a,b,c)
  • Posts: 2,361

    @dave1707 - that’s a very neat excellent demo on construction of a model. My model is simpler and uses a mesh building up triangles from a vertex list which uses colour attributes to generate the shading, made in that way the model doesn’t distort when rotated. What I was hoping to do was to build a texture from the mesh so I could test the stability of the model trying to understand the distortions I get when using the data in an obj or obj/mtl file which also uses only colour data and not an image.

    Although the way you have built the tile image may do that - I’ll give it a try. Thanks.

    @LoopSpace - thanks for your feedback, I understand the principles and think that I may be going about this the wrong way. Need to sit back and think this out properly, it may not be worth the time and effort - may go and watch some football myself then try another approach. Thanks again.

  • Posts: 2,361
    @TheMojoMan - I'm slowly getting there with Blender texturing but hit a problem with the final texture. I unwrapped a model, used texture painting then saved the texture. Unfortunately the texture retained all the wireframes of the model which kinda spoils the effect. Do you know how to hide the wireframes?
  • edited December 2020 Posts: 2,361
    Getting there, for simple models Wings 3D is easier to digest and less complicated than blender. Hopefully be able to generate a few models in a demo soon.
Sign In or Register to comment.