Move "handle" of CreateCube()

Blitz3D Forums/Blitz3D Beginners Area/Move "handle" of CreateCube()

Sir Gak(Posted 2005) [#1]
I am trying my hand at creating a door in Blitz3D (there's another post regarding coloring it). I have tried using the CreateCube() command, then scalemesh to form its shape into a flattish rectangle. So far, so good. Now, when I try painting it (entitytexture) with a "door.jpg" image, it works. Great!

BUT..... the door shows hinges on the left, and when I paint the door image, the hinges are on the left on both sides of the door. Logically, when hinges on on the left side of a door on one side, they should be on the right side of the door on the other side! Now, obviously, I can "flip" the image, but how do I get the image to be painted solely on one side (i.e. hinges on left side), instead of all sides (where the door's other side needs hinges on the right side)?

Another problem:
When I use turnentity with this door created via CreateCube(), the door swivels in the middle, as though the hinges were at the dead center of the top and bottom sides, instead of at the left edge (which is where hinges would be located). What's up with that, and how can I fix it so that the turnentity command will turn it off the side?


stayne(Posted 2005) [#2]
textures are put on objects according to their UV coordinates. blitz doesn't know to mirror the texture on the other side of the door. i'm pretty sure you're going to have to model the door, UV map it, and create the texture for it externally. before you do that though, make sure you look through the code archives in case someone figured out how to do it natively in blitz.

as far as opening the door with turnentity, your best bet is to create a pivot, create the door and make it a child of the pivot and then move the door over with positionentity. then turn the pivot, not the door itself. something like...

; create the pivot, create the door, then attach the door to the pivot
doorpiv=createpivot()
door=createcube(doorpiv)
scaleentity door, blah, blah, blah
positionentity door, somenumber, somenumber, somenumber

; open the door
turnentity doorpiv, somenumber, somenumber, somenumber



Sir Gak(Posted 2005) [#3]
Thanks. Yes, after I did the post, I remembered that if you use CreateCube() with a parent (in this case, a pivot), then the mesh created will start at 0,0,0, whereas CreateCube() starts a mesh at -1,-1,-1, and goes to 1,1,1. Hence, 0,0,0 is at the dead center, and so turnentity "hinges" at the 0,0,0 point, which is why the door turns along the middle (ie turnentity door,0,1,0 along the y-axis).

The whole UV system is still baffling to me, as I don't understand UV coordinates and how they relate to a 3D object.


stayne(Posted 2005) [#4]
UV mapping can be confusing as hell unless you start with the basics. every triangle rendered has to have UV coordinates if you want it to be textured. search for some tutorials. if you don't have a modeling app, download wings3d and start from there.

basic example: you create a crate (simple box) in your modeling app and you have a cool crate texture you want to wrap around it. when you do a UV map on the box, you're laying the box out flat in 2D and exporting that as a .bmp or whatever image format (which in turn creates the UV coordinates). once you have your image exported you can open it in photoshop or whatever, then copy/paste your crate texture over the image.

here's an example... it's a colt 45 i modeled. on the left is the laid out texture map with all the triangles spread out in 2D (rather hastily I might add lol), and on the right is the texture map applied back onto the colt. as you can see, every triangle is now a blank "canvas" ready to be painted on. if i copied a metal texture and pasted it onto the image on the left, the colt on the right would in turn have that wrapped around it, as long as the metal covered all the triangles on the left.

http://www.strafed.net/gallery/v/colt.jpg.html


Sir Gak(Posted 2005) [#5]
Hmmm, so let's see if I understand what you are saying....

UV mapping has to be done by a 3D modeling program, in which the application creates/exports the "flat" image version of the 3d object, and then I can paint over that flat image, so that the modeling program can re-grab the flat image, and when it wraps it around the 3D object, the texture I applied to the flat image now becomes the coloring/graphics/texture surface I wanted to apply to my 3D object?

Would you say that this is the correct understanding?


stayne(Posted 2005) [#6]
yes i would! you grasped that one well.

actually, you can use a third party UV mapping tool like UltimateUnwrap3D (soooo so worth the money). that way you can export your model from your modeling app without UV coordinates, import it into UU3D, create/export the UV map, paint on it/paste on it/whatever, then import back into UU3D and apply it to your model.

here's a hint: you can stack UV maps on top of each other. for instance, you can stack all the sides of a box on top of each other, paste your texture on top, then all sides get the texture applied to them. that trick only works for things that get the same texture though, like the wings of a plane, arms, legs, car wheels, etc. i wish i would have known this trick when i first started heh.

once you get it down pat you'll have a whole new world opened up for you. in this day and age, self-sufficiency is a must.


jfk EO-11110(Posted 2005) [#7]
Basicly good Modellers contain UV Mapping / Unwrapping Tools, but there are some dedicated UV Mappers. One is the Freeware Tool Lithunwrap 1.3.

Every Triangle of a Mesh has 3 UV Coordinates. U and V may be values of 0.0 to 1.0, representing their x/y position on the texture. It doesn't matter if the texture is 256 or 512 Pixel big, the UVs are relative to the size. If you draw a 2D triangle from the 3 UV Coordinates on the texture then you'll see the region of the texture that will be used for that triangle.

There are two Methods that may be combined:
Load a Mesh and use some Unwrapping automation, like Cube-Mapping, Cylindric Mapping, Decal Mapping etc. depending on what's most useful for a specific mesh. Then manually move and scale some parts until the texture space is used most economicly. Then save this as a UV Template. All triangles will be drawn on this BMP. Now you can Load it in a Painting App, use this template as a layer that will guide you where to put the graphics.

The other Method is to save your Texture in a painting App without to know the UV Coors, then Load the Texture in the UV Mapper App and align the UVs to the graphics.

When you're orking with Lithunwrap, there are several traps you should know. You cannot assign a selection to a material unless the selection Mode is set to group.

If you have one group and want two materials, you need to create a new group and assign a Faces Selection to it.

When Loading a new Materials Bitmap, it will not be displayed by default, you need to save it (after assigning some groups to it, of course), then reload it. Now the texture will be drawn in the background of the UV Space, allowing to align the Faces to it.

Fot the door problem you would use Cube Mapping, then Align, Scale and mirror the 6 quads (1 quad=2 tris) the way you want. In fact a door is a good first exercise.

The only problem in Lithunwrap is, usually you are not sure what side is what (up vs down vs left vs right etc.), esp. with a cube mesh whis may be confusing. In this case, save the UV map, draw some individual numbers to all sides, then load it as a material and check the Preview to see what is what.


Sir Gak(Posted 2005) [#8]
Well, I worked around the whole UV thingeee. I created a pivot, then made it the parent when I created a cube i.e.
p_pivot=CreatePivot()
door=CreateCube(p_pivot)

To stop the door from hinging in the middle, I used:
PositionMesh door,1,1,1
This moved the cube with relation to the Pivot, and thereby made the hinge happen on the left.

I still couldn't figure out the UV stuff, so I entered my door image in my paint program and simply removed the hinges. Now, it swivels on the edge, without regard to hinges. Also, I created a portcullis effect, so that doors can simply go "up" into the ceiling.


Jake L.(Posted 2005) [#9]
To get your head around UV's and UV-Mapping, try something simple: Build a quad (2 triangles with 4 vertices, see Codearchive for a quad-function), assign a texture and try some different UVs on the 4 vertices.

Basically UV's map 2D (your texture) to 3D (vertex). Cause textures have different sizes UVs use a range from 0 to 1 (instead of pixels) to cover it.

A default quad will have u/v of (0,0) for the upperleft, (1,0) for the upperright vertex and (1,1) for the lowerright vertex. This will simply display your texture like any 2D-Paint will. Then try to revert UV's (changing 0 to 1, 1 to 0) and you'll see it mirrored.

You really need to get around UVs - it's mandatory. And it's easy at all. Just google to get some graphical explanation (there should be one at www.gamedev.net in the artices-section)