/* Returns Vec4f = normal & heigh at (x,z) */ Vec4f calcSineValue(float x, float z) { float mag; Vec4f v; float t = animationTime; /* Sum heights of both waves at (x,z) */ v.w = calcHeight(&sineWaveX, x, t) + calcHeight(&sineWaveZ, z, t); /* Normal for each sine wave */ Vec2f normX = calcNormal(&sineWaveX, x, t); Vec2f normZ = calcNormal(&sineWaveZ, z, t); /* Combining normals */ v.x = normX.x; v.y = 1.0f; v.z = normZ.x; /* Normalizing */ mag = sqrt((v.x*v.x) + (v.y*v.y) + (v.z*v.z)); v.x = v.x/mag; v.y = v.y/mag; v.z = v.z/mag; return v; }
void Utility::loadPlyfile(char *filename) { int headerEndFlag=0,vertexEndFlag=0; int temp,i=0,j=1; char str[500],tempStr1[20],tempStr2[20]; char c; FILE *plyReader; if ((plyReader = fopen(filename, "r")) == NULL) { printf("File not found !"); return; } // running down the comments. while (strstr(str, "comment")) { fgets(str, 100, plyReader); } while(!feof(plyReader)) { if(fgets(str,200,plyReader)) { if(headerEndFlag!=1) { // reading header. if(strstr(str,"element vert")) sscanf(str,"%s %s %d",tempStr1,tempStr2,&plyVertexCount); if(strstr(str,"element face")) sscanf(str,"%s %s %d",tempStr1,tempStr2,&plyfaceCount); if(strstr(str,"end_header")) headerEndFlag=1; normalise(); } else if(vertexEndFlag!=1){ if(i<plyVertexCount){ sscanf(str,"%f %f %f %f %f",&plyVertex[i][0],&plyVertex[i][1],&plyVertex[i][2],&plyVertex[i][3],&plyVertex[i][4]); i++; } else{ vertexEndFlag=1; sscanf(str,"%d %d %d %d ",&temp,&plyFace[0][0],&plyFace[0][1],&plyFace[0][2]); calcNormal(0,plyVertex[plyFace[0][0]],plyVertex[plyFace[0][1]],plyVertex[plyFace[0][2]]); } } else{ if(j<plyfaceCount){ sscanf(str,"%d %d %d %d ",&temp,&plyFace[j][0],&plyFace[j][1],&plyFace[j][2]); calcNormal(j,plyVertex[plyFace[j][0]],plyVertex[plyFace[j][1]],plyVertex[plyFace[j][2]]); j++; } } } } }
std::vector<CalcEntropy::ConfigDist> RayTracePluginUtils::intersectionsToConfig(std::vector<RayIntersection> const &rays, double depth_err, tf::Vector3 start, tf::Vector3 end) { std::vector<CalcEntropy::ConfigDist> distToConfig; for(int ray_index = 0; ray_index < rays.size(); ray_index ++){ for(int id=0; id < rays[ray_index].dist.size(); id++){ int n = 10; //For adding extra points to simulate error tf::Vector3 normal = calcNormal(start, end); double cosOffNormal = fabs(normal.dot((end-start).normalized())); // ROS_INFO("Along Normal: %f", cosOffNormal); cosOffNormal = std::max(cosOffNormal, 0.05); //Limit off angle to avoid overflow errors double dist_err = depth_err/cosOffNormal; for(double i=-1*n; i <=n; i++){ double err = depth_err * i/n; CalcEntropy::ConfigDist c; c.id = id; c.dist = rays[ray_index].dist[id]; distToConfig.push_back(c); } } } return distToConfig; }
Plane::Plane() { a = glm::vec3(0.2f, 0.9f, -0.4); b = glm::vec3(0.4f, 0.9f, -0.4); c = glm::vec3(0.2f, 0.9f, 0.2); calcNormal(); }
void Triangle::rotate(const Vector3d &axis, double angle) { A = A.rotate(angle, axis); B = B.rotate(angle, axis); C = C.rotate(angle, axis); calcNormal(); }
Triangle::Triangle() { p[0]=Point(1,0,0); p[1]=Point(0,1,0); p[2]=Point(0,0,1); calcNormal(); calcBB(); }
Triangle::Triangle(Point p1, Point p2, Point p3) { p[0]=p1; p[1]=p2; p[2]=p3; calcNormal(); calcBB(); }
Triangle::Triangle(const Triangle &t) { p[0]=t.p[0]; p[1]=t.p[1]; p[2]=t.p[2]; calcNormal(); calcBB(); }
Triangle3d::Triangle3d( Vector const & a, Vector const & b, Vector const & c ) : m_cornerA(a), m_cornerB(b), m_cornerC(c), m_normal() { calcNormal(); }
void Triangle::rotate(const Vector3d axis, double angle) { //Normal = triangles[i].Normal.rotate(angle, axis.x, axis.y, axis.z); A = A.rotate(angle, axis.x, axis.y, axis.z); B = B.rotate(angle, axis.x, axis.y, axis.z); C = C.rotate(angle, axis.x, axis.y, axis.z); calcNormal(); }
void MainWindow::save(QUrl url) { //if saving process was aborted if(!url.isValid()) return; QString path = url.toLocalFile(); //if no file suffix was chosen, automatically use the PNG format QFileInfo file(path); if(!file.baseName().isEmpty() && file.suffix().isEmpty()) path += ".png"; QString suffix = file.suffix(); //Qt can only read tga, saving is not supported if(suffix.toLower() == "tga") suffix = "png"; //append a suffix to the map names (result: path/original_normal.png) QString name_normal = file.absolutePath() + "/" + file.baseName() + "_normal." + suffix; QString name_specular = file.absolutePath() + "/" + file.baseName() + "_spec." + suffix; QString name_displace = file.absolutePath() + "/" + file.baseName() + "_displace." + suffix; bool successfullySaved = true; if(ui->checkBox_queue_generateNormal->isChecked()) { if(normalmap.isNull()) ui->statusBar->showMessage("calculating normalmap..."); calcNormal(); successfullySaved &= normalmap.save(name_normal); } if(ui->checkBox_queue_generateSpec->isChecked()) { if(specmap.isNull()) ui->statusBar->showMessage("calculating specularmap..."); calcSpec(); successfullySaved &= specmap.save(name_specular); } if(ui->checkBox_queue_generateDisplace->isChecked()) { if(displacementmap.isNull()) ui->statusBar->showMessage("calculating displacementmap..."); calcDisplace(); successfullySaved &= displacementmap.save(name_displace); } if(successfullySaved) ui->statusBar->showMessage("Maps successfully saved", 4000); else QMessageBox::information(this, "Maps not saved", "One or more of the maps was NOT saved!"); //store export path setExportPath(url.adjusted(QUrl::RemoveFilename)); //enable "Open Export Folder" gui button ui->pushButton_openExportFolder->setEnabled(true); }
//------------------------------------------------------------------------------ // drawFunc() //------------------------------------------------------------------------------ void Polygon::drawFunc() { BEGIN_DLIST unsigned int nv = getNumberOfVertices(); const osg::Vec3* vertices = getVertices(); if (nv >= 2) { // Draw with texture unsigned int ntc = getNumberOfTextureCoords(); if (ntc > 0 && hasTexture()) { const osg::Vec2* texCoord = getTextureCoord(); unsigned int tc = 0; // texture count glBegin(GL_POLYGON); for (unsigned int i = 0; i < nv; i++) { if (tc < ntc) { lcTexCoord2v(texCoord[tc++].ptr()); } lcVertex3v( vertices[i].ptr() ); } glEnd(); } // Draw without texture else { // get our color gradient, because if we have one, instead of a regular color, we will // override it here and set it on a per vertex level. ColorGradient* colGradient = dynamic_cast<ColorGradient*>(getColor()); glBegin(GL_POLYGON); osg::Vec3* ptr = nullptr; for (unsigned int i = 0; i < nv; i++) { if (colGradient != nullptr) { Basic::Color* col = colGradient->getColorByIdx(i+1); if (col != nullptr) glColor4f(static_cast<GLfloat>(col->red()), static_cast<GLfloat>(col->green()), static_cast<GLfloat>(col->blue()), static_cast<GLfloat>(col->alpha())); } // if we have a material name, we will set up like we have a material if (getMaterialName() != nullptr) { //lcVertex3v( vertices[i].ptr() ); ptr = const_cast<osg::Vec3*>(reinterpret_cast<const osg::Vec3*>(vertices[i].ptr())); if (ptr != nullptr) { calcNormal(); lcNormal3(norm.x(), norm.y(), -(norm.z())); lcVertex3(ptr->x(), ptr->y(), ptr->z()); } } else { lcVertex3v(vertices[i].ptr()); } } glEnd(); } } END_DLIST }
plane::plane(const GLfloat values[]){ for(int i = 0; i < 4; i++){ points[i].x = values[i*3]; points[i].y = values[i*3 + 1]; points[i].z = values[i*3 + 2]; } calcNormal(); calcCentroid(); }
//The primary method of instantiating a plane will be to give it an array of values plane::plane(const point pointsb[]){ for(int i = 0; i < 4; i++){ points[i].x = pointsb[i].x; points[i].y = pointsb[i].y; points[i].z = pointsb[i].z; } calcNormal(); calcCentroid(); }
const plane& plane::operator=(const GLfloat values[]){ for(int i = 0; i < 4; i++){ points[i].x = values[i*3]; points[i].y = values[i*3 + 1]; points[i].z = values[i*3 + 2]; } calcNormal(); calcCentroid(); return *this; }
Triangle::Triangle(Vector4 & v1, Vector4 & v2, Vector4 & v3, Vector4 & n1, Vector4 & n2, Vector4 & n3) { this->vertices[0].vertex = v1; this->vertices[1].vertex = v2; this->vertices[2].vertex = v3; this->vertices[0].normal = n1; this->vertices[1].normal = n2; this->vertices[2].normal = n3; this->normal = calcNormal(); this->area = 0; memset(gradient, 0.0, sizeof(gradient)); }
MyTriangle::MyTriangle() : MyPrimitive() { this->x1 = -0.5; this->y1 = -0.5; this->z1 = 0.0; this->x2 = 0.5; this->y2 = -0.5; this->z2 = 0.0; this->x3 = 0.0; this->y3 = 0.5; this->z3 = 0.0; calcNormal(); }
MyTriangle::MyTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) : MyPrimitive() { this->x1 = x1; this->y1 = y1; this->z1 = z1; this->x2 = x2; this->y2 = y2; this->z2 = z2; this->x3 = x3; this->y3 = y3; this->z3 = z3; calcNormal(); }
float Face::planeDistanceTo(XYZ &v_test) { // XYZ P = v_test; // XYZ Q = *points[0]; // Vector v = P - Q; Vector w,v; calcNormal(v); w = v_test; w -= *points[0]; return v.dotProduct(w)/v.magnitude(); }
// Creates a shadow projection matrix out of the plane equation // coefficients and the position of the light. The return value is stored // in destMat[][] void MakeShadowMatrix(GLfloat points[3][3], GLfloat lightPos[4], GLfloat destMat[4][4]) { GLfloat planeCoeff[4]; GLfloat dot; // Find the plane equation coefficients // Find the first three coefficients the same way we // find a normal. calcNormal(points,planeCoeff); // Find the last coefficient by back substitutions planeCoeff[3] = - ( (planeCoeff[0]*points[2][0]) + (planeCoeff[1]*points[2][1]) + (planeCoeff[2]*points[2][2])); // Dot product of plane and light position dot = planeCoeff[0] * lightPos[0] + planeCoeff[1] * lightPos[1] + planeCoeff[2] * lightPos[2] + planeCoeff[3] * lightPos[3]; // Now do the projection // First column destMat[0][0] = dot - lightPos[0] * planeCoeff[0]; destMat[1][0] = 0.0f - lightPos[0] * planeCoeff[1]; destMat[2][0] = 0.0f - lightPos[0] * planeCoeff[2]; destMat[3][0] = 0.0f - lightPos[0] * planeCoeff[3]; // Second column destMat[0][1] = 0.0f - lightPos[1] * planeCoeff[0]; destMat[1][1] = dot - lightPos[1] * planeCoeff[1]; destMat[2][1] = 0.0f - lightPos[1] * planeCoeff[2]; destMat[3][1] = 0.0f - lightPos[1] * planeCoeff[3]; // Third Column destMat[0][2] = 0.0f - lightPos[2] * planeCoeff[0]; destMat[1][2] = 0.0f - lightPos[2] * planeCoeff[1]; destMat[2][2] = dot - lightPos[2] * planeCoeff[2]; destMat[3][2] = 0.0f - lightPos[2] * planeCoeff[3]; // Fourth Column destMat[0][3] = 0.0f - lightPos[3] * planeCoeff[0]; destMat[1][3] = 0.0f - lightPos[3] * planeCoeff[1]; destMat[2][3] = 0.0f - lightPos[3] * planeCoeff[2]; destMat[3][3] = dot - lightPos[3] * planeCoeff[3]; }
static void _createNormal(ELEV_TYPE *data, unsigned int w, unsigned int h, unsigned char *normal) { #define BYTES_PER_PIXEL 3 ELEV_TYPE *srcptr = (ELEV_TYPE *)data; unsigned int bpp = BYTES_PER_PIXEL; double bumpZScale = -20; for(unsigned int x=0; x< w-1; x++) { for(unsigned int y=0; y< h-1; y++) { iiMath::vec3 n = calcNormal(srcptr, (int)x, (int)y, w, h); normal[x*w*bpp + y*bpp ] = (unsigned char) (128-n.x()*bumpZScale); normal[x*w*bpp + y*bpp + 1 ] = (unsigned char) (128+n.y()*bumpZScale); normal[x*w*bpp + y*bpp + 2 ] = (unsigned char) 255; if(x == (w - 2) ) { unsigned int xEdge = w-1; normal[xEdge*w*bpp + y*bpp ] = (unsigned char) (128-n.x()*bumpZScale); normal[xEdge*w*bpp + y*bpp + 1 ] = (unsigned char) (128+n.y()*bumpZScale); normal[xEdge*w*bpp + y*bpp + 2 ] = (unsigned char) 255; } if(y == (h - 2) ) { unsigned int yEdge = h-1; normal[x*w*bpp + yEdge*bpp ] = (unsigned char) (128-n.x()*bumpZScale); normal[x*w*bpp + yEdge*bpp + 1 ] = (unsigned char) (128+n.y()*bumpZScale); normal[x*w*bpp + yEdge*bpp + 2 ] = (unsigned char) 255; } if((y == (h - 2) ) && (x == (w - 2) )) { unsigned int yEdge = h-1; unsigned int xEdge = w-1; normal[xEdge*w*bpp + yEdge*bpp ] = (unsigned char) (128-n.x()*bumpZScale); normal[xEdge*w*bpp + yEdge*bpp + 1 ] = (unsigned char) (128+n.y()*bumpZScale); normal[xEdge*w*bpp + yEdge*bpp + 2 ] = (unsigned char) 255; } } } }
void MainWindow::calcSsao() { if(input.isNull()) return; //if no normalmap was created yet, calculate it if(normalmap.isNull()) { calcNormal(); } //scale depthmap (can be smaller than normalmap because of KeepLargeDetail normalmapRawIntensity = normalmapRawIntensity.scaled(normalmap.width(), normalmap.height()); float size = ui->doubleSpinBox_ssao_size->value(); unsigned int samples = ui->spinBox_ssao_samples->value(); unsigned int noiseTexSize = ui->spinBox_ssao_noiseTexSize->value(); //setup generator and calculate map SsaoGenerator ssaoGenerator; ssaomap = ssaoGenerator.calculateSsaomap(normalmap, normalmapRawIntensity, size, samples, noiseTexSize); }
void MainWindow::calcNormalAndPreview() { ui->statusBar->showMessage("calculating normalmap..."); //timer for measuring calculation time QElapsedTimer timer; timer.start(); //calculate map calcNormal(); //display time it took to calculate the map this->lastCalctime_normal = timer.elapsed(); displayCalcTime(lastCalctime_normal, "normalmap", 5000); //preview in normalmap tab preview(1); //activate corresponding save checkbox ui->checkBox_queue_generateNormal->setChecked(true); }
Foam::searchablePlate::searchablePlate ( const IOobject& io, const dictionary& dict ) : searchableSurface(io), origin_(dict.lookup("origin")), span_(dict.lookup("span")), normalDir_(calcNormal(span_)) { if (debug) { Info<< "searchablePlate::searchablePlate :" << " origin:" << origin_ << " origin+span:" << origin_+span_ << " normal:" << vector::componentNames[normalDir_] << endl; } }
Foam::searchablePlate::searchablePlate ( const IOobject& io, const point& origin, const vector& span ) : searchableSurface(io), origin_(origin), span_(span), normalDir_(calcNormal(span_)) { if (debug) { Info<< "searchablePlate::searchablePlate :" << " origin:" << origin_ << " origin+span:" << origin_+span_ << " normal:" << vector::componentNames[normalDir_] << endl; } }
void MakeShadowMatrix(float points[3][3], float lightPos[4], float destMat[4][4]) { float Coeff[3]; float dot; float d; calcNormal(points,Coeff); d = - Coeff[0]*points[0][0]-Coeff[1]*points[0][1]-Coeff[2]*points[0][2]; dot = Coeff[0]*lightPos[0]+Coeff[1]*lightPos[1]+Coeff[2]*lightPos[2]+d; // Pierwsza wiersz destMat[0][0] = dot-Coeff[0]*lightPos[0]; destMat[1][0] =-Coeff[1]*lightPos[0] ; destMat[2][0] = -Coeff[2]*lightPos[0] ; destMat[3][0] = -d*lightPos[0] ; // Druga kolumna destMat[0][1] = -Coeff[0]*lightPos[1]; destMat[1][1] =dot-Coeff[1]*lightPos[1]; destMat[2][1] =-Coeff[2]*lightPos[1] ; destMat[3][1] =-d*lightPos[1] ; // Trzecia kolumna destMat[0][2] = -Coeff[0]*lightPos[2]; ; destMat[1][2] = -Coeff[1]*lightPos[2] ; destMat[2][2] = dot-Coeff[2]*lightPos[2]; destMat[3][2] = -d*lightPos[2] ; // Czwarta kolumna destMat[0][3] = -Coeff[0]*lightPos[3]; destMat[1][3] = -Coeff[1]*lightPos[3] ; destMat[2][3] = -Coeff[2]*lightPos[3] ; destMat[3][3] = dot-d*lightPos[3]; }
void mbChargeLattice::genEdge(mbLatticeCube *cube, int edgeIndex, int pointIndex, int pointIndex2) { mbLatticeEdge *edge = cube->edges[edgeIndex]; mbVector3D interpolationResult, normalResult; float *position = edge->position; if (edge->lastFrameVisited != currentFrame) { edge->lastFrameVisited = currentFrame; interpolationResult = interpolateEdge(cube->points[pointIndex], cube->points[pointIndex2], edge->axis); position[0] = interpolationResult.x; position[1] = interpolationResult.y; position[2] = interpolationResult.z; edge->vertexIndex = vertexCount; normalResult = calcNormal(interpolationResult); int realLocation = 3 * vertexCount; meshNormals[realLocation] = normalResult.x; meshVertices[realLocation] = interpolationResult.x; meshNormals[realLocation+1] = normalResult.y; meshVertices[realLocation+1] = interpolationResult.y; meshNormals[realLocation+2] = normalResult.z; meshVertices[realLocation+2] = interpolationResult.z; vertexCount++; } };
void kostka2 (){ float normal[3]; float v[3][3]={{-10.0,-10.0,-20},{10.0,-10.0,-20},{10.0,10.0,-20}}; calcNormal(v,normal); glBegin(GL_POLYGON); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(-10.0,-10.0,-20); glVertex3f(10.0,-10.0,-20); glVertex3f(10.0,10.0,-20); glVertex3f(-10.0,10.0,-20); glEnd(); { glBegin(GL_POLYGON); float v[3][3]={{10.0,-10.0,-20},{10.0,-10.0,-40},{10.0,10.0,-40}}; calcNormal(v,normal); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(10.0,-10.0,-20); glVertex3f(10.0,-10.0,-40); glVertex3f(10.0,10.0,-40); glVertex3f(10.0,10.0,-20); glEnd(); } { glBegin(GL_POLYGON); float v[3][3]={{10.0,-10.0,-40},{-10.0,-10.0,-40},{-10.0,10.0,-40}}; calcNormal(v,normal); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(10.0,-10.0,-40); glVertex3f(-10.0,-10.0,-40); glVertex3f(-10.0,10.0,-40); glVertex3f(10.0,10.0,-40); glEnd(); } { glBegin(GL_POLYGON); float v[3][3]={{-10.0,-10.0,-40},{-10.0,-10.0,-20},{-10.0,10.0,-20}}; calcNormal(v,normal); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(-10.0,-10.0,-40); glVertex3f(-10.0,-10.0,-20); glVertex3f(-10.0,10.0,-20); glVertex3f(-10.0,10.0,-40); glEnd(); } { glBegin(GL_POLYGON); float v[3][3]={{-10.0,10.0,-2.0},{10.0,10.0,-20},{10.0,10.0,-40}}; calcNormal(v,normal); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(-10.0,10.0,-20); glVertex3f(10.0,10.0,-20); glVertex3f(10.0,10.0,-40); glVertex3f(-10.0,10.0,-40); glEnd(); } { glBegin(GL_POLYGON); float v[3][3]={{-10.0,-10.0,-40},{10.0,-10.0,-40},{10.0,-10.0,-20}}; calcNormal(v,normal); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(-10.0,-10.0,-40); glVertex3f(10.0,-10.0,-40); glVertex3f(10.0,-10.0,-20.0); glVertex3f(-10.0,-10.0,-20.0); glEnd(); } }
void kostka (){ float normal[3]; float v[3][3]={{-10.0,-10.0,-20},{10.0,-10.0,-20},{10.0,10.0,-20}}; glColor3f(1.0,0.0,0.0); calcNormal(v,normal); glBegin(GL_POLYGON); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(-10.0,-10.0,-20); glVertex3f(10.0,-10.0,-20); glVertex3f(10.0,10.0,-20); glVertex3f(-10.0,10.0,-20); glEnd(); { glBegin(GL_POLYGON); float v[3][3]={{10.0,-10.0,-20},{10.0,-10.0,-40},{10.0,10.0,-40}}; calcNormal(v,normal); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(10.0,-10.0,-20); glVertex3f(10.0,-10.0,-40); glVertex3f(10.0,10.0,-40); glVertex3f(10.0,10.0,-20); glEnd(); } glDisable( GL_TEXTURE_2D ); { glBegin(GL_POLYGON); float v[3][3]={{10.0,-10.0,-40},{-10.0,-10.0,-40},{-10.0,10.0,-40}}; calcNormal(v,normal); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(10.0,-10.0,-40); glVertex3f(-10.0,-10.0,-40); glVertex3f(-10.0,10.0,-40); glVertex3f(10.0,10.0,-40); glEnd(); } { glBegin(GL_POLYGON); float v[3][3]={{-10.0,-10.0,-40},{-10.0,-10.0,-20},{-10.0,10.0,-20}}; calcNormal(v,normal); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(-10.0,-10.0,-40); glVertex3f(-10.0,-10.0,-20); glVertex3f(-10.0,10.0,-20); glVertex3f(-10.0,10.0,-40); glEnd(); } { glBegin(GL_POLYGON); float v[3][3]={{-10.0,10.0,-2.0},{10.0,10.0,-20},{10.0,10.0,-40}}; calcNormal(v,normal); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(-10.0,10.0,-20); glVertex3f(10.0,10.0,-20); glVertex3f(10.0,10.0,-40); glVertex3f(-10.0,10.0,-40); glEnd(); } { glBegin(GL_POLYGON); float v[3][3]={{-10.0,-10.0,-40},{10.0,-10.0,-40},{10.0,-10.0,-20}}; calcNormal(v,normal); glNormal3f(normal[0],normal[1],normal[2]); glVertex3f(-10.0,-10.0,-40); glVertex3f(10.0,-10.0,-40); glVertex3f(10.0,-10.0,-20.0); glVertex3f(-10.0,-10.0,-20.0); glEnd(); } }
void gkBlenderMeshConverter::convert_legacy(void) { Blender::MFace* mface = m_bmesh->mface; Blender::MVert* mvert = m_bmesh->mvert; Blender::MCol* mcol = 0; Blender::MTFace* mtface[8] = {0, 0, 0, 0, 0, 0, 0, 0}; Blender::MVert vpak[4]; unsigned int cpak[4]; unsigned int ipak[4]; int totlayer; gkSubMesh* curSubMesh = 0; m_meshtable.clear(); gkLoaderUtils_getLayers_legacy(m_bmesh, mtface, &mcol, totlayer); bool sortByMat = gkEngine::getSingleton().getUserDefs().blendermat; bool openglVertexColor = gkEngine::getSingleton().getUserDefs().rendersystem == OGRE_RS_GL; for (int fi = 0; fi < m_bmesh->totface; fi++) { const Blender::MFace& curface = mface[fi]; // skip if face is not a triangle || quad if (!curface.v3) continue; const bool isQuad = curface.v4 != 0; TempFace t[2]; PackedFace f; f.totlay = totlayer; if (isQuad) { vpak[0] = mvert[curface.v1]; vpak[1] = mvert[curface.v2]; vpak[2] = mvert[curface.v3]; vpak[3] = mvert[curface.v4]; ipak[0] = curface.v1; ipak[1] = curface.v2; ipak[2] = curface.v3; ipak[3] = curface.v4; if (mcol != 0) { cpak[0] = packColourABGR(mcol[0]); cpak[1] = packColourABGR(mcol[1]); cpak[2] = packColourABGR(mcol[2]); cpak[3] = packColourABGR(mcol[3]); } else cpak[0] = cpak[1] = cpak[2] = cpak[3] = 0xFFFFFFFF; for (int i = 0; i < totlayer; i++) { if (mtface[i] != 0) { f.uvLayers[i][0] = gkVector2((float*)mtface[i][fi].uv[0]); f.uvLayers[i][1] = gkVector2((float*)mtface[i][fi].uv[1]); f.uvLayers[i][2] = gkVector2((float*)mtface[i][fi].uv[2]); f.uvLayers[i][3] = gkVector2((float*)mtface[i][fi].uv[3]); } } f.verts = vpak; f.index = ipak; f.colors = cpak; gkVector3 e0, e1; e0 = (gkVector3(mvert[curface.v1].co) - gkVector3(mvert[curface.v2].co)); e1 = (gkVector3(mvert[curface.v3].co) - gkVector3(mvert[curface.v4].co)); if (e0.squaredLength() < e1.squaredLength()) { convertIndexedTriangle(&t[0], 0, 1, 2, f); convertIndexedTriangle(&t[1], 2, 3, 0, f); } else { convertIndexedTriangle(&t[0], 0, 1, 3, f); convertIndexedTriangle(&t[1], 3, 1, 2, f); } } else { for (int i = 0; i < totlayer; i++) { if (mtface[i] != 0) { f.uvLayers[i][0] = gkVector2((float*)mtface[i][fi].uv[0]); f.uvLayers[i][1] = gkVector2((float*)mtface[i][fi].uv[1]); f.uvLayers[i][2] = gkVector2((float*)mtface[i][fi].uv[2]); } } vpak[0] = mvert[curface.v1]; vpak[1] = mvert[curface.v2]; vpak[2] = mvert[curface.v3]; ipak[0] = curface.v1; ipak[1] = curface.v2; ipak[2] = curface.v3; if (mcol != 0) { cpak[0] = packColourABGR(mcol[0]); cpak[1] = packColourABGR(mcol[1]); cpak[2] = packColourABGR(mcol[2]); } else cpak[0] = cpak[1] = cpak[2] = cpak[3] = 0xFFFFFFFF; f.verts = vpak; f.index = ipak; f.colors = cpak; convertIndexedTriangle(&t[0], 0, 1, 2, f); } gkMeshPair tester(curSubMesh); if (sortByMat) { int mode = 0; if (mtface[0]) mode = mtface[0][fi].mode; tester.test = gkMeshHashKey(curface.mat_nr, mode); } else { Blender::Image* ima[8] = {0, 0, 0, 0, 0, 0, 0, 0}; for (int i = 0; i < totlayer; i++) { if (mtface[i] != 0) ima[i] = mtface[i][fi].tpage; } int mode = 0, alpha = 0; if (mtface[0]) { mode = mtface[0][fi].mode; alpha = mtface[0][fi].transp; } tester.test = gkMeshHashKey(mode, alpha, ima); } // find submesh UTsize arpos = 0; if ((arpos = m_meshtable.find(tester)) == UT_NPOS) { curSubMesh = new gkSubMesh(); curSubMesh->setTotalLayers(totlayer); curSubMesh->setVertexColors(mcol != 0); m_gmesh->addSubMesh(curSubMesh); tester.item = curSubMesh; m_meshtable.push_back(tester); } else curSubMesh = m_meshtable.at(arpos).item; if (curSubMesh == 0) continue; if (!(curface.flag & ME_SMOOTH)) { // face normal calcNormal(&t[0]); if (isQuad) t[1].v0.no = t[1].v1.no = t[1].v2.no = t[0].v0.no; } int triflag = 0; if (mtface[0]) { if (mtface[0][fi].mode & TF_DYNAMIC) triflag |= gkTriangle::TRI_COLLIDER; if (mtface[0][fi].mode & TF_INVISIBLE) triflag |= gkTriangle::TRI_INVISIBLE; } else triflag = gkTriangle::TRI_COLLIDER; curSubMesh->addTriangle(t[0].v0, t[0].i0, t[0].v1, t[0].i1, t[0].v2, t[0].i2, triflag); if (isQuad) { curSubMesh->addTriangle(t[1].v0, t[1].i0, t[1].v1, t[1].i1, t[1].v2, t[1].i2, triflag); } if (mcol) mcol += 4; } }