Positioning a texture on a generated 3D object?

Previous topic - Next topic

Hatonastick

I've got a sphere on screen (using the primitive generation routine that came with the examples), the camera looking at it and all was well.  Then I loaded a texture and added it to the sphere object, but the whole thing is upside down and to the left.  Does this mean my object is upside down and facing to the left?  Or that my camera isn't where I think it is?  Or does my computer just hate my guts? :)

Edit: Bad code deleted.

Hatonastick

Ok I've already found some errors in the above code.  For example I had the wrong parameters for the X_ROTATION command. :)  Still not fixed.  I'm starting to think there is no exact science to this.  The texture position seems to move when I change size of the object as well as size of the texture itself.

Edit: Actually I just realised it might have everything to do with the shape I'm using (disc).  I'm guessing I need to use a program designed for altering/creating textures to fit certain shapes?  What do they call them, texture mapper or something right?

Code now looks like:
Code (glbasic) Select
SETSCREEN 600, 600, 0

// Limit our frame rate
LIMITFPS 60

// Load graphics
LOADSPRITE "BinaryLight3.png", 1
CreateSphere(1, 15, 48, RGB(255, 255, 255))

// main loop
WHILE TRUE
  X_MAKE3D 20, 600, 45
  X_CAMERA 0,0,40,0,0,0

  // Add our texture
  X_SETTEXTURE 1, -1
  // Turn the sphere into a disc
  X_SCALING 1,1,0.2
  //X_ROTATION 90,0,1,0
  X_DRAWOBJ 1, 0

  // Lets do the "flip the back and display screen" thing!  Woo hoo!
  SHOWSCREEN
WEND

// Create a sphere object.
// Code "borrowed" from GLBasic examples.
FUNCTION CreateSphere: num, r, n, col
LOCAL i,j, theta1, theta2, theta3, pi
pi = ACOS(0)*2
IF r < 0 THEN r = -r
IF n < 4 THEN n = 4

X_AUTONORMALS 2 // smooth edges
X_OBJSTART num
FOR j=0 TO INTEGER(n/2) -1
theta1 = j * 2*pi / n - pi/2;
theta2 = (j + 1) * 2*pi / n - pi/2;
FOR i=0 TO n
theta3 = i * 2*pi / n;
X_OBJADDVERTEX r*COS(theta2) * COS(theta3), r*SIN(theta2), _
r*COS(theta2) * SIN(theta3), i/n, 2*(j+1)/n, col
X_OBJADDVERTEX r*COS(theta1) * COS(theta3), r*SIN(theta1), _
r*COS(theta1) * SIN(theta3), i/n, 2*j/n, col
NEXT
X_OBJNEWGROUP
NEXT
X_OBJEND
ENDFUNCTION // n

Hatonastick

Hmm ok I have made a simple disc using Milkeshape and managed to map the texture so it looks right (gave up trying to work out the above) - how on earth do I get it into GLBasic ie. which format am I better off exporting with and then using the import tool in GLBasic?  I tried exporting as 3DS, but when I use the GLBasic tool to convert it, nothing seems to happen (other than the brief flash of what looks like a DOS command box).  Is this because my file is not an animated model?

I'm hoping to get the package Gernot recommends later on (AC3D?), this is something I bought a license for ages ago and never used - can see why, darn messy interface and a big waste of money I think...

[Edit} Aha!  I exported as a Direct X model and the GLBasic x->ddd converter worked fine. :)
[Edit] Hmm ok it worked, but not fine.  I can't get my model to display but I replacing it with one of the example ones worked.  I tried the DDD Viewer sample and loaded - again nothing.  So obviously I must have done something wrong maybe during the export from Milkshape.
[Edit] I'm exporting from Milkeshape as a Direct X 8.0 model.  Doesn't seem to be any other DirectX options, and the 3DS export doesn't seem to work.
[Edit] I now remember when and why I got Milkeshape.  Not that I like it much, it feels clunky and the UI design is very messy.  Feels thrown together to be honest.  Anyway I got it because there's a Blitz3D exporter for it.  Anyway never mind, I'm going to give up on this for now.  Far too tired. :)

Kitty Hello

For 3D Objects just make sure the texture is always power of 2 in size:
Like 64x128, 256x256, 512x512 or so...

Hatonastick

Already was mate.  I think the problem was the odd shape I was using.  Anyway I decided it might be easier (hah!) to make a model and import it instead. :)  So now it's a new problem:  I think that something is breaking down from exporter to importer, and I don't point the finger at the GLBasic tool.  I think I'm messing something up with Milkeshape.  If someone is familiar with this program and has successfully gotten a model from Milkshape into GLBasic, let me know.

Kitty Hello

I did the old Wumbo3D Model animations with MilkShape. It's excellent for importing/exporting, but the animation capabilities were crap back then.
I use Blender for animations, but it takes a day or so to get a grip on it. After you got the idea, it's pretty easy and fast to use.

Hatonastick

I suspect they still are crap. :)  Can you remember what you exported your model as from Milkshape?  And does the model have to contain animations, skeleton or similar?

Yeah I've used Blender in the past, I find it to be far too complex for my simple needs.  The 3D models I need for any games I'm currently working on aren't going to be all that complex.  I'll check it out again now though. I'm definitely wanting to give Milkshape the flick.

Kitty Hello

I think I exported as MD2 then. Yes, I animated Wumbo in MS3D -> The model itself was an AC3D model. That's the best modeller IMO.

Hatonastick

Ah well... Unfortunately Milkshape doesn't seem to want to export to MD2 any models that don't contain joints/animations.  I'm going to leave this till tomorrow.  Hopefully I'll spot what I'm doing wrong then.

Kitty Hello

does not? I think it did.
Maybe you must select the mesh?

Hatonastick

Keeps saying "Found vertices with no bone.  No animations exported!" and no file is created.  I've also tried selecting the mesh.  Maybe I'm not selecting the right exporter...

[Edit] Ok gave up on Milkeshape, and really don't like Blender.  Downloaded and tried the demo of AC3D.  Fantastic little modeler that.  Make my disc, mapped the texture, exported as 3DS, imported into GLBasic and it all worked fine. :)

[Edit] Of course AC3D doesn't do animation, so I guess I'm back looking at Blender again. :)  Or AC3D + Milkshape.  I'm really impressed with AC3D, just hope they add animation one day.  I could put up with Milkshape if the exporters did the job (especially since I already have a license for it).  Exporting from AC3D works fine, but as I've said above, none of the compatible exporters in Milkshape seem to work properly.  Very odd.  I should post on the Milkshape forum I think.

bigsofty

Quote from: Hatonastick[Edit] I now remember when and why I got Milkeshape.  Not that I like it much, it feels clunky and the UI design is very messy.  Feels thrown together to be honest.  Anyway I got it because there's a Blitz3D exporter for it.  Anyway never mind, I'm going to give up on this for now.  Far too tired. :)
MS exporters are a mixed bunch, there always seems to be caveats, esp with animated formats... I dont know why its so popular?
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Hatonastick

I don't either.  Basically I want something that allows me to make basic non-animated objects in 3D relatively easily and which will actually import into GLBsaic..  AC3D seems to fit that bill although it's a bit pricey for something that doesn't include animation.  I also need something that allows me to make "simple" animated models which can be imported into GLBasic without too much in the way of mental gymnastics.

3D really isn't my strong point and quite frankly I find Blender overwhelming despite having messed with it many times over the years, and I've yet to get a non-animated model to import from Milkshape into GLBasic.  I don't mind Anim8or which is free, but I don't think it exports to anything compatible with GLbasic.

bigsofty

What animated format are you trying to convert? I believe DDD is a mesh deformation format, ala MD2, so I guess that would be quite a good starting point.

To manually apply a texture to anything other than a simple shape would require a UV co-ordinate set. My advice would be to perceiver with Gernots converter, with a model format that includes the texture information.

Gernot, do you have a DDD file format doc? I may have a go at writing a custom file format converter for some unsupported formats?
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Kitty Hello

Don't write ddd. If you want to write a converter, use the dda format (http://www.glbasic.com/forum/viewtopic.php?id=334) and then (optionally) convert this with a small GLBasic program:
Code (glbasic) Select
X_LOADOBJ name$+".dda", 0
X_SAVEOBJ name$+".ddd", 0
END
There's 2 reasons for this:
1) The ddd file format is very, very cryptic but small in size
2) The ddd format offers you to "protect" your models against importers (sort of. X_GETFACE still works, though)
3) Somtimes I make changes to the ddd format, so you would have to keep up with it.
4) a bad ddd file might break your game, there's not much error checking in the read_ddd function.