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,024

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.

Comments

  • 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,024

    @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,024
    @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: 8,936

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

    viewer.mode=FULLSCREEN
    
    function setup()  
        sides=5
    
        assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")        
        scene = craft.scene()
        v=scene.camera:add(OrbitViewer,vec3(px,100,pz), 1000, 0, 10000)
        v.camera.farPlane=10000
        pos={}
    
        cm = craft.material(asset.builtin.Materials.Basic)  
        rm=readImage(asset.builtin.Cargo_Bot.Startup_Screen)
    
        for a=359,0,-360/sides do
            x=math.cos(math.rad(a))*50
            y=math.sin(math.rad(a))*50
            z=200
            table.insert(pos,vec3(x,y,z))
            x=math.cos(math.rad(a))*50  --1
            y=math.sin(math.rad(a))*50  --1
            z=-200
            table.insert(pos,vec3(x,y,z))
        end
        s1=0
        for z=1,#pos-2,2 do
            p1=pos[z]
            p2=pos[z+2]
            p3=pos[z+3]
            p4=pos[z+1]
            nor={}
            norm(p1,p3,p4)
            norm(p1,p2,p3)        
            createTile(p1,p2,p3,p4,s1,s1+1/sides) 
            s1=s1+1/sides 
        end
        p1=pos[#pos-1]
        p2=pos[1]
        p3=pos[2]
        p4=pos[#pos]
        nor={}
        norm(p1,p3,p4)
        norm(p1,p2,p3)     
        createTile(p1,p2,p3,p4,s1,s1+1/sides)   
    end
    
    function draw()
        update(DeltaTime)
        scene:draw() 
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function createTile(p1,p2,p3,p4,s1,s2)
        local c=color(255, 255, 255, 255)
        r=scene:entity()
        r.model = craft.model()
        r.model.positions={p1,p3,p4,p1,p2,p3}
        r.model.indices={1,2,3,4,5,6,6,5,4,3,2,1}
        r.model.colors={c,c,c,c,c,c}
        r.model.uvs={vec2(s1,0),vec2(s2,1),vec2(s1,1),vec2(s1,0),vec2(s2,0),vec2(s2,1)}
        r.model.normals=nor
        r.material = cm
        r.material.map=rm
    end
    
    function norm(a,b,c)
        v1=b-a
        v2=c-b
        n1=v1:cross(v2)
        table.insert(nor,n1)
        table.insert(nor,n1)
        table.insert(nor,n1)
    end
    
  • Posts: 2,024

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