sdk How int Convert Bitarray and Bitarray Convert int?

sdk How int Convert Bitarray and Bitarray Convert int?

4330822
Participant Participant
1,181 Views
8 Replies
Message 1 of 9

sdk How int Convert Bitarray and Bitarray Convert int?

4330822
Participant
Participant

4330822_0-1669537717958.png

 

0 Likes
1,182 Views
8 Replies
Replies (8)
Message 2 of 9

istan
Advisor
Advisor
0 Likes
Message 3 of 9

4330822
Participant
Participant

Yes, but I don't know how to convert an int value to a bit array. It only provides a constructor to pass in an int value, set the size, not the real value. In maxscript, you can convert it to an as array

0 Likes
Message 4 of 9

klvnk
Collaborator
Collaborator

 

BitArray vertsel(mesh.numVerts);
vertsel.Set(vertindex);

 

though you have to be careful vert index != normal index 

 

0 Likes
Message 5 of 9

4330822
Participant
Participant

4330822_0-1669555864310.png

I seem to be a little confused. I get a vertex serial number a, and I want to get the corresponding normal serial number through a, which seems to fail to work

0 Likes
Message 6 of 9

istan
Advisor
Advisor
qickn dirty bitarr -> intarr code
BitArray arr;
Tab<int> iarr;
for (int i=0; i<arr.GetSize(); i++) if (arr[i]) iarr.append(1,i);
0 Likes
Message 7 of 9

klvnk
Collaborator
Collaborator


 

 

there isn't always a corresponding normal to a vert there maybe several

you need to know what faces are used by the vert then get the corner of the vert in that face and from there get the normal ID (it's very similar to how uv's work) they may all share the same normal ID but they may not.

 

if you are doing a lot changes to normals working from vert indexs but no changes to the geometry you can build a reverse look up table vert to face and corner

 

 

 

 

typedef std::pair<int, int> fcorner;
typedef std::vector<std::deque<fcorner>> vertfacelookup;

void BuildVertFaceLookUpTable(Mesh& mesh, vertfacelookup& vfac)
{
	vfac.clear();
	vfac.resize(mesh.numVerts);
	Face* faces = mesh.faces;
	for(int f = 0; f < mesh.numFaces; ++f, ++faces)
	{
		vfac[faces->v[0]].push_back(fcorner(f,0));
		vfac[faces->v[1]].push_back(fcorner(f,1));
		vfac[faces->v[2]].push_back(fcorner(f,2));
	}
}

 

 

 

 

then getting the normals becomes something like.....

 

 

 

 

void PrintVertNormals(int vert, IEditNormalsMod* enm, vertfacelookup& vfac)
{
	std::deque<fcorner>& vfaces = vfac[vert];

	for(int i = 0; i < vfaces.size(); ++i)
	{
		int normalID = enm->EnfnGetNormalID (vfaces[i].first, vfaces[i].second);
		Point3* normal = enm->EnfnGetNormal(normalID);	
		mprintf(_T("[%f,%f,%f]\n"), normal->x, normal->y, normal->z);
	}
	
}

 

 

 

0 Likes
Message 8 of 9

denisT.MaxDoctor
Advisor
Advisor

what is the reason to use 

std::deque

if you use only push_back?

0 Likes
Message 9 of 9

klvnk
Collaborator
Collaborator

deques are useful when you don't know what the size  is going be (they don't even have resize() as they don't need it) You could use a vector and reserve( arbitary_amount) if you want or just let it reallocate as it goes, what ever float yer boat. Could even use Max Tab.

 

vector vs list vs deque 

0 Likes