creating 'Sculpties' for Second Life
All  1-7  8-12

Previous
Next
 From:  Michael Gibson
597.8 In reply to 597.7 
The OpenNURBS library does provide the code for evaluating the 3D point location of a surface at a particular u,v NURBS parameter location. So that method would actually probably involve writing less new code on your part.

The tricky part may just be navigating through the structure of a NURBS model if you are not familiar with that.

Here is a quick overview that should jump start you.

First, you need to download the OpenNURBS toolkit, this is a library that lets you read the contents of .3dm files, that's at http://opennurbs.org

There is an example project in there called example_read, that shows the basic steps to open a .3dm file and read it into memory. Basically you open a file, then define an ON_BinaryFile object that takes the file pointer, and then there is kind of a high level helper class called ONX_Model that sort of represents the entire model file contents, which can be populated by a call to ONX_Model::Read().

ONX_Model has a member called m_object_table, this is an array that holds all the objects that were sucked out of the .3dm file, each entry in the array is an ONX_Model_Object.

There are various types of objects, like a curve object, a brep object, etc... - you'll want to look for a brep object. I guess you'll probably expect to have just a single surface saved in the file.

ONX_Model_Object has a member m_object, which is an ON_Object, this is the generic base class for the various object types.

To test if the object is a brep, you do something like this:

ON_Brep* pBrep = ON_Brep::Cast( m_object );
if ( pBrep != NULL )
{
// It's a brep, use it.
}

Basically that tests if the generic object is actually a brep object and then casts it to a brep pointer so now you have a brep to work with.

If you're assuming that the brep is made up of just a single surface, you can access that surface by calling

ON_Surface* pSrf = pBrep->m_S[0]; // Grab the first surface of the brep.

Now that you have the surface, you can evaluate points on it. First you need to get the boundaries of the surface's uv space. Surfaces don't necessary have uvs that start at 0 and go to 1, they can be between any range. So to grab the ranges:

double UMin, UMax, VMin, VMax;
pSrf->GetDomain( 0, &UMin, UMax );
pSrf->GetDomain( 1, &VMin, VMax );


Now to evaluate points - you'll step between those ranges. So for example if you want to evaluate 16 steps along the surface, you will go in sixteenth increments between UMin and UMax for the u coordinate, same for v. So that gives you numbers for a u,v point.


Now you can get the 3D point for this UV parameter value by calling:

ON_3dPoint pt = pSrf->PointAt( u, v );

And that's your x,y,z point for that one spot.

Note that I just wrote this up quickly, I didn't test anything so there may be typos above. But those are the basic steps.

If you give it a try, I can probably help you out if you get stuck on something.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Cindy
597.9 In reply to 597.8 

Now you wrote almost the complete Program for me :)
I got the first Result already, i wrote the vertices to a .obj File and fed it to my old obj2sculpt Program
(its C#, so i cant simply copy and paste it to the C++ program).
The Result looks good. I guess it works.
Now its time for more testing, some cleanup and making it easy to use.

/me bows to the Master of 3D Programming

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
597.10 In reply to 597.9 
Wow, that was quick Cindy, that's really cool!

Is there any way to create a file that represents an assembly of multiple 'Sculpties' that are positioned in relation to one another?

I guess right now if you wanted to make a more complex object made out of multiple untrimmed NURBS surfaces, it would be kind of difficult because each different sculpt map that you create probably represents an object centered around its own local origin. So I guess you would have to manually reposition each surface into its proper relative place later on.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Cindy
597.11 In reply to 597.10 
It should be possible, using LSL (the Second Life Scripting Language).
I still have some testing and Bugfixing to do, to get the best possible Result.
At the Moment, the origin of my Sculpties is off Center, this will be next.
My Program exports only a single Object now, but support for multiple
Objects would be a nice Feature - and not too hard to do.
I think the Perfect Sculptie Export would do these extra Steps :
-Scale all Axes to the Maximum, prior to the Rounding.
(for best Resolution, 8 Bits is not much)
-Create a LSL Script to scale the Object back
..and maybe align multiple Objects to fit together...
Well, a Programmer's work is never done. ;)
But first, i try to solve the off-center Problem.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Michael Gibson
597.12 In reply to 597.11 
> Well, a Programmer's work is never done. ;)

I know that feeling! :)

The nice thing about your stand-alone tool is that it can be used with a few different programs - MoI, Rhino, and I think that Ayam modeler can save a NURBS surface in a .3dm file, and possibly some other CAD programs like SolidWorks...

One other idea - probably right now you are doing that even stepping in UV space - that's a type of "uniform" tessellation.

That can be a problem if the surface has different behavior in different areas. Like if the surface is fairly flat in one half of it, but wiggly in the other half, you're still going to place a bunch of points in the flat area where it doesn't really need the points.

A different style, "adaptive" tessellation, would do something like subdivide UV space into half by placing one point in the middle, then try to analyze each of the remaining halves and if one of them was pretty flat then it would not add any more in that half and instead continue adding more in the bendy part.

That would be a way to try and optimize the point placement.

It's a bit tricky, but I could help you with it a bit at some point if it seems like it would improve the quality. It may not make much of a difference if people are doing mostly fairly evenly curved things. In fact one problem is if things are really evenly curved maybe the uniform way is actually a bit better spacing than adaptive...

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
 
Show messages: All  1-7  8-12