Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to make the function run faster?

3 REPLIES 3
Reply
Message 1 of 4
udumbara
581 Views, 3 Replies

How to make the function run faster?

the function below is published by FP system and used in maxscirpt

here is the code

 

bool MeshFns::meshFromPts(Mesh* pMs,Tab<Point3*>*pts, int rows, Point2* uv)
{
	
	int nmvts = pts->Count();
	int colums = nmvts / rows;
	pMs->setNumVerts(nmvts);
	for (int i = 0; i < nmvts; i++){
		pMs->setVert(i, *(*pts)[i]);

	}
	////TV verts///
	pMs->setNumTVerts(nmvts);

	float* udisls = new float[colums];
	float* vdisls = new float[rows];
	udisls[0] = 0.0f;
	vdisls[0] = 0.0f;
	float disU = 0.0f;
	float disV = 0.0f;
	float uwid = uv->x, vwid = uv->y;

	for (int i = 1; i < rows; i++)
	{
		disV += (*(*pts)[i*colums] - *(*pts)[(i - 1)*colums]).Length();
		vdisls[i] = disV;
	}

	for (int j = 1; j < colums; j++){
		disU += (*(*pts)[j] - *(*pts)[j - 1]).Length();
		udisls[j] = disU;

	}

	for (int i = 0; i < rows; i++){
		for (int j = 0; j < colums; j++){
			pMs->setTVert(i*colums + j, udisls[j] / uwid, vdisls[i] / vwid, 0.0f);
		}
	}
	////end tv verts//



	int numfcs = 2 * (rows - 1)*(colums - 1);
	int n = 0;
	pMs->setNumFaces(numfcs);
	pMs->setNumTVFaces(numfcs);
	for (int i = 0; i < rows - 1; i++){
		for (int j = 0; j < colums - 1; j++){
			pMs->faces[n].setVerts(i*colums + j, i*colums + j + 1,(i + 1)*colums + j );
			pMs->faces[n].setEdgeVisFlags(1, 0, 1);
			pMs->tvFace[n].setTVerts(i*colums + j, i*colums + j + 1, (i + 1)*colums + j);
			pMs->faces[n].setSmGroup(1);
			n += 1;
			pMs->faces[n].setVerts((i + 1)*colums + j + 1,  (i + 1)*colums + j,i*colums + j + 1);
			pMs->faces[n].setEdgeVisFlags(1, 0, 1);
			pMs->tvFace[n].setTVerts((i + 1)*colums + j + 1, (i + 1)*colums + j, i*colums + j + 1);
			pMs->faces[n].setSmGroup(1);
			n += 1;
		}
	}

	delete[] udisls;
	delete[] vdisls;
	return true;

}

this function can work ,but after run several times ,the speed obviously become slow ,I have to call gc() to clear memory.

 

I also write another function with MAXScript in same way,but the ms function run faster than the function before writed with C++.

 

 

I think there is someting wrong.

Could you tell me how to improve the function?

 

thank you

 

 

 

 

3 REPLIES 3
Message 2 of 4
maxtoolsQUR5M
in reply to: udumbara


@udumbara wrote:

...

I also write another function with MAXScript in same way


Hello,
Your question is not entirely clear, since you have not shown an example of code in MAXScript for comparison. Can you show the code of this function in MAXScript?

Message 3 of 4
denisT.MaxDoctor
in reply to: udumbara

Your c++ function looks like a grid-mesh to me ... I would make a grid-mesh using built-in methods and move the vertices to the specified positions, which is easy to do with memcpy.

 

About MXS performance ... Looks like the published function is doing something wrong and causing a memory leak. As it was correctly noted above ... before we suggest anything useful, we need to first look at how your MXS function is used in code.

 

Message 4 of 4
istan
in reply to: udumbara

I agree with the others - w/o seeing the other code impossible to say..

But one thing is already noticeable - ihmo: the parameter: "Tab<Point3 *> * pts".

How you're filling out this array?  Why you cannot use "Tab<Point3> * pts" instead?

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report