Howdy, Stranger!

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

Craft texture

edited October 21 in Codea Craft Posts: 29

Hello,
Is there a way to texture only one of six sides of a craft.model.cube?
Im new at craft, please help!
I found the example „Block Library“, but they use voxels, i dont!

Thank you

Tagged:

Comments

  • dave1707dave1707 Mod
    edited October 21 Posts: 7,155

    @Silvio2400 You can do whatever you want to each side of a cube. You just have to create each side of the cube yourself. I created an example shortly after Craft came out where I created a cube and each side of the cube was a different texture. Here’s a link to the example. Increase the slider opac to show the sides. Not sure if this is exactly what you’re after.

    https://codea.io/talk/discussion/8800/craft-physics-example
    
  • Do i have to make six cubes ( walls ) to texture each side?
    or is there a other way to texture a craft.model.cube on each different side?

  • dave1707dave1707 Mod
    Posts: 7,155

    @Silvio2400 You can create a skin (texture) that can wrap around a cube that is made up of different designs. See the skins of the Blocky Characters in the Assets folder. I haven’t tried creating a cube and doing something to just one of the sides, or a least I don’t remember doing it. I’ll have to check on that.

  • dave1707dave1707 Mod
    Posts: 7,155

    @Silvio2400 Here’s an example where I’m changing the colors of one side of a cube. Whether I can change a texture of one side, I’m not sure yet.

    displayMode(FULLSCREEN)
    
    function setup()
        assert(craft, "Please include Craft as a dependency")
        assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
        fill(255)
        scene = craft.scene()
        skyMaterial=scene.sky.material
        skyMaterial.sky=color(0, 62, 255, 255)
        skyMaterial.horizon=color(99, 255, 0, 255)
        scene.sun.rotation=quat.eulerAngles(20,45,-30)
        v=scene.camera:add(OrbitViewer, vec3(0,0,0), 100, 0, 200)
        v.rx,v.ry=20,20
        createRect()
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()    
        text("Drag your finger on the screen to rotate the cube",WIDTH/2,HEIGHT-100)
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function createRect() 
        c1=scene:entity()
        c1.position=vec3(0,0,0)
    
        c1.model = craft.model.cube(vec3(20,20,20))
        side=5
        c1.model:color(side*4-3,255,0,0,255)
        c1.model:color(side*4-2,255,255,0,255)
        c1.model:color(side*4-1,255,0,255,255)
        c1.model:color(side*4,0,255,0,255)
    
        c1.material = craft.material("Materials:Standard")
        c1.material.map = readImage("Blocks:Trunk White Top")
    end
    
  • dave1707dave1707 Mod
    Posts: 7,155

    @Silvio2400 Here’s an example of changing the texture on one side of a craft cube. It uses one wall to overlay one of the sides. Not sure what you’re going to do with your cubes.

    displayMode(FULLSCREEN)
    
    function setup()
        assert(craft, "Please include Craft as a dependency")
        assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
        fill(255)
        scene = craft.scene()
        skyMaterial=scene.sky.material
        skyMaterial.sky=color(0, 62, 255, 255)
        skyMaterial.horizon=color(99, 255, 0, 255)
        scene.sun.rotation=quat.eulerAngles(20,45,-30)
        createObjects()
        v=scene.camera:add(OrbitViewer, vec3(0,0,0), 50, 0, 200)
        v.rx,v.ry=20,20
    end
    
    function createObjects()
        c1=scene:entity()
        c1.position=vec3(0,0,0)
        c1.model = craft.model.cube(vec3(10,10,10))
        c1.material = craft.material("Materials:Standard")
        c1.material.map = readImage("Blocks:Gravel Stone")
    
        wall1=createWall(1,vec3(-5,0,0),vec3(.1,10,10),vec3(.1,10,10),"Blocks:Brick Red")
    end
    
    function createWall(rest,pos,a,mod,map)
        local ww=scene:entity()
        local w=ww:add(craft.rigidbody,STATIC)
        w.restitution=rest
        ww.position=pos
        ww:add(craft.shape.box,a)
        ww.model = craft.model.cube(mod)
        ww.material = craft.material("Materials:Standard")
        ww.material.map = readImage(map)
        ww.material.blendMode = NORMAL
        return ww
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()    
        text("Drag your finger on the screen to rotate the cube",WIDTH/2,HEIGHT-100)
    end
    
    function update(dt)
        scene:update(dt)
    end
    
  • edited October 25 Posts: 29

    If you zoom right at the edge of example 2 it is‘nt smooth!
    Is there a way to fix that?

  • edited October 25 Posts: 29

    Can you please try to find out how to wrap images
    That’s exactly what i needed

  • Posts: 1,014

    @Silvio2400 - you can wrap six separate images around a cube using 3D model building in Codea. If you want to do it in Craft you have to build a obj and mat file pair with a texture map. If you know how to use Blender, a free 3D modelling package, you can generate them. There are several other packages available to do this, just search the net.

    You need to use a package that generates the Wavefront format for the files to ensure it loads into the current loader within Codea.

    Alternatively you can build one using the skybox method within Codea, search the Codea database, and modify the size of the box. You can use this alongside Craft, I have done it - but only as a Skybox proper.

Sign In or Register to comment.