TGC Codebase Backup



Texture a primitive box using advanced vectordata UV texture mapping by rik007

6th Jun 2012 17:17
Summary

This allows you to amend an objects texture and wrap a complex texture around a simple box.



Description

Lets say you want a door, and the front and back look different to the sides. A long way around would be to create a plain for each face, texture each one and join them together. No need! You can create a simple box and 'wrap' a texture around it, by manipulating the UV data. This allows you to create complex looking objects but it is a simple cube.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem Project: Dark Basic Pro Project
Rem Created: Wednesday, June 06, 2012

Rem ***** Main Source File *****
load image "texture1.jpg",1
make object cube 1,100
texture object 1,1

make object cube 2,100
texture object 2,1

position object 1,-50,0,100
position object 2,50,0,100

        lock vertexdata for limb 1,0
        rem face 1 - front
        set vertexdata uv 0,0.333,0.5
        set vertexdata uv 1,1,0.5
        set vertexdata uv 2,1,1
        set vertexdata uv 3,0.333,1
        rem face 2 - back
        set vertexdata uv 4,1,0.5      
        set vertexdata uv 5,1,1
        set vertexdata uv 6,0.333,1
        set vertexdata uv 7,0.333,0.5
        rem face 3 - top
        set vertexdata uv 8,0,0    
        set vertexdata uv 9,0.333,0
        set vertexdata uv 10,0.333,0.5
        set vertexdata uv 11,0,0.5
        rem face 4 - bottom
        set vertexdata uv 12,0,0.5    
        set vertexdata uv 13,0.333,0.5
        set vertexdata uv 14,0.333,1
        set vertexdata uv 15,0,1
        rem face 5 - right
        set vertexdata uv 16,0.333,0
        set vertexdata uv 17,0.666,0
        set vertexdata uv 18,0.666,0.5
        set vertexdata uv 19,0.333,0.5
        rem face 6 - left
        set vertexdata uv 20,1,0
        set vertexdata uv 21,1,0.5
        set vertexdata uv 22,0.666,0.5
        set vertexdata uv 23,0.666,0

        unlock vertexdata
        
        scale object 1,100,100,25
        scale object 2,100,100,25

repeat
    text 0,0,"Press 1 for texture 1"
    text 0,25,"Press 2 for texture 2"
    text 0,50,"Click mouse to exit"
    text 0,75,"Left - UV changed. Right - original"
    
    y=y+mousemovex()/2
    x=x-mousemovey()/2

    rotate object 1,x,y,0
    rotate object 2,x,y,0
    
    a$=inkey$()
    if a$="1" then load image "texture1.jpg",1:texture object 1,1:texture object 2,1
    if a$="2" then load image "texture2.jpg",1:texture object 1,1:texture object 2,1
    
until mouseclick()