3D object manipulation

Previous topic - Next topic

Crivens

Is it possible to alter a 3D object's core values? Say to alter the coords of a single 3D vertex? More importantly, for me, I would like to change the colour of a vertex of a 3D object (or at least to change the complete object to be a certain colour).

Main reason for me is I have some primitive 3D objects that are simply coloured with the X_OBJADDVERTEX command. At a later point I want to change that colour without using a different object or a different coloured texture. Another routine I have uses changing lighting to give a pulse effect on 3D objects, but because of problems with iOS it would be better if I could just change the core colour on the fly giving a similar effect.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Slydog

I wanted to do the same thing in my game.
I tried creating a shader that you pass a colour to, and it tints the object in that shade.
It worked great on the PC, just not for iOS (different OpenGL version? or something).

That was my next option too, just recreate the object (they are all created dynamically anyhow).

I think the 'X_GETFACE()' command gives you the vertex details of an object.
You could create a generic function that you pass on object id, and a colour.
It could strip the vertex info, and recreate the vertices with the new colour.

I don't know how slow that would be however!
Especially something you want changed per frame, like in a pulse effect.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Ruidesco

Having an object with pre-made multiple frames where each is coloured as needed seems to be the least CPU-consuming possibility.

Crivens

Hmm, probably. Although if it's only a single cube or plain then might not be that slow. Good point about frames. How do you go about inserting frames into a 3d object?

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Ruidesco

At runtime? It's not possible yet :( but Gernot agreed that it will be implemented. :good:
What I meant is that .ddd objects created with the 3D Converter can have multiple keyframes, so that might be a way to do what you need.

Slydog

I think that feature was recently requested (inserting frames into object).
Gernot says he added it to the 'to do' list!

http://www.glbasic.com/forum/index.php?topic=3843.msg57694#msg57694

[Edit] Oops, i was too slow!
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Slydog

Memory wise, or speed wise, or any other reason, are frames better than just an array of objects?

You could do 'frames' on your own by pre-generating a bunch of cubes (in this case) with different colours, each with an object id.
Add those ids to a list / array, then display the cube you want from that array list.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Crivens

I thought of multiple objects but would be 255 for the colour cycle. Not great. Would be nice to duplicate object with a change to the colour.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Kitty Hello

don't use colours - it's slow on mobile devices.
Use textures instead. If you want to swap colours, swap textures used. Might this work for you?

Slydog

QuoteUse textures instead.

You could use the 'X_SETTEXTUREOFFSET()' command, along with a gradient texture.
(A texture with multiple colours, maybe each colour a pixel by a pixel, or larger if bleeding occurs)

IF your objects are simple solid colours, then the texture coordinates could all be set to pixel 1, 1. (or the first colour in the gradient)  To change the object colour, just call X_SETTEXTUREOFFSET before drawing that object, and set the offset to the proper colour in your texture gradient.

This doesn't work of course if your objects aren't just a solid colour.  You could still use X_SETTEXTUREOFFSET with a textured object, you'd just have to include all coloured versions of that texture in one texture.

Or, combine both a gradient and a regular texture, and assign multiple textures to an object, with the gradient being a colour overlay.  I don't know how to do this in GLBasic, but two textures is possible in OpenGL I think.  Then you still need to offset ONLY the colour overlay texture, if possible.

Hmm, now I have to rethink about abandoning my attempts at colour cycling!  Shader approach had iOS issues.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Kitty Hello

nah. Just update the texture. (CREATESCREEN)

Crivens

It's a simple 3d plain with a complicated texture not a simple one. I cycle the light colour so it gives it a cop car type effect. Unfortunately as was reported elsewhere on the forum iOS devices just don't look that good with lighting. I can get away with it but it's a lot more washed out (brightness or colour changes seemingly make no difference)

Because of the colour cycle I would need 256 textures to simulate the effect.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Kitty Hello

Can you give an example program/video hint? I can't imagine what you try to do.
It should be pretty easy to do with updating the texture in my mind. I might have the wrong impression of what you try, though.

Slydog

Quote from: Kitty Hello on 2011-Oct-18
nah. Just update the texture. (CREATESCREEN)

Is CREATESCREEN fast enough to use per frame?
So each frame, he could draw the texture to another screen via CREATESCREEN, using POLYVECTORS to set the current colour, then use that new sprite as the object's texture?
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Crivens

#14
QuoteIs CREATESCREEN fast enough to use per frame?
I'd rather not. Another post earlier showed that a 60FPS app crawled to 30FPS on retina when createscreen was used for resolution scaling. I've only just got my app upto 60FPS at retina resolution and don't want to lose it again...

QuoteCan you give an example program/video hint? I can't imagine what you try to do
I can dig out the code later. And it works, just not in iOS 100% correctly (ie. the problem with the lights being washed out when used in iOS that we talked about before).

Essentially using 3ES just create a 3D textured cube (mine is a single faced plane to speed things up as much as possible but it makes no difference, and the texture itself isn't important) then create a light. The plane then obviously gets effected by the light. Then for each showscreen (or timer based I forget which) I simply cycle the lights colour. It basically cycles from 0 to 255 and back again, giving an impression of a pulsating light. Only on iOS the colours look washed out (as if brightness is too high but lowering it doesn't help as that washed out look is still there). Everything else (WebOS and PC) looks fine.

When creating the cube then if a colour is given to each vertex then the texture will be effected by that colour (like polyvector). So I thought an alternative solution would be to amend the vertex colour values for the object in question to use this colour cycling rather than using an actual light. It would also be nice in the future if I use 3D objects for the GUI (any news on the fix for 3ES for sticky 2D objects which didn't update to the correct 3D position on my project?) so the lighting doesn't effect them (unless you can turn off lighting on an object - can you? If so then I would go with that as it pretty much covers what I want).

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.