Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help - Programmatically creating sculpties

Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
05-29-2009 20:23
I'm trying to create a simple flat sculptie using a C# program and am clearly missing something on how the sampling is being done by SL. The PNG file I'm creating uses row and column positions at 0, 2, 4...62, 63 in X and Y and planar stitching. The other cells are all set to (111, 111, 111). All cells have alpha set to 255.

If there were 8 rows and columns, with + for colored and ~ for empty cells it would be:

+~+~+~++
~~~~~~~~
+~+~+~++
~~~~~~~~
+~+~+~++
~~~~~~~~
+~+~+~++
+~+~+~++

The contents of the colored cells range from (0, 255, 128) in the upper left to (0,0,128) at the lower left to (255, 0, 128) at lower right, to (255,255, 128) at the upper right.

When imported lossessly and using planar stitching, this renders as a kind of bowtie shape of two triangles arranged point to point with the common point displaced slightly negative from the origin in each axis. This makes me think that the "unused" rows are being rendered. Running the same code with no empty rows results in a perfect plane.

Clearly I'm not understanding how the sampling is being done and would greatly appreciate some enlightenment.

Thanks.
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
05-30-2009 02:02
From: Ralph Doctorow
When imported lossessly and using planar stitching, this renders as a kind of bowtie shape of two triangles arranged point to point with the common point displaced slightly negative from the origin in each axis. This makes me think that the "unused" rows are being rendered.


It depends on the sculpty size and LOD which pixels are used. 64 x 128 for example has hardly any common pixels between the various LODS. I handle this in the Primstar Blender scripts with the following python code:

quote this post for tab spacing
CODE
def lod_size(width, height, lod):
'''Returns x and y face counts for the given map size and lod'''
sides = float([ 6, 8, 16, 32 ][lod])
ratio = float(width) / float(height)
verts = int(min(0.25 * width * height, sides * sides))
y_faces = int(sqrt(verts / ratio))
y_faces = max(y_faces, 4)
x_faces = verts // y_faces
x_faces = max(x_faces, 4)
y_faces = verts // x_faces
return x_faces, y_faces

def vertex_pixels(size, faces):
'''Returns a list of pixels used for vertex points on map size'''
pixels = [ int(size * i / float(faces)) for i in range(faces) ]
pixels.append(faces - 1)
return pixels

def map_pixels(width, height):
'''Returns ss and ts as lists of used pixels for the given map size.'''
ss = [ width - 1 ]
ts = [ height - 1 ]
for i in [3,2,1,0]:
u,v = lod_size(width, height, i)
for p in vertex_pixels(width, u):
if p not in ss:
ss.append(p)
for p in vertex_pixels(height, v):
if p not in ts:
ts.append(p)
ss.sort()
ts.sort()
return ss, ts


So vertex_pixels(64, 32) gives list of pixels used at LOD3, vertex_pixels( 64, 6 ) gives a list used at LOD0.

map_pixels(64, 64) returns two lists for u and v pixel usage across all 4 LODs. This is how my finalise code which setups the map for mirroring in SL knows which pixels it can work on.

The complete list of used pixels for a standard sculptie (6, 8, 16, 32 faces on 64 pixels) is [0, 2, 4, 5, 6, 7, 8, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 26, 28, 30, 31, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 53, 54, 56, 58, 60, 62, 63]

For a 64 x 128 map, the results are:

u points = [0, 2, 3, 4, 5, 8, 10, 11, 12, 14, 16, 17, 20, 21, 23, 25, 26, 29, 32, 34, 37, 38, 40, 43, 46, 48, 49, 51, 52, 55, 58, 61, 63]

v points = [0, 2, 5, 8, 10, 11, 13, 14, 16, 19, 21, 22, 25, 27, 28, 30, 32, 33, 36, 38, 41, 42, 44, 45, 47, 50, 52, 53, 55, 56, 58, 61, 64, 66, 69, 71, 72, 74, 75, 77, 80, 83, 85, 86, 89, 91, 94, 96, 97, 99, 100, 102, 105, 106, 108, 111, 113, 114, 116, 117, 119, 122, 125, 127]

This is because of the face counts for this particular map which are:

LOD3:22x46
LOD2:11x23
LOD1:5x12
LOD0:4x9

Oh, and on sculpties 0,0 is bottom left, so your +~+~+ thing should have the bottom row at the top..
Omei Turnbull
Registered User
Join date: 19 Jun 2005
Posts: 577
05-30-2009 13:21
Do the two trianges lie in a common plane? If so, I don't think your problem is one of misunderstanding which points are sampled.

A picture of what it looks like in SL would help. It's just a guess, but is the "bowtie" planar and only one of the triangles visible from any one viewpoint?
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
05-30-2009 13:50
From: Omei Turnbull
Do the two trianges lie in a common plane? If so, I don't think your problem is one of misunderstanding which points are sampled.

A picture of what it looks like in SL would help. It's just a guess, but is the "bowtie" planar and only one of the triangles visible from any one viewpoint?


My last comment is the most important one ;)

He's only baking hot rows, rest are mid grey, so by getting the 0,0 at top left instead of bottom left, he's getting first row 0 and last row 63 hot as expected, all even rows 2,4,8 etc are mid grey, hence the bowtie.
Omei Turnbull
Registered User
Join date: 19 Jun 2005
Posts: 577
05-30-2009 14:54
From: Domino Marama
My last comment is the most important one ;)

He's only baking hot rows, rest are mid grey, so by getting the 0,0 at top left instead of bottom left, he's getting first row 0 and last row 63 hot as expected, all even rows 2,4,8 etc are mid grey, hence the bowtie.
Yes, that does seem to fit his description. I think you're right. I have to admit that I never got to the end of your post, since it appeared to me to be going off on a tangent.:o
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
05-30-2009 15:17
From: Omei Turnbull
Yes, that does seem to fit his description. I think you're right. I have to admit that I never got to the end of your post, since it appeared to me to be going off on a tangent.:o


He he... It sort of was.. But anyone wanting to deal with just the hot pixels needs something like those routines to figure things out. This seemed an ideal moment to release my versions outside of the GPL license the rest of the Primstar scripts are under.

Lets see.. posted in an open forum, no copyright notice.. I think it's safe to treat them as public domain. Happy coding everyone ;)
Drongle McMahon
Older than he looks
Join date: 22 Jun 2007
Posts: 494
LODdite mainfesto
05-30-2009 16:06
Or everyone can stick to 2^(2*n) quads; 2<= n<=5, and all will stay nice and simple as it should be.
Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
Bingo! Many Thanks Domino!!!
05-30-2009 16:52
That did the trick, flipping the vertical axis so row 63 is at the top of the image and row 0 at the bottom fixed it perfectly.

Once I play with the other stitching and LOD parameters a bit more I'll do a complete write up of it. The technical discussion in the Wiki is (at least to me) pretty misleading / incomplete.

Thanks again,
Ralph
Drongle McMahon
Older than he looks
Join date: 22 Jun 2007
Posts: 494
05-30-2009 18:08
From: Ralph Doctorow
Once I play with the other stitching and LOD parameters a bit more I'll do a complete write up of it. The technical discussion in the Wiki is (at least to me) pretty misleading / incomplete.
Such a clear definition would be a good thing for all, especially if you can get Domino to check it for accuracy.
Gaia Clary
mesh weaver
Join date: 30 May 2007
Posts: 884
05-31-2009 03:55
Sorry, this post was meant for another thread. i deleted it ...
Infiniview Merit
The 100 Trillionth Cell
Join date: 27 Apr 2006
Posts: 845
06-01-2009 02:17
Which exact program are you guys using for this?
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
06-01-2009 03:15
From: Infiniview Merit
Which exact program are you guys using for this?


My code above was written for use in Blender, but there's no Blender specific stuff in there so it just needs Python.

Ralph is coding his own in C# - don't use that myself, so not sure of platform requirements, I think it's mono?
Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
06-01-2009 14:48
I'm using C# in XP with .NET 3.5. I use C# for my RL work and like it a lot but have just started playing with 3D programming which I'm doing with WPF.

I don't think Mono supports WPF or all of .NET 3.5 as of yet.