Vertex Color and Vertex Alpha in C#

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 10 October 2012   #1
Vertex Color and Vertex Alpha in C#

I'm in the process of converting a bunch of scripts into .NET Assemblies and have finally started to get along on the process. But here is one thing I can't figure out. I cannot get the vertex color as I expect. I actually want the Vertex Alpha... but I'm stuck at the phase of simply getting the color data.

Following is a simple loop over the Verts in Imesh b.


  //IMesh b;
   string R = "";
   for (int i=0; i <= (b.Verts.Count - 1); i++) 
{
 IPoint3 theColor = b.VertCol[i];
 R += theColor.X.ToString()+"\n";
   }


But whenever this code gets executed, I'm getting:

   Object reference not set to an instance of an object.


Any help? I'm obviously missing some step.
__________________
Shawn Olson
Autodesk Expert Elite
3ds Max Charter Member

Developer of:
Wall Worm Tools for the Source Game Engine
CorVex Level Design Plugin

Last edited by wallworm : 10 October 2012 at 04:14 PM. Reason: Fixed typos.
 
Old 10 October 2012   #2
The first thing to find out would be what is actually null: b, theColor, or theColor.X?
 
Old 10 October 2012   #3
Hi Pier,

I haven't been able to get the debugger to work... my break points won't work.

So at the moment I just have the function returning the Exception.Message and it tells me that.

I know only that b is defined since it is used before and after in the code without incident.

What I am trying to do here is emulate this code from MAXScript:


	b.SetSelection #Vertex #{i}
	local theVertColor =b.getVertexColor #Alpha
 


But IMesh does not have any method that I can find like getVertexColor() (or IMNMesh, which I'm also experimenting with).
__________________
Shawn Olson
Autodesk Expert Elite
3ds Max Charter Member

Developer of:
Wall Worm Tools for the Source Game Engine
CorVex Level Design Plugin
 
Old 10 October 2012   #4
Originally Posted by wallworm: Hi Pier,

I haven't been able to get the debugger to work... my break points won't work.
If you attach the visual studio debugger to the 3dsmax process, it should pop up once the exception is thrown. Regardless of breakpoints.
 
Old 10 October 2012   #5
Originally Posted by Pjanssen: If you attach the visual studio debugger to the 3dsmax process, it should pop up once the exception is thrown. Regardless of breakpoints.


Aha... Much thanks. I come mainly from the web developer environment... so my handling of debuggers is generally a lot different. Now I can see debug info.

It appears that the problem is that b.VertCol.Count == 0 ... so b.VertCol[i] is failing.

Now the question is why? I know these objects have vertex color data in all the vertices... So again I am missing something in accessing this info.
__________________
Shawn Olson
Autodesk Expert Elite
3ds Max Charter Member

Developer of:
Wall Worm Tools for the Source Game Engine
CorVex Level Design Plugin
 
Old 10 October 2012   #6
Can you post a more complete bit of code which shows the failure?

And a little pedantic note, you for loop can be a bit simpler
for (int i=0; i < b.Verts.Count; i++)
 
Old 10 October 2012   #7
one thing that comes to mind as in with scripting max meshes the same applies to the SDK

number of verts does not always equal number of color verts
 
Old 10 October 2012   #8
Originally Posted by Pjanssen: Can you post a more complete bit of code which shows the failure?

And a little pedantic note, you for loop can be a bit simpler
for (int i=0; i < b.Verts.Count; i++)


... it was simply a result of me having confusion for a bit because of 0-based arrays in .NEt and 1-based in MAXScript... I was changing those around as I messed with it and left it at the last iteration that worked.


Originally Posted by claude666: one thing that comes to mind as in with scripting max meshes the same applies to the SDK

number of verts does not always equal number of color verts


Yes, that is true. But in these specific objects, there is always a 1-to-1 number of verts > mapverts > color verts. The type of object I'm dealing with isn't valid any other way... and the ordering of the data is always in the ordering of the verts... which is why the loop is on the verts rather than the faces--because this specific function needs to get all the info from vert 0/1 (depending on SDK/MAXScript) to the end in the mesh and output in that order.

I think my dilemma is solved, though. I had been assuming that the data for Vertex Colors was stored separately than the Map Verts. It turns out that getting the Map Verts is all I need.

So in the context of the example above (modified for a Value between 0-255, which is what I really wanted but hadn't mentioned it because it didn't matter to me yet):


R+= (b.MapVerts(-2)[i].X * 255).ToString();
 
__________________
Shawn Olson
Autodesk Expert Elite
3ds Max Charter Member

Developer of:
Wall Worm Tools for the Source Game Engine
CorVex Level Design Plugin
 
Old 10 October 2012   #9
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:20 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.