Example #1
0
void MainWindow::on_generateButton_clicked()
{
    //Ensure all images are the same size
    if(!SameSize(topImage, rightImage, leftImage, bottomImage))
    {
        QMessageBox msgBox;
        msgBox.setText("Images are not the same size!");
        msgBox.exec();
        return;
    }

    int normalMapSize = topImage.size().width()*topImage.size().height();
    normals = new QVector3D[normalMapSize];

    for(int i = 0; i < normalMapSize; i++)
    {
        //Point all vectors -z
        normals[i].setZ(-1.0);
        normals[i].setY(0);
        normals[i].setX(0);
    }

    ProcessNormals(topImage, IMAGE::TOP);
    ProcessNormals(rightImage, IMAGE::RIGHT);
    ProcessNormals(bottomImage, IMAGE::BOTTOM);
    ProcessNormals(leftImage, IMAGE::LEFT);

    resultImage = QImage(topImage.width(), topImage.height(), QImage::Format_RGB32);

    for(int i = 0; i < normalMapSize; i++)
    {
        normals[i].normalize();
        QColor normColor;
        normColor.setRgbF((normals[i].x()+1.0)/2.0,
                          (normals[i].y()+1.0)/2.0,
                          (-normals[i].z()+1.0)/2.0);
        int yCoord = i / topImage.width();
        int xCoord = i % topImage.width();
        resultImage.setPixel(QPoint(xCoord, yCoord), normColor.rgb());
    }
    resultScene->addPixmap(QPixmap::fromImage(resultImage.scaled(QSize(100, 100))));
    ui->resultView->show();
    ui->oglWidget->SetNormalMap(resultImage);
}
Example #2
0
bool MeshMender::Mend(
                  std::vector< Vertex >&    theVerts,
				  std::vector< unsigned int >& theIndices,
				  std::vector< unsigned int >& mappingNewToOldVert,
				  const float minNormalsCreaseCosAngle,
				  const float minTangentsCreaseCosAngle,
				  const float minBinormalsCreaseCosAngle,
				  const float weightNormalsByArea,
				  const NormalCalcOption computeNormals,
				  const ExistingSplitOption respectExistingSplits,
				  const CylindricalFixOption fixCylindricalWrapping)
{
	MinNormalsCreaseCosAngle = minNormalsCreaseCosAngle;
	MinTangentsCreaseCosAngle= minTangentsCreaseCosAngle;
	MinBinormalsCreaseCosAngle = minBinormalsCreaseCosAngle;
	WeightNormalsByArea = weightNormalsByArea;
	m_RespectExistingSplits = respectExistingSplits;

	//fix cylindrical should happen before we do any other calculations
	if(fixCylindricalWrapping == FIX_CYLINDRICAL)
	{
		FixCylindricalWrapping( theVerts , theIndices , mappingNewToOldVert );
	}


	SetUpData( theVerts, theIndices, mappingNewToOldVert, computeNormals);

	//for each unique position
	for(VertexChildrenMap::iterator vert = m_VertexChildrenMap.begin();
		vert!= m_VertexChildrenMap.end();
		++vert)
	{
		D3DXVECTOR3 workingPosition = vert->first;

		TriangleList& possibleNeighbors = vert->second;
		if(computeNormals == CALCULATE_NORMALS)
		{
			ProcessNormals(possibleNeighbors, theVerts, mappingNewToOldVert, workingPosition );
		}
		ProcessTangents(possibleNeighbors, theVerts, mappingNewToOldVert, workingPosition );
		ProcessBinormals(possibleNeighbors, theVerts, mappingNewToOldVert, workingPosition );
	}

	UpdateTheIndicesWithFinalIndices(theIndices );
	OrthogonalizeTangentsAndBinormals(theVerts);

	return true;
}