Notifications
Clear all

[Closed] MNMesh cheapest update

Here is a SDK function which randomizes Editable Poly vertices.


  def_visible_primitive(randomizeAllVerts, "randomizeAllVerts");
  Value* randomizeAllVerts_cf(Value** arg_list, int count)
  {
  	check_arg_count_with_keys(randomizeAllVerts, 1, count);
  	Point3 min = key_arg_or_default(min, new Point3Value(-1.0f,-1.0f,-1.0f))->to_point3(); 
  	Point3 max = key_arg_or_default(max, new Point3Value(1.0f,1.0f,1.0f))->to_point3(); 
  
  	INode* node = arg_list[0]->to_node();
  	Object* obj = Get_Object_Or_XRef_BaseObject(node->GetObjectRef());
  	if (obj->ClassID() == EPOLYOBJ_CLASS_ID) 
  	{
  		PolyObject *poly = dynamic_cast<PolyObject *>(obj);
  		if(poly)
  		{
  			MNMesh &mesh = poly->GetMesh();
  			Point3 offset;
  			Random rand;
  			for (int i=0; i < mesh.numv; i++)
  			{
  				offset = Point3(rand.getf(max.x,min.x),rand.getf(max.y,min.y),rand.getf(max.z,min.z));
  				mesh.v[i].p += offset;
  			}
  			mesh.InvalidateGeomCache();
  			return Integer::intern(mesh.numv);
  		}
  	}
  	return &undefined;
  }
  

use it as


 randomizeAllVerts <editable poly> min:<point3> max:<point3>
 

my question is: What minimum update action do i need to add to the function to update the poly object in max viewport?

thank you for any ideas!

7 Replies

not sure…
InvalidateTopoCache() should do it

gw

1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

no. it doesn’t update.

assuming you’re using nitrous viewports…
can you try if it works with a DX viewport ?

once i had a similar problem
mesh changes were not updating in nitrous but worked fine with DX

i’ll check what i did to make it work with nitrous
guruware

ok,
what i did to work with nirous too i added:

NotifyDependents(FOREVER, PART_GEOM, REFMSG_CHANGE, NOTIFY_ALL, TRUE);

hope that helps…
guruware

in Nitrous everything updates… Problem with DX. max using cached geometry for display. So only way i found is use InvalidateHardwareMesh(). but it’s pretty heavy update and costs time.
But… if the mesh selected or doesn’t use any material applied, or max Display Color Mode is “Shaded Object” everything works without extra update. and works fast!

it seems like i found a solution… all ‘official’ poly mesh updates are very expensive. they do a lot of things those are not really necessary for right mesh viewport display. so i’ve decided to render the mesh myself. i’m using mesh->render… there was some problem with a ‘doubled’ rendering, but i’ve solved it by not sending a notification message and by setting a flag that the view redrawing was complete…

and finally… why do i dig all this sh*t? because the MAX skin is ridiculously slow! my Poly Skin modifier today works 5(!!!) times faster than max’s built-in. which means that i have a real-time playback for five 30K-poly skinned characters.

there is a comparison:
the test scene – five 30K-poly fully animated skinned meshes… all are in viewport…

and what we have:

MAX 2012 DirectX: ~2 FPS

MAX 2012 Nitrous: ~2 FPS

MAX 2014 DirectX: ~2 FPS

MAX 2014 Nitrous (DX11): ~5(!) FPS

Maya 2014: ~4-6 FPS (it’s really hard to truly test maya’s fps performance)

… and finally

MAX 2014 DirectX (Poly Skin by denisT): ~20 FPS !!!

MAX 2014 Nitrous (Poly Skin by denisT): … hmm… it’s worse than DX… it’s about 10-14 FPS. sucks, i know… but i’m working on it