void bhkProxyObject::CreateMesh() { if (Interface *gi = this->mIP) { if (const Mesh* pMesh = &this->proxyMesh) { if (TriObject *triObject = CreateNewTriObject()) { MNMesh mnmesh(*pMesh); Mesh& mesh = triObject->GetMesh(); mnmesh.OutToTri(mesh); INode *node = gi->CreateObjectNode(triObject); // Wireframe Red color StdMat2 *collMat = NewDefaultStdMat(); collMat->SetDiffuse(Color(1.0f, 0.0f, 0.0f), 0); collMat->SetWire(TRUE); collMat->SetFaceted(TRUE); gi->GetMaterialLibrary().Add(collMat); node->SetMtl(collMat); node->SetPrimaryVisibility(FALSE); node->SetSecondaryVisibility(FALSE); node->BoneAsLine(TRUE); node->SetRenderable(FALSE); node->SetWireColor( RGB(255,0,0) ); gi->SelectNode(node); } } } }
INode* plDistribComponent_old::IMakeOne(plDistribInstTab& nodes) { if( !nodes.Count() ) return nil; int iStartNode = 0; NameMaker *nn = GetCOREInterface()->NewNameMaker(); while( iStartNode < nodes.Count() ) { TriObject* triObj = CreateNewTriObject(); Mesh* outMesh = &triObj->mesh; *outMesh = *nodes[iStartNode].fMesh; INode *outNode = GetCOREInterface()->CreateObjectNode(triObj); Matrix3 l2w = nodes[0].fObjectTM; Matrix3 w2l = Inverse(l2w); MeshDelta meshDelta(*outMesh); int i; for( i = iStartNode; i < nodes.Count(); i++ ) { Mesh* nextMesh = nodes[i].fMesh; Matrix3 relativeTransform = nodes[i].fObjectTM * w2l; meshDelta.AttachMesh(*outMesh, *nextMesh, relativeTransform, 0); meshDelta.Apply(*outMesh); const int kFaceCutoff = 1000; if( outMesh->getNumFaces() > kFaceCutoff ) break; } iStartNode = i; outNode->SetNodeTM(TimeValue(0), l2w); outNode->CopyProperties(nodes[0].fNode); outNode->SetMtl(nodes[0].fNode->GetMtl()); outNode->SetObjOffsetPos(Point3(0,0,0)); Quat identQuat; identQuat.Identity(); outNode->SetObjOffsetRot(identQuat); outNode->SetObjOffsetScale(ScaleValue(Point3(1.f, 1.f, 1.f))); TSTR outName(TSTR("Preview")); nn->MakeUniqueName(outName); outNode->SetName(outName); fCompPB->Append(kReplicants, 1, &outNode); } return nil; }
Object* SimpleObject::ConvertToType(TimeValue t, Class_ID obtype) { if (obtype==defObjectClassID||obtype==triObjectClassID||obtype==mapObjectClassID) { TriObject *triob; UpdateMesh(t); triob = CreateNewTriObject(); triob->GetMesh() = mesh; triob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t)); triob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t)); return triob; } #ifndef NO_PATCHES if (obtype == patchObjectClassID) { UpdateMesh(t); PatchObject *patchob = new PatchObject(); patchob->patch = mesh; // Handy Mesh->PatchMesh conversion patchob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t)); patchob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t)); return patchob; } #endif if (Object::CanConvertToType (obtype)) { UpdateMesh (t); return Object::ConvertToType(t,obtype); } if (CanConvertTriObject(obtype)) { UpdateMesh (t); TriObject *triob = CreateNewTriObject (); triob->GetMesh() = mesh; triob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t)); triob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t)); Object *ob = triob->ConvertToType (t, obtype); if (ob != triob) triob->DeleteThis (); // (ob should never = tob.) return ob; } return NULL; }
Object* TriPatchObject::ConvertToType(TimeValue t, Class_ID obtype) { if(obtype == patchObjectClassID || obtype == defObjectClassID || obtype == mapObjectClassID) { PatchObject *ob; UpdatePatchMesh(t); ob = new PatchObject(); ob->patch = patch; ob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t)); ob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t)); return ob; } if(obtype == triObjectClassID) { TriObject *ob = CreateNewTriObject(); PrepareMesh(t); ob->GetMesh() = patch.GetMesh(); ob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t)); ob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t)); return ob; } #ifndef NO_NURBS if (obtype==EDITABLE_SURF_CLASS_ID) { PatchObject *pob; UpdatePatchMesh(t); pob = new PatchObject(); pob->patch = patch; Object *ob = BuildEMObjectFromPatchObject(pob); delete pob; ob->SetChannelValidity(TOPO_CHAN_NUM, ObjectValidity(t)); ob->SetChannelValidity(GEOM_CHAN_NUM, ObjectValidity(t)); return ob; } #endif if (Object::CanConvertToType (obtype)) return Object::ConvertToType (t, obtype); if (CanConvertPatchObject (obtype)) { PatchObject *ob; UpdatePatchMesh(t); ob = new PatchObject(); ob->patch = patch; ob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t)); ob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t)); Object *ret = ob->ConvertToType (t, obtype); ob->DeleteThis (); return ret; } return NULL; }
Object *TriObject::MakeShallowCopy(ChannelMask channels) { TriObject* newob = CreateNewTriObject(); #ifdef TRIPIPE_DEBUG DebugPrint ("TriObject(%08x)::MakeShallowCopy (%08x): %08x\n", this, channels, newob); #endif newob->ShallowCopy(this,channels); /* Redundant code NS:03-15-00 newob->mesh.ShallowCopy(&mesh,channels); newob->CopyValidity(this,channels); newob->mDispApprox = mDispApprox; newob->mSubDivideDisplacement = mSubDivideDisplacement; newob->mSplitMesh = mSplitMesh; newob->mDisableDisplacement = mDisableDisplacement; */ return newob; }
Object* bhkProxyObject::ConvertToType(TimeValue t, Class_ID obtype) { if (obtype == triObjectClassID) { int bvType = 0; pblock2->GetValue(PB_BOUND_TYPE, 0, bvType, FOREVER, 0); if (bvType != 0) { TriObject *ob = CreateNewTriObject(); #if VERSION_3DSMAX >= ((5000<<16)+(15<<8)+0) // Version 5+ ob->GetMesh().CopyBasics(proxyMesh); #else ob->GetMesh() = proxyMesh; #endif ob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t)); ob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t)); return ob; } } return 0; }
int OBJImport::DoImport(const TCHAR *filename,ImpInterface *i,Interface *gi, BOOL suppressPrompts) { TriObject *object = CreateNewTriObject(); if(!object) return 0; if(objFileRead(filename, &object->GetMesh())) { ImpNode *node = i->CreateNode(); if(!node) { delete object; return 0; } Matrix3 tm; tm.IdentityMatrix(); node->Reference(object); node->SetTransform(0,tm); i->AddNodeToScene(node); node->SetName(GetString(IDS_TH_WAVE_OBJ_NAME)); i->RedrawViews(); return 1; } return 0; }
Object* SimpleObject::ConvertToType(TimeValue t, Class_ID obtype) { if (obtype==defObjectClassID||obtype==triObjectClassID||obtype==mapObjectClassID) { TriObject *triob; UpdateMesh(t); triob = CreateNewTriObject(); triob->GetMesh() = mesh; triob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t)); triob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t)); return triob; } else if (obtype == patchObjectClassID) { UpdateMesh(t); PatchObject *patchob = new PatchObject(); patchob->patch = mesh; // Handy Mesh->PatchMesh conversion patchob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t)); patchob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t)); return patchob; } return Object::ConvertToType(t,obtype); }
int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, BOOL suppressPrompts) { IfcGeom::IteratorSettings settings; settings.use_world_coords() = false; settings.weld_vertices() = true; settings.sew_shells() = true; #ifdef _UNICODE int fn_buffer_size = WideCharToMultiByte(CP_UTF8, 0, name, -1, 0, 0, 0, 0); char* fn_mb = new char[fn_buffer_size]; WideCharToMultiByte(CP_UTF8, 0, name, -1, fn_mb, fn_buffer_size, 0, 0); #else const char* fn_mb = name; #endif IfcGeom::Iterator<float> iterator(settings, fn_mb); if (!iterator.initialize()) return false; itfc->ProgressStart(_T("Importing file..."), TRUE, fn, NULL); MtlBaseLib* mats = itfc->GetSceneMtls(); int slot = mats->Count(); std::map<std::vector<std::string>, Mtl*> material_cache; do{ const IfcGeom::TriangulationElement<float>* o = static_cast<const IfcGeom::TriangulationElement<float>*>(iterator.get()); TSTR o_type = S(o->type()); TSTR o_guid = S(o->guid()); Mtl *m = ComposeMultiMaterial(material_cache, mats, itfc, slot, o->geometry().materials(), o->type(), o->geometry().material_ids()); TriObject* tri = CreateNewTriObject(); const int numVerts = o->geometry().verts().size()/3; tri->mesh.setNumVerts(numVerts); for( int i = 0; i < numVerts; i ++ ) { tri->mesh.setVert(i,o->geometry().verts()[3*i+0],o->geometry().verts()[3*i+1],o->geometry().verts()[3*i+2]); } const int numFaces = o->geometry().faces().size()/3; tri->mesh.setNumFaces(numFaces); bool needs_default = std::find(o->geometry().material_ids().begin(), o->geometry().material_ids().end(), -1) != o->geometry().material_ids().end(); typedef std::pair<int, int> edge_t; std::set<edge_t> face_boundaries; for(std::vector<int>::const_iterator it = o->geometry().edges().begin(); it != o->geometry().edges().end();) { const int v1 = *it++; const int v2 = *it++; const edge_t e((std::min)(v1, v2), (std::max)(v1, v2)); face_boundaries.insert(e); } for( int i = 0; i < numFaces; i ++ ) { const int v1 = o->geometry().faces()[3*i+0]; const int v2 = o->geometry().faces()[3*i+1]; const int v3 = o->geometry().faces()[3*i+2]; const edge_t e1((std::min)(v1, v2), (std::max)(v1, v2)); const edge_t e2((std::min)(v2, v3), (std::max)(v2, v3)); const edge_t e3((std::min)(v3, v1), (std::max)(v3, v1)); const bool b1 = face_boundaries.find(e1) != face_boundaries.end(); const bool b2 = face_boundaries.find(e2) != face_boundaries.end(); const bool b3 = face_boundaries.find(e3) != face_boundaries.end(); tri->mesh.faces[i].setVerts(v1, v2, v3); tri->mesh.faces[i].setEdgeVisFlags(b1, b2, b3); MtlID mtlid = o->geometry().material_ids()[i]; if (needs_default) { mtlid ++; } tri->mesh.faces[i].setMatID(mtlid); } tri->mesh.buildNormals(); // Either use this or undefine the FACESETS_AS_COMPOUND option in IfcGeom.h to have // properly oriented normals. Using only the line below will result in a consistent // orientation of normals accross shells, but not always oriented towards the // outside. // tri->mesh.UnifyNormals(false); tri->mesh.BuildStripsAndEdges(); tri->mesh.InvalidateTopologyCache(); tri->mesh.InvalidateGeomCache(); ImpNode* node = impitfc->CreateNode(); node->Reference(tri); node->SetName(o_guid); node->GetINode()->Hide(o->type() == "IfcOpeningElement" || o->type() == "IfcSpace"); if (m) { node->GetINode()->SetMtl(m); } const std::vector<float>& matrix_data = o->transformation().matrix().data(); node->SetTransform(0,Matrix3 ( Point3(matrix_data[0],matrix_data[1],matrix_data[2]),Point3(matrix_data[3],matrix_data[4],matrix_data[5]), Point3(matrix_data[6],matrix_data[7],matrix_data[8]),Point3(matrix_data[9],matrix_data[10],matrix_data[11]) )); impitfc->AddNodeToScene(node); itfc->ProgressUpdate(iterator.progress(), true, _T("")); } while (iterator.next()); itfc->ProgressEnd(); return true; }
ObjectHandle TriPatchObject::CreateTriObjRep(TimeValue t) { TriObject *tri = CreateNewTriObject(); PrepareMesh(t); // Turn it into a mesh tri->GetMesh() = patch.GetMesh(); // Place it into the TriObject return(ObjectHandle(tri)); }
void ExtrudeMod::ModifyObject(TimeValue t, ModContext &mc, ObjectState * os, INode *node) { //DebugPrint(_T("Extrude modifying object\n")); // Get our personal validity interval... Interval valid = GetValidity(t); // and intersect it with the channels we use as input (see ChannelsUsed) valid &= os->obj->ChannelValidity(t,TOPO_CHAN_NUM); valid &= os->obj->ChannelValidity(t,GEOM_CHAN_NUM); int output; pblock->GetValue(PB_OUTPUT, TimeValue(0), output, FOREVER); switch (output) { case NURBS_OUTPUT: #ifndef NO_NURBS { // Here is where all the fun stuff happens -- GenerateExtrudeSurface fills in the EM, // then we stuff the EditableSurface into the pipeline. ShapeObject *shape = (ShapeObject *)os->obj; float amount; BOOL texturing, genMatIds, useShapeIDs; pblock->GetValue(PB_MAPPING, TimeValue(0), texturing, FOREVER); pblock->GetValue(PB_GEN_MATIDS, TimeValue(0), genMatIds, FOREVER); pblock->GetValue(PB_USE_SHAPEIDS, TimeValue(0), useShapeIDs, FOREVER); int levels,capStart,capEnd,capType; pblock->GetValue(PB_SEGS,t,levels,FOREVER); if (levels<1) levels = 1; pblock->GetValue(PB_CAPSTART,t,capStart,FOREVER); pblock->GetValue(PB_CAPEND,t,capEnd,FOREVER); pblock->GetValue(PB_CAPTYPE,t,capType,FOREVER); pblock->GetValue(PB_AMOUNT,t,amount,FOREVER); LimitValue(amount, -1000000.0f, 1000000.0f); BOOL suspended = FALSE; if (theHold.Holding()) { theHold.Suspend(); suspended = TRUE; } Object *nobj = CreateNURBSExtrudeShape(ip, GetString(IDS_RB_EXTRUDE), t, shape, amount, capStart, capEnd, capType, texturing, genMatIds, useShapeIDs); if (suspended) { theHold.Resume(); } // We only set geom validity because we preserve animation on clone // and copying other cahnnels causes problems -- SCM 9/2/97 nobj->SetChannelValidity(GEOM_CHAN_NUM, valid); os->obj = nobj; break;} #endif #ifndef NO_PATCHES case PATCH_OUTPUT: { // Here is where all the fun stuff happens -- BuildPatchFromShape fills in the PatchObject's patch mesh, // then we stuff the PatchObject into the pipeline. PatchObject *pat = new PatchObject; BuildPatchFromShape(t, mc, os, pat->patch); pat->SetChannelValidity(TOPO_CHAN_NUM, valid); pat->SetChannelValidity(GEOM_CHAN_NUM, valid); pat->SetChannelValidity(TEXMAP_CHAN_NUM, valid); pat->SetChannelValidity(MTL_CHAN_NUM, valid); pat->SetChannelValidity(SELECT_CHAN_NUM, valid); pat->SetChannelValidity(SUBSEL_TYPE_CHAN_NUM, valid); pat->SetChannelValidity(DISP_ATTRIB_CHAN_NUM, valid); os->obj = pat; break;} #endif // NO_PATCHES case MESH_OUTPUT: { // Here is where all the fun stuff happens -- BuildMeshFromShape fills in the TriObject's mesh, // then we stuff the TriObj into the pipeline. TriObject *tri = CreateNewTriObject(); BuildMeshFromShape(t, mc, os, tri->GetMesh()); tri->SetChannelValidity(TOPO_CHAN_NUM, valid); tri->SetChannelValidity(GEOM_CHAN_NUM, valid); tri->SetChannelValidity(TEXMAP_CHAN_NUM, valid); tri->SetChannelValidity(MTL_CHAN_NUM, valid); tri->SetChannelValidity(SELECT_CHAN_NUM, valid); tri->SetChannelValidity(SUBSEL_TYPE_CHAN_NUM, valid); tri->SetChannelValidity(DISP_ATTRIB_CHAN_NUM, valid); os->obj = tri; break; } #ifdef XXDESIGN_VER case AMSOLID_OUTPUT: { //Create an extrusion solid using Facet Modeler Object* solid = (Object*)CreateInstance(GEOMOBJECT_CLASS_ID, GENERIC_AMSOLID_CLASS_ID); assert(solid); if(solid) { IGeomImp* cacheptr = (IGeomImp*)(solid->GetInterface(I_GEOMIMP)); assert(cacheptr); if(cacheptr) { bool res = BuildAMSolidFromShape(t, mc, os, cacheptr); solid->ReleaseInterface(I_GEOMIMP, cacheptr); if(!res) { valid.SetInstant(t); // assert(!cacheptr->isNull()); } for(int i=0; i<NUM_OBJ_CHANS;i++) solid->SetChannelValidity(i, valid); os->obj = solid; } } break; } #endif } os->obj->UnlockObject(); }
bool PlasmaImport::IImportObject(plSceneObject *obj, ImpInterface *imp) { if (!obj->getDrawInterface().isLoaded()) return false; plDrawInterface* draw = plDrawInterface::Convert(obj->getDrawInterface()->getObj()); plCoordinateInterface* coord = NULL; if (obj->getCoordInterface().Exists()) coord = plCoordinateInterface::Convert(obj->getCoordInterface()->getObj()); TriObject *maxObj = CreateNewTriObject(); Mesh *msh = &maxObj->GetMesh(); std::vector<Point3> vertexList; std::vector<int> indexList; if (!maxObj) return false; // read the object from PRP for (size_t i = 0; i < draw->getNumDrawables(); i++) { if (draw->getDrawableKey(i) == -1) continue; plDrawableSpans* span = plDrawableSpans::Convert(draw->getDrawable(i)->getObj()); plDISpanIndex di = span->getDIIndex(draw->getDrawableKey(i)); if ((di.fFlags & plDISpanIndex::kMatrixOnly) != 0) continue; for (size_t idx = 0; idx < di.fIndices.size(); idx++) { plIcicle* ice = (plIcicle*)span->getSpan(di.fIndices[idx]); std::vector<plGBufferVertex> verts = span->getVerts(ice); std::vector<unsigned short> indices = span->getIndices(ice); for (size_t j = 0; j < verts.size(); j++) { hsVector3 pos; if (coord != NULL) pos = coord->getLocalToWorld().multPoint(verts[j].fPos) * 10.0f; else pos = ice->getLocalToWorld().multPoint(verts[j].fPos) * 10.0f; vertexList.push_back(Point3(pos.X, pos.Y, pos.Z)); } indexList.insert(indexList.end(), indices.begin(), indices.end()); } } //create the Mesh msh->setNumVerts(vertexList.size()); msh->setNumFaces(indexList.size()/3); for (size_t i = 0; i < vertexList.size(); i++) msh->setVert(i, vertexList[i]); for (size_t i = 0; i < indexList.size()/3; i++) { int v1, v2, v3; v1 = indexList[3*i]; v2 = indexList[3*i+1]; v3 = indexList[3*i+2]; msh->faces[i].setVerts(v1, v2, v3); msh->faces[i].setEdgeVisFlags(1,1,1); //we asume we have Triangles obnly } msh->buildNormals(); msh->buildBoundingBox(); msh->InvalidateEdgeList(); //Add Object To Scene ImpNode *node = imp->CreateNode(); Matrix3 tm; tm.IdentityMatrix(); node->Reference(maxObj); node->SetTransform(0,tm); imp->AddNodeToScene(node); node->SetName(obj->getKey()->getName()); imp->RedrawViews(); return true; }
BOOL objFileRead(const TCHAR *filename, ImpInterface *imp){ FILE *fp; int i; tLump *idxtable; if((fp = fopen(filename, "rb")) == NULL) return 0; fseek(fp, 0, SEEK_END); int fileSize = ftell(fp); fseek(fp, 0, SEEK_SET); char *data = new char[fileSize]; fread(data, fileSize, 1, fp); tHeader *header = (tHeader *)data; if(*(int*)header->strID != CMAPHEADER_ID) return 0; if(header->version != CMAPHEADER_VERSION) return 0; idxtable = (tLump *)header + 1; tVertex *Verts = (tVertex *)(data + idxtable[kVertices].offset); int NumVerts = idxtable[kVertices].length / sizeof(tVertex); tFace *faces = (tFace *)(data + idxtable[kLeafFaces].offset); int NumFaces = idxtable[kLeafFaces].length / sizeof(tFace); int *elems = (int *)(data + idxtable[kElements].offset); int NumElems = idxtable[kElements].length / sizeof(int); tArea *mAreas = (tArea *)(data + idxtable[kAreas].offset); int NumAreas = idxtable[kAreas].length / sizeof(tArea); Point3 p; TriObject *object = CreateNewTriObject(); if(!object) return 0; Mesh *msh = &object->GetMesh(); msh->setNumVerts(NumVerts); for(i = 0 ; i < NumVerts ; i++){ msh->setVert(i, Verts[i].point[0], -Verts[i].point[2], Verts[i].point[1]); p.Set(Verts[i].norm[0], -Verts[i].norm[2], Verts[i].norm[1]); msh->setNormal(i, p); } int face = 0; for(int k = 1 ; k < NumAreas ; k++){ for(i = mAreas[k].startFace ; i < mAreas[k].startFace + mAreas[k].numOfFaces ; i++){ for(int j = faces[i].startElement ; j < faces[i].startElement + faces[i].elementsSize ; j++){ int k = j * 3; if(elems[k] < 0){ elems[k] = 0; elems[k+1] = 1; elems[k+2] = 2; faces[i].vertexIndex = 0; } msh->setNumFaces(face + 1, TRUE); msh->faces[face].setVerts(faces[i].vertexIndex + elems[k + 0], faces[i].vertexIndex + elems[k + 1], faces[i].vertexIndex + elems[k + 2]); msh->faces[face].setEdgeVisFlags(1, 1, 1); face++; } } } delete [] data; fclose(fp); msh->buildNormals(); msh->buildBoundingBox(); msh->InvalidateEdgeList(); ImpNode *node = imp->CreateNode(); if(!node) { delete object; return 0; } Matrix3 tm; tm.IdentityMatrix(); node->Reference(object); node->SetTransform(0,tm); imp->AddNodeToScene(node); node->SetName(_T("Sylphis map")); return TRUE; }