Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - [Matrix1Utils] Make segmented box primitive

Author
Message
MonoCoder
18
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 23rd Nov 2013 20:47 Edited at: 23rd Nov 2013 22:35
MakeSegmentedBox(
- object number
- width, height, depth
- width segments, height segments, depth segments
)



Create a box primitive with each face divided into a variable number of segments. Works like the 3ds Max box primitive.

Function



Example
instructions on-screen (edit: can move camera base with arrow keys now)


Notes
- This can probably done more easily and quickly by sticking a few plane primitives together, but this was a learning experience.
- Some aspects (particularly UVs) involved a lot of trial and error, so there's probably a lot that could be optimised. The way polys are added is a little haphazard; certainly, I wouldn't make any assumptions as to what number vertices can be found where.
- As far as I can tell thus far though, it's bug free
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Jan 2014 11:29
Hi there
I hadn't see this code before . I'm astonished, this is brilliant...!! .Playing with vertexdata is what I like best. I will keep it

I'm not a grumpy grandpa
MonoCoder
18
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 20th Jan 2014 22:21 Edited at: 21st Jan 2014 17:40
Thanks : )

Some development:
I think the reason the object has intra-box face tears when jittered with a naive per-vertex method is because I haven't properly shared vertices between polygons (ie. each box face is just a landscape of disconnected tiles).

Rather than fix that, I've written a new version of the function which I'm sure is better:





(the result is slightly different in another way, however, in that you can no longer deform it by changing limb zero's verts; you have to change 6 limbs, one for each box face. I tried to make an alternate version that uses the method above then packs all verts back into limb zero, but couldn't do it.)

In any case, you'd still get inter-box face tears with per-vertex jitter; I don't think there's any way around that - if all box faces shared their edge verts they'd share their normals too...


edit: Updated example with improved camera.






.
MonoCoder
18
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 23rd Jan 2014 01:37 Edited at: 23rd Jan 2014 12:27


Just for fun, I've improved the world space tripod from the example. It should be unproblematic moving it to other projects without modification (provided you need just the one).

Also made the camera base-position indicator easier to read (haven't properly formalised it though, so will need modification).



Not entirely a tangent - the centre-cube of the tripod is made as a segmented cube so I can colour each limb/face seperately.

The tripod alone:


.

Login to post a reply

Server time is: 2024-11-23 08:02:10
Your offset time is: 2024-11-23 08:02:10