globalContainer::globalContainer() { math = new lbmathhelper(); //create root floorsTree = new LObject; chosenField = NULL; chosenField2 = NULL; floorsAmount = 0; for(int cnt = 0; cnt < floorsAmount; cnt++) { // addFloor(cnt*10); /* LBFloor * help = new LBFloor(cnt*10); ((LObject*)help) -> connectTo(floorsTree);*/ } /* actualFloor = ((LBFloor*)(floorsTree -> child)); actualFloor -> height = 0.0f;*/ appState = new STATE; actualFloor = NULL; cameraKid = new LObject(); cameraKid -> position = LVector(500.0f, 0.0f, 500.0f); cameraKid -> direction = -45.0f; *appState = none; floorsComboBox = new QComboBox; stuffArea = new QScrollArea; stuffArea->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); stuffArea->setFixedSize(100,100); stairsBottom = NULL; stairsTop = NULL; stairsFieldBottomEdge = 0; stairsFieldTopEdge = 0; isBottomFieldSet = false; stairsTree = new LBStairs(0, 0, 0); ////////// IDAmount = 1000000; //IDPool - false means that particular ID is not available IDPool = new bool[IDAmount]; //reset IDPool (ID 0 is reserved for all objects - it means, //that object has no ID) IDPool[0] = false; for(int cnt = 1; cnt < IDAmount; cnt++) { IDPool[cnt] = true; } ////////// }
void makePlane(GeometryBatch &batch, float width, int divisions, bool normals, bool uvs, const LColor *color) { float dx = width / divisions, dy = 0, dz = -width / divisions; float x0 = -width / 2.0f, y0 = 0.0f, z0 = width / 2.0f; LPoint p0(x0, y0, z0); LVector dp(dx, dy, dz); batch.init(GL_TRIANGLE_STRIP, "plane"); for (int strip = 0; strip < divisions; ++strip) { LVector index = LVector(0,0,strip); for (int x = 0; x < divisions+1; ++x) { index.setX(x); LVector index1 = index + LVector(0,0,1); LPoint pb = p0 + index * dp; LPoint pt = p0 + index1 * dp; if (x == 0 && strip > 0 && strip < divisions) { batch.ps.push_back(pt); } batch.ps.push_back(pt); batch.ps.push_back(pb); if (x == divisions && strip < divisions-1) { batch.ps.push_back(pb); } } } if (normals) { batch.ns.assign(batch.ps.size(), LNormal(0,1,0)); } if (uvs) { std::cout << "Plane UV not implemented\n"; } if (color) { batch.cs.assign(batch.ps.size(), *color); } // cout << "plane vertices\n"; // ostream_iterator<LPoint> osi(cout, "\n"); // copy(batch.ps.begin(), batch.ps.end(), osi); }
LVector LTransform::operator*(const LVector rhs) const { if (_orderIn != rhs.getOrder()) FormatAndThrow<>() << "Order mismatch between LTransform [" << _orderIn << "] and LVector [" << rhs.getOrder() << "]"; boost::shared_ptr<tmv::Vector<double> > out(new tmv::Vector<double>(sizeOut())); *out = (*_m) * rhs.rVector(); return LVector(_orderOut, out); }
void LBStairs::selfDraw() { triangle vBottom[2]; triangle vTop[2]; vBottom[0].point[0] = cornersBottom[0].x; vBottom[0].point[1] = cornersBottom[0].y; vBottom[0].point[2] = cornersBottom[0].z; vBottom[1].point[0] = cornersBottom[1].x; vBottom[1].point[1] = cornersBottom[1].y; vBottom[1].point[2] = cornersBottom[1].z; vTop[0].point[0] = cornersTop[0].x; vTop[0].point[1] = cornersTop[0].y; vTop[0].point[2] = cornersTop[0].z; vTop[1].point[0] = cornersTop[1].x; vTop[1].point[1] = cornersTop[1].y; vTop[1].point[2] = cornersTop[1].z; //these values should be calculated in constructor //to not recalculate same values every time float stairsHeight = cornersTop[0].y - cornersBottom[0].y; // assumed every step's height (it will be modified to fit stairs height) //1 pix = 5cm float desiredHeight = 4.0f; float stairsWidth = LVector(cornersBottom[0].x - cornersTop[0].x, 0.0f, cornersBottom[0].z - cornersTop[0].z).Length(); lbmathhelper math; // float stairsWidth = math.pointLineDistance(vBottom[0].point[2], vBottom[0].point[0], vTop[0].point[2], vTop[0].point[0], vTop[1].point[2], vTop[1].point[0]); int stepsNumber = stairsHeight / desiredHeight; float stepHeight = stairsHeight / stepsNumber; float stepWidth = stairsWidth / stepsNumber; //variables keeping current step's coordinates: //vertical part of step triangle verticalDraw[4]; //horizontal part of step triangle horizontalDraw[4]; /* 3 ------ 2 3 ------ 2 | | / / 0 ------ 1 0 ------ 1 vertical part horizontal part */ ///////////////// verticalDraw[0] = vBottom[0]; verticalDraw[1] = vBottom[1]; verticalDraw[2] = verticalDraw[1]; verticalDraw[2].point[1] += stepHeight; verticalDraw[3] = verticalDraw[0]; verticalDraw[3].point[1] += stepHeight; ///////////////// horizontalDraw[0] = verticalDraw[3]; horizontalDraw[1] = verticalDraw[2]; horizontalDraw[2] = horizontalDraw[1]; horizontalDraw[2].point[0] += horizontalVector.x * stepWidth; horizontalDraw[2].point[2] += horizontalVector.z * stepWidth; horizontalDraw[3] = horizontalDraw[0]; horizontalDraw[3].point[0] += horizontalVector.x * stepWidth; horizontalDraw[3].point[2] += horizontalVector.z * stepWidth; ///////////////// //printf("%f, %f\n", horizontalVector.x, horizontalVector.z); glShadeModel(GL_SMOOTH); /* glColor4f(0.0,0.0,0.0,1.0); glPushMatrix(); glBegin(GL_LINE); glVertex3fv(vBottom[0].point); glVertex3fv(vTop[0].point); glVertex3fv(vBottom[1].point); glVertex3fv(vTop[1].point); glEnd(); */ for(int stepCnt = 0; stepCnt < stepsNumber; stepCnt++) { glBegin(GL_LINE_LOOP); { //draw vertical part of step glVertex3fv(verticalDraw[0].point); glVertex3fv(verticalDraw[1].point); glVertex3fv(verticalDraw[2].point); glVertex3fv(verticalDraw[3].point); } glEnd(); glBegin(GL_LINE_LOOP); { //draw horizontal part of step glVertex3fv(horizontalDraw[0].point); glVertex3fv(horizontalDraw[1].point); glVertex3fv(horizontalDraw[2].point); glVertex3fv(horizontalDraw[3].point); } glEnd(); //set parts of next step for(int setCnt = 0; setCnt < 4; setCnt++) { //update every vertice's coordinates verticalDraw[setCnt].point[0] += horizontalVector.x * stepWidth; horizontalDraw[setCnt].point[0] += horizontalVector.x * stepWidth; verticalDraw[setCnt].point[1] += stepHeight; horizontalDraw[setCnt].point[1] += stepHeight; verticalDraw[setCnt].point[2] += horizontalVector.z * stepWidth; horizontalDraw[setCnt].point[2] += horizontalVector.z * stepWidth; } } glPopMatrix(); }
Bool ApplinkExporter::Execute(BaseDocument* document, BaseContainer* bc) { matDefault = BaseMaterial::Alloc(Mmaterial); if(!matDefault) return false; Filename fileObjPath; fileObjPath.SetDirectory(bc->GetString(IDC_TMP_FOLDER)); fileObjPath.SetFile(document->GetDocumentName()); fileObjPath.SetSuffix("obj"); Filename fileObjOutPath; fileObjOutPath.SetDirectory(bc->GetString(IDC_TMP_FOLDER)); fileObjOutPath.SetFile("output.obj"); Filename fileImport; fileImport.SetDirectory(bc->GetString(IDC_EXCH_FOLDER)); fileImport.SetFile("import.txt"); GePrint(fileObjPath.GetString()); GePrint(fileObjOutPath.GetString()); GePrint(fileImport.GetString()); const Matrix tM(LVector(0.0f, 0.0f, 0.0f), LVector(1.0f, 0.0f, 0.0f), LVector(0.0f, 1.0f, 0.0f), LVector(0.0f, 0.0f, -1.0f)); //BaseDocument* doc = document->Polygonize(); AutoAlloc<AtomArray> oSel; document->GetActiveObjects(oSel, GETACTIVEOBJECTFLAGS_0); if(oSel->GetCount() > 0) { //Write import.txt// AutoAlloc<BaseFile> basefileImport; if (!basefileImport->Open(fileImport, FILEOPEN_WRITE, FILEDIALOG_NONE, GeGetByteOrder())) return FALSE; this->WriteString(fileObjPath.GetString() + "\n", basefileImport); this->WriteString(fileObjOutPath.GetString() + "\n", basefileImport); this->WriteString(mapType(bc->GetLong(IDC_COMBO_MAP_TYPE)) + "\n", basefileImport); Bool bSkipImp = bc->GetBool(IDC_CHK_SKIP_IMP_DIALOG); if(bSkipImp) { this->WriteString("[SkipImport]\n", basefileImport); } Bool bSkipExp = bc->GetBool(IDC_CHK_SKIP_EXP_DIALOG); if(bSkipExp) { this->WriteString("[SkipExport]\n", basefileImport); } GePrint(mapType(bc->GetLong(IDC_COMBO_MAP_TYPE))); basefileImport->Close(); GePrint("File " + fileImport.GetString() + " write success!"); //Write file.obj// AutoAlloc<BaseFile> objfile; //if (!objfile) return FALSE; if (!objfile->Open(fileObjPath, FILEOPEN_WRITE, FILEDIALOG_NONE, GeGetByteOrder())) return FALSE; String str; str = "#Wavefront OBJ Export for 3D-Coat\n"; this->WriteString(str, objfile); DateTime t; GetDateTimeNow(t); str = "#File created: " + FormatTime("%d.%m.%Y %H:%M:%S", t) + "\n"; this->WriteString(str, objfile); str = "#Cinema4D Version: " + LongToString(GetC4DVersion()) + "\n"; this->WriteString(str, objfile); this->WriteEndLine(objfile); Bool expMat = bc->GetBool(IDC_CHK_EXP_MAT); vpcnt = vtcnt = 0; for(int i = 0; i < oSel->GetCount(); i++) { StatusSetSpin(); PolygonObject* ob = (PolygonObject*) oSel->GetIndex(i); if (ob->GetType() == Opolygon) { StatusSetText("Export object " + ob->GetName()); ExportObject mObject; GePrint("Name " + ob->GetName()); //GePrint("Type " + LongToString(ob->GetType())); if(expMat) { mObject.pmatidxArray.ReSize(ob->GetPolygonCount()); mObject.tempMats.ReSize(1); mObject.pmatidxArray.Fill(0); Bool haveMats = false; ////////////////////////////////////////// for(BaseTag* tag = ob->GetFirstTag(); tag != NULL; tag = tag->GetNext()) { LONG typ = tag->GetType(); if(typ == Ttexture) { if (!getParameterLink(*tag, TEXTURETAG_MATERIAL, Mbase)) continue; haveMats = true; TextureTag* txttag = (TextureTag*)tag; BaseMaterial* material = txttag->GetMaterial(); if(material == NULL) { GePrint("Material not found on " + ob->GetName() + "object."); return false; } //GePrint("Mat Name: " + material->GetName()); String restrict = getParameterString(*tag, TEXTURETAG_RESTRICTION); if (restrict.Content()) { mObject.tempMats.Push(material); //GePrint("Selection: " + restrict); for(BaseTag* seltag = ob->GetFirstTag(); seltag != NULL; seltag = seltag->GetNext()) { LONG seltyp = seltag->GetType(); if(seltyp == Tpolygonselection && seltag->GetName() == restrict) { SelectionTag* selecttag = (SelectionTag*)seltag; BaseSelect* sel = selecttag->GetBaseSelect(); //GePrint("sel data count: " + LongToString(sel->GetCount())); LONG seg = 0, a, b, p; while (sel->GetRange(seg++, &a, &b)) { for (p = a; p <= b; ++p) { //GePrint("seltpolygon: " + LongToString(p)); mObject.pmatidxArray[p] = mObject.tempMats.GetCount()-1; } } } } } else { mObject.tempMats[0] = material; mObject.pmatidxArray.Fill(0); } } } if(!mObject.tempMats[0]) { matDefault->SetName("Default"); BaseChannel* color = matDefault->GetChannel(CHANNEL_COLOR); if (!color) return false; // return some error BaseContainer cdata = color->GetData(); cdata.SetVector(BASECHANNEL_COLOR_EX, Vector(1.0f, 1.0f, 1.0f)); //document->InsertMaterial(matDefault, NULL, FALSE); //matDefault->Update(TRUE, TRUE); //matDefault->Message(MSG_UPDATE); mObject.tempMats[0] = matDefault; //GePrint("Global material not found on object " + ob->GetName() + "."); //return false; } if(haveMats) { //GePrint("mObject.tempMats.GetCount(): " + LongToString(mObject.tempMats.GetCount())); for(LONG m = 0; m < mObject.tempMats.GetCount(); m++) { Bool inMats = false; //GePrint("materialArray.GetCount(): " + LongToString(materialArray.GetCount())); for(LONG n = 0; n < materialArray.GetCount(); n++) { if(mObject.tempMats[m]->GetName() == materialArray[n]->GetName()) { inMats = true; break; } } if(!inMats) { materialArray.Push(mObject.tempMats[m]); } } } //String str1; //for (LONG p = 0; p < ob->GetPolygonCount(); p++) //{ // str1 += LongToString(mObject.pmatidxArray[p]) + ","; //} //GePrint(str1); } ///////////////////////////////////////////////// const Vector* vadr = ob->GetPointR(); const CPolygon* padr = ob->GetPolygonR(); LONG vcnt = ob->GetPointCount(); LONG pcnt = ob->GetPolygonCount(); mObject.Fpvnb.ReSize(pcnt);// poly counts for(LONG p = 0; p < pcnt; p++) { if(padr[p].c != padr[p].d) { mObject.Fpvnb[p] = 4; } else { mObject.Fpvnb[p] = 3; } } mObject.pVertexCount = PVertexLength(mObject); //Vertex positions mObject.Vp.ReSize(vcnt); Matrix mg = tM * ob->GetMgn(); for (LONG v = 0; v < vcnt; v++) { mObject.Vp[v] = vadr[v] * mg; //GePrint("Point[" + LongToString(i) + "] " + LongToString(padr[i].x) + ", " + LongToString(padr[i].y) + ", " + LongToString(padr[i].z)); //str = "v " + LongToString(vadr[p].x) + " " + LongToString(vadr[p].y) + " " + LongToString(vadr[p].z) + "\n"; //this->WriteString(str, objfile); } mObject.Fv.ReSize(mObject.pVertexCount); LONG y=0; for (LONG p = 0; p < pcnt; p++) { if(mObject.Fpvnb[p] == 4) { mObject.Fv[y] = padr[p].d; mObject.Fv[y+1] = padr[p].c; mObject.Fv[y+2] = padr[p].b; mObject.Fv[y+3] = padr[p].a; } else { mObject.Fv[y] = padr[p].c; mObject.Fv[y+1] = padr[p].b; mObject.Fv[y+2] = padr[p].a; } y += mObject.Fpvnb[p]; } //String str1; //for (LONG p = 0; p < mObject.Fv.GetCount(); p++) //{ // str1 += LongToString(mObject.Fv[p]) + " "; //} //GePrint(str1); /////////////////////////////// ///////////vertex UV ////////////////////////////// if(bc->GetBool(IDC_CHK_EXP_UV)) { // Get first UV tag (if at least one) UVWTag* uvw_tag = (UVWTag*)ob->GetTag(Tuvw, 0); if(!uvw_tag) { GePrint("Object \"" + ob->GetName() + "\" has no UVW tag.\nUV coordinates can't be exported."); return FALSE; } else { mObject.Vt.ReSize(mObject.pVertexCount); mObject.Fvt.ReSize(mObject.pVertexCount); const UVWHandle dataptr = uvw_tag->GetDataAddressR(); UVWStruct res; for(LONG t=0, y=0; t < pcnt; t++) { //GePrint("y: " + LongToString(y)); UVWTag::Get(dataptr, t, res); if(mObject.Fpvnb[t] == 4) { mObject.Vt[y] = res.d; mObject.Vt[y + 1] = res.c; mObject.Vt[y + 2] = res.b; mObject.Vt[y + 3] = res.a; mObject.Fvt[y] = y; mObject.Fvt[y + 1] = y + 1; mObject.Fvt[y + 2] = y + 2; mObject.Fvt[y + 3] = y + 3; } else { mObject.Vt[y] = res.c; mObject.Vt[y + 1] = res.b; mObject.Vt[y + 2] = res.a; mObject.Fvt[y] = y; mObject.Fvt[y + 1] = y + 1; mObject.Fvt[y + 2] = y + 2; } y += mObject.Fpvnb[t]; } } //String str1; //for (LONG p = 0; p < mObject.Fvt.GetCount(); p++) //{ // str1 += LongToString(mObject.Fvt[p]) + " "; //} //GePrint(str1); } WriteExportFile(bc, ob, objfile, mObject, vcnt, pcnt); //GePrint("Fvt: " + LongToString(Fvt.GetCount())); vpcnt += mObject.Vp.GetCount(); if(bc->GetBool(IDC_CHK_EXP_UV)) vtcnt += mObject.Vt.GetCount(); } } objfile->Close(); if(expMat && materialArray.GetCount() > 0) WriteMatsFile(document, bc); } else { GePrint("No selected objects!"); } BaseMaterial::Free(matDefault); return TRUE; }