Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simple Prim 1D mesh

grumble Loudon
A Little bit a lion
Join date: 30 Nov 2005
Posts: 612
12-06-2006 03:52
The goal: To make a prim type that can mimic most of the common extruded or lathed items while keeping the data size as small as possible.

One thing to remember is that all prims (ignoring trees) are extrusions of a base pattern. A Sphere is a circle that is stretched and then shrunk along a sine wave path. Given this it would actually be possible to make a primitive prim mesh where you could specify the base pattern using a list of points and then the list of extrusion path points.

Here are some examples to describe the concept in a more programmatically manor.

To assemble the arrays you start with a sphere and replace the extrusion circle with the base pattern and you replace the sine wave arc with the second 1D array.

WARNING: The following is a cross between C++ and PHP and will not compile.
CODE

struct STRUCT_1D_POINT16 {
int16 x; // representing -100% to 100% of the Size.
int16 y; // representing -100% to 100% of the Size.
}
#define f(n) (int16)(n * 0x7FFF)

// Here is a 1m cube using the concept.
//I know it would be silly to make a cube using this method, but it’s possible,
struct SendACube {
//usual object items ObjectType = TYPE_1D_MESH;
vector size = <1, 1, 1>;
byte BaseSegmentCount = 4;
STRUCT_1D_POINT16 Bsp[] = {f(1), f(1)},{ f(1), f(-1)},{ f(-1), f(-1)},{ f(-1), f(1)};
byte ExtrusionSegmentCount = 0;
//blank
}

//here is a tube with a flare on one end.
struct SendACube {
//usual object items ObjectType = TYPE_1D_MESH;
vector size = <1, 1, 10>;
byte BaseSegmentCount = 0;
//blank
byte ExtrusionSegmentCount = 2;
STRUCT_1D_POINT16 Esp[] = {f(.8), f(-1)},{ f(.8), f(.5)},{ f(1), f(1)};
}


Here is the deconstruction concept in code like structures
CODE

//create base point array
struct POINT_F {
float x;
float y;
}
#define n2f(n) (float)( (float)n / (float)0x7fff);

POINT_F BasePoints[MAX_POINTS] ;
integer BasePointCount = Prim-> BaseSegmentCount;
if (BaseSegmentCount = 0){
//Load a circle into array based on LOD
}else{
for (int i = 0 ; i< BasePointCount;++i){
BasePoints.x = n2f(Prim->Bsp.x) * Prim->size.x;
BasePoints.y = n2f(Prim->Bsp.y) * Prim->size.y;
}
}

//The array is extruded based on X as the scale
// and Y as the point on the extrusion.
if (prim-> ExtrusionSegmentCount = 0){
//load points {1,-1},{1,1};
}else{
//load points as above
};

//Extrude using Y as percent of extrusion and X as scale.

//1. Add tris of base using first ExtrusionSegment
//2. Fill middle as needed using
//3 Add tris of top using last ExtrusionSegment


Possible future improvements.
1. Add the ability to add Bezier points in the 1D arrays. This would make it easier to make rounded curves.
grumble Loudon
A Little bit a lion
Join date: 30 Nov 2005
Posts: 612
12-09-2006 12:41
Changing the Extrusion scale array so that it has a separate X and Y would allow for other common shapes like stairs.

Another thought would be to separate the two extrusion systems so that you could base the extrusion or the scale path using common objects.

Example: Stairs
//1 usual object items ObjectBase = Cube, ObjectExtrusion = TYPE_1D_XY_SCALE;
//2 Count of points
//3 A series of X Zig zags with Y = 1

The saw tooth prim would look like a series of boxes connected at the edges and would then be tilted at an angle to make the steps flat.

The bottom side would also be stepped, but that is ok.

I also know that there is no way to make the editor edit things like this, but I can imagine scripts automating it.

PS: There are so many votes in the voting tool that I have given up on it and I see this forum as a better place to suggest solutions.