コード例 #1
0
ファイル: EditFaceData.cpp プロジェクト: 2asoft/xray
void EditFaceDataModData::ApplyChanges (MNMesh & mesh) {
	// Make sure we're sized correctly for this mesh.
	// (NOTE: If the user reduces, then increases input number of faces, we lose data.)
	if (mesh.numf != mFaceSel.GetSize()) SynchSize (mesh.numf);

	// Set the selection:
	mesh.FaceSelect (mFaceSel);

	// Get the face data manager from the mesh:
	DebugPrint ("EditFaceDataMod: Getting manager from MNMesh (0x%08x)\n", &mesh);
	IFaceDataMgr *pFDMgr = static_cast<IFaceDataMgr*>(mesh.GetInterface (FACEDATAMGR_INTERFACE));
	if (pFDMgr == NULL) return;

	SampleFaceData* fdc = dynamic_cast<SampleFaceData*>(pFDMgr->GetFaceDataChan( FACE_MAXSAMPLEUSE_CLSID ));
	if ( fdc == NULL ) {
		// The mesh does not have our sample face-data channel so we will add it here
		fdc = new SampleFaceData();
		fdc->FacesCreated (0, mFaceSel.GetSize());
		pFDMgr->AddFaceDataChan( fdc );
	}

	if (!mFacesAffected.NumberSet ()) return;

	for (int i=0; i<mFacesAffected.GetSize(); i++) {
		if (!mFacesAffected[i]) continue;
		fdc->SetValue (i, mtNewFaceValues[i]);
	}
}
コード例 #2
0
ファイル: EditFaceData.cpp プロジェクト: 2asoft/xray
float EditFaceDataModData::FaceValue (int faceID) {
	if (faceID<0) return 0.0f;
	if (faceID>mFacesAffected.GetSize()) return 0.0f;
	if (mFacesAffected[faceID]) return mtNewFaceValues[faceID];
	IFaceDataMgr *pFDMgr = NULL;
	if (mpCacheMesh && (faceID < mpCacheMesh->numFaces)) {
		// Get the face data manager from the mesh:
		pFDMgr = static_cast<IFaceDataMgr*>(mpCacheMesh->GetInterface (FACEDATAMGR_INTERFACE));
	}
	if (mpCacheMNMesh && (faceID < mpCacheMNMesh->numf)) {
		// Get the face data manager from the mesh:
		pFDMgr = static_cast<IFaceDataMgr*>(mpCacheMNMesh->GetInterface (FACEDATAMGR_INTERFACE));
	}
	if (pFDMgr == NULL) return 0.0f;
	SampleFaceData* fdc = dynamic_cast<SampleFaceData*>(pFDMgr->GetFaceDataChan( FACE_MAXSAMPLEUSE_CLSID ));
	if (!fdc) return 0.0f;
	float val;
	if (!fdc->GetValue (faceID, val)) return 0.0f;
	return val;
}
コード例 #3
0
ファイル: ExportFaceData.cpp プロジェクト: artemeliy/inf4715
BOOL FaceDataExport::nodeEnum(INode* node,Interface *ip) {	
	if(!exportSelected || node->Selected()) {
		ObjectState os = node->EvalWorldState(ip->GetTime());

		IFaceDataMgr *pFDMgr = NULL;
		if (os.obj->IsSubClassOf(triObjectClassID)) {
			TriObject *tobj = (TriObject *)os.obj;
			Mesh* mesh = &tobj->GetMesh();
			pFDMgr = static_cast<IFaceDataMgr*>(mesh->GetInterface( FACEDATAMGR_INTERFACE ));
		} else if (os.obj->IsSubClassOf (polyObjectClassID)) {
			PolyObject *pobj = (PolyObject *)os.obj;
			MNMesh *mesh = &pobj->GetMesh();
			pFDMgr = static_cast<IFaceDataMgr*>(mesh->GetInterface( FACEDATAMGR_INTERFACE ));
		}
		if (pFDMgr == NULL) return FALSE;

		SampleFaceData* SampleDataChan = NULL; 
		IFaceDataChannel* fdc = pFDMgr->GetFaceDataChan( FACE_MAXSAMPLEUSE_CLSID );
		if ( fdc != NULL ) SampleDataChan = dynamic_cast<SampleFaceData*>(fdc);
		if ( SampleDataChan == NULL) {
			fileStream.Printf(_T("Node %s does not have our Face Data\n"),node->GetName());
			return false;
		}

		//OK so We have Face data lets dump it out..
		fileStream.Printf(_T("\nNode %s has %d faces with FaceFloats\n"),node->GetName(), SampleDataChan->Count());
		for(ULONG i=0;i<SampleDataChan->Count();i++) {
			float data = SampleDataChan->data[i];
			fileStream.Printf(_T("Face %d, float %f\n"),i,data);
		}
	}

	// Recurse through this node's children, if any
	for (int c = 0; c < node->NumberOfChildren(); c++) {
		if (!nodeEnum(node->GetChildNode(c), ip)) return FALSE;
	}

	return TRUE;
}
コード例 #4
0
void FaceDataToColorMod::ModifyObject(TimeValue t, ModContext &mc, ObjectState * os, INode *node) {
	if (mDisabled) return;

	IFaceDataMgr* pFDMgr = NULL;

	// We can work with Face Data in a couple different object types:
	TriObject *pTri = NULL;
	PolyObject *pPoly = NULL;
	Mesh *pMesh = NULL;
	MNMesh *pMNMesh = NULL;
	int numFaces = 0;

	if (os->obj->IsSubClassOf(triObjectClassID)) {
		pTri = (TriObject*)os->obj;
		pMesh = &(pTri->GetMesh());
		numFaces = pMesh->getNumFaces();
		// Get the face-data manager from the incoming object
		pFDMgr = static_cast<IFaceDataMgr*>(pMesh->GetInterface( FACEDATAMGR_INTERFACE ));
	} else if (os->obj->IsSubClassOf(polyObjectClassID)) {
		pPoly = (PolyObject*)os->obj;
		pMNMesh = &pPoly->GetMesh();
		numFaces = pMNMesh->numf;
		// Get the face-data manager from the incoming object
		pFDMgr = static_cast<IFaceDataMgr*>(pMNMesh->GetInterface( FACEDATAMGR_INTERFACE ));
	}

	if (pFDMgr == NULL) return;

	//Get our parameters
	int channel;
	float r, g, b;
	Interval ourValidity = os->obj->ChannelValidity (t, TOPO_CHAN_NUM);
	mpParams->GetValue (pb_channel, t, channel, ourValidity);
	mpParams->GetValue (pb_red, t, r, ourValidity);
	mpParams->GetValue (pb_green, t, g, ourValidity);
	mpParams->GetValue (pb_blue, t, b, ourValidity);

	// Get at our SampleFaceData:
	SampleFaceData *pFaceData = dynamic_cast<SampleFaceData *>(pFDMgr->GetFaceDataChan (FACE_MAXSAMPLEUSE_CLSID));

	// Apply the colors - different code depending on object type:
	if (pMesh) {
		pMesh->setMapSupport (-channel, true);
		pMesh->setNumMapVerts (-channel, 3*numFaces);
		TVFace *pFace = pMesh->mapFaces(-channel);
		VertColor *pColor = pMesh->mapVerts (-channel);

		int maxFaceData = pFaceData ? pFaceData->Count() : 0;

		for (int i=0; i<numFaces; i++) {
			for (int j=0; j<3; j++) {
				int k = i*3+j;
				pFace[i].t[j] = k;
				if (i<maxFaceData) {
					float fdValue = pFaceData->data[i];
					VertColor val;
					val.x = r*fdValue;
					if (val.x < 0) val.x = 0.0f;
					if (val.x > 1) val.x = 1.0f;
					val.y = g*fdValue;
					if (val.y < 0) val.y = 0.0f;
					if (val.y > 1) val.y = 1.0f;
					val.z = b*fdValue;
					if (val.z < 0) val.z = 0.0f;
					if (val.z > 1) val.z = 1.0f;
					pColor[k] = val;
				} else pColor[k] = VertColor(0,0,0);
			}
		}
	}

	if (pMNMesh) {
		if ((channel == 0) && (pMNMesh->numm == 0)) pMNMesh->SetMapNum (1);
		pMNMesh->M(-channel)->ClearFlag (MN_DEAD);
		pMNMesh->M(-channel)->setNumFaces (numFaces);

		// Precount the number of map vertices we need:
		int numColors = 0;
		for (int i=0; i<numFaces; i++) {
			if (pMNMesh->f[i].GetFlag (MN_DEAD)) continue;
			numColors += pMNMesh->f[i].deg;
		}
		pMNMesh->M(-channel)->setNumVerts (numColors);

		MNMapFace *pFace = pMNMesh->M(-channel)->f;
		VertColor *pColor = pMNMesh->M(-channel)->v;

		int maxFaceData = pFaceData ? pFaceData->Count() : 0;

		for (int i=0, k = 0; i<numFaces; i++) {
			if (pMNMesh->f[i].GetFlag (MN_DEAD)) continue;
			pFace[i].SetSize (pMNMesh->f[i].deg);
			for (int j=0; j<pMNMesh->f[i].deg; j++) {
				pFace[i].tv[j] = k;
				if (i<maxFaceData) {
					float fdValue = pFaceData->data[i];
					VertColor val;
					val.x = r*fdValue;
					if (val.x < 0) val.x = 0.0f;
					if (val.x > 1) val.x = 1.0f;
					val.y = g*fdValue;
					if (val.y < 0) val.y = 0.0f;
					if (val.y > 1) val.y = 1.0f;
					val.z = b*fdValue;
					if (val.z < 0) val.z = 0.0f;
					if (val.z > 1) val.z = 1.0f;
					pColor[k] = val;
				} else pColor[k] = VertColor(0,0,0);
				k++;
			}
		}
	}

	os->obj->SetChannelValidity (VERT_COLOR_CHAN_NUM, ourValidity);
}