It is currently Wed Aug 12, 2020 6:01 am


All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: how to set material? (SOLVED)
PostPosted: Sun Nov 11, 2012 5:29 pm 

Joined: Mon Oct 15, 2012 4:33 pm
Posts: 52
it seems easy to set... but i can't get it work. look at this code please. i'm doing something wrong?

Code:
#include "testApp.h"
#include "ofxPolyvox.h"
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
#include "PolyVoxCore/RawVolume.h"
#include "PolyVoxCore/MaterialDensityPair.h"
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"

//Use the PolyVox namespace
using namespace PolyVox;

void createRawVolume(RawVolume<MaterialDensityPair44>& volData, float fRadius)
{
   //This vector hold the position of the center of the volume
   Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);

    MaterialDensityPair44 voxel;
   //This three-level for loop iterates over every voxel in the volume
   for (int z = 0; z < volData.getWidth(); z++)
   {
      for (int y = 0; y < volData.getHeight(); y++)
      {
         for (int x = 0; x < volData.getDepth(); x++)
         {
            //Store our current position as a vector...
            Vector3DFloat v3dCurrentPos(x,y,z);
            //And compute how far the current position is from the center of the volume
            float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();

            if(fDistToCenter <= fRadius)
            {

                    uint8_t uMaterial = 2;
                    uint8_t uValue = 3;

               //Modify the density and material
               voxel.setMaterial( uMaterial );
               voxel.setDensity( MaterialDensityPair44::getMaxDensity() );
                    //voxel = MaterialDensityPair44(uValue, uValue > 0 ? MaterialDensityPair44::getMaxDensity() : MaterialDensityPair44::getMinDensity());
                    uint8_t mat = voxel.getMaterial();
                    cout << "mat:" << mat << endl;

                    volData.setVoxelAt( x, y, z, voxel );


            }

         }
      }
   }
}


//--------------------------------------------------------------
void testApp::setup(){

    ofSetLogLevel(OF_LOG_VERBOSE);

    PolyVox::Region reg(Vector3DInt32(0,0,0), Vector3DInt32(32, 32, 32));
    RawVolume<MaterialDensityPair44> volData(reg);

    createRawVolume(volData, 12);

    SurfaceMesh<PositionMaterialNormal> mesh;

   MarchingCubesSurfaceExtractor< RawVolume<MaterialDensityPair44> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);

   surfaceExtractor.execute();

    std::cout << "polyvox vertices: " << mesh.getNoOfVertices() << std::endl;
    std::cout << "polyvox indices: " << mesh.getNoOfIndices() << std::endl;

    OF_mesh.setMode(OF_PRIMITIVE_TRIANGLES);

    polyvox.polyvoxToOfMesh(mesh,OF_mesh);

    std::cout << "OF_mesh vertices: " << OF_mesh.getNumVertices() << std::endl;

    }


and here where i get the materialid and i apply to the OF mesh:

Code:
  for (int i = 0; i < surfaceMesh.getNoOfVertices(); i++ ){

    PositionMaterialNormal vert0 = vecVertices[i];
    //uint8_t material = static_cast<uint8_t>(vert0.getMaterial() + 0.5);
    uint8_t material = static_cast<uint8_t>(vert0.getMaterial() + 0.5);
    cout << "material:" << material << endl;
    ofFloatColor colour = convertMaterialIDToColour(material);


    polyvxToOfMesh.addColor(colour);

    }

ofFloatColor  ofxPolyvox::convertMaterialIDToColour(uint8_t materialID)
{
   ofFloatColor colour;

   switch(materialID)
   {
   case 1:

      colour.red = 255.0f;
      colour.green = 0.0f;
      colour.blue = 0.0f;
      break;
   case 2:
      colour.red = 0.0f;
      colour.green = 255.0f;
      colour.blue = 0.0f;
      break;
   case 3:
      colour.red = 0.0f;
      colour.green = 0.0f;
      colour.blue = 1.0f;
      break;
   case 4:
      colour.red = 1.0f;
      colour.green = 1.0f;
      colour.blue = 0.0f;
      break;
   case 5:
      colour.red = 1.0f;
      colour.green = 0.0f;
      colour.blue = 1.0f;
      break;
   default:
      colour.red = 1.0f;
      colour.green = 1.0f;
      colour.blue = 1.0f;
   }

   return colour;
}


but it seems that no material is assigned to every vertex because i receive from
Code:
uint8_t mat = voxel.getMaterial();
    cout << "mat:" << mat << endl;


the cout output absolutely nothing! So i suppose that i miss to add some very relevant part...
I looked for this at your OpenGL example, but you use LargeVolume, i tried also with LargeVolume but with the same luck.


Last edited by kalwalt on Mon Nov 12, 2012 6:04 pm, edited 1 time in total.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: how to set material?
PostPosted: Mon Nov 12, 2012 1:43 am 

Joined: Fri Sep 14, 2012 10:54 pm
Posts: 15
If the cout outputs nothing i guess
Code:
if(fDistToCenter <= fRadius)

never becomes true.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: how to set material?
PostPosted: Mon Nov 12, 2012 9:14 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
As KuroSei says you should investigate why the 'cout' is never being executed. Can you step through with the dubugger to see why the 'fDistToCenter <= fRadius' condition is never true? Or place a cout outsite of that condition to check if the loop is being executed?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: how to set material?
PostPosted: Mon Nov 12, 2012 1:16 pm 

Joined: Mon Oct 15, 2012 4:33 pm
Posts: 52
I think I expressed myself badly. I wanted to say that "cout" in the console I get only "mat" but no value (even not 0!) and this means that the material is not assigned? but instead have a look at the image of my debugging it seems that instead the Material is assigned to the voxel!


Attachments:
Screenshot.Jpeg
Screenshot.Jpeg [ 197.21 KiB | Viewed 6722 times ]
Top
Offline Profile  
Reply with quote  
 Post subject: Re: how to set material?
PostPosted: Mon Nov 12, 2012 3:32 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Try this:

Code:
cout << "mat:" << int(mat) << endl;


However, I would be more interested in knowing if you are still getting a valid mesh (even if the materials are wrong). Does it have valid vertices and indices or is the mesh completly empty?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: how to set material?
PostPosted: Mon Nov 12, 2012 4:41 pm 

Joined: Mon Oct 15, 2012 4:33 pm
Posts: 52
Quote:
Code:
cout << "mat:" << int(mat) << endl;


this help me now i get mat: 2 !
Quote:
However, I would be more interested in knowing if you are still getting a valid mesh (even if the materials are wrong). Does it have valid vertices and indices or is the mesh completly empty?


yes,i have a valid mesh and vertices and indices.

The problem is not in the mesh ( it always build, a sphere) but where i use the material info to add the color to the mesh.
p.s. now it is more related to my implementation in OF because i add this
Quote:
bool col = polyvxToOfMesh.hasColors();

cout << "hasColors:" << col << endl;


give me true values so i think there will be a setting to display Color in a ofMesh class that i don't know...


Top
Offline Profile  
Reply with quote  
 Post subject: Re: how to set material?
PostPosted: Mon Nov 12, 2012 5:34 pm 

Joined: Mon Oct 15, 2012 4:33 pm
Posts: 52
i solved the problem!
first i changed :

Quote:
ofFloatColor colour = convertMaterialIDToColour(material);

to
Quote:
ofFloatColor colour = convertMaterialIDToColour(int(material));


and inside convertMaterialIDToColour(int material) where i define the colors with ofFloatColor


Quote:
colour.red = 1.0f
colour.green = 0.0f;
colur.blue = 0.0f;


to
Quote:
ofFloatColor ofxPolyvox::convertMaterialIDToColour(int materialID)
{
ofFloatColor colour;

switch(materialID)
{
case 1:

colour = ofFloatColor(1.0f,0.0f,0.0f);

break;
case 2:

colour = ofFloatColor(0.0f,1.0f,0.0f);

break;
case 3:

colour = ofFloatColor(0.0f,0.0f,1.0f);

break;
case 4:

colour = ofFloatColor(1.0f,1.0f,0.0f);

break;
case 5:

colour = ofFloatColor(1.0f,0.0f,1.0f);

break;
default:

colour = ofFloatColor(1.0f,1.0f,1.0f);
}

return colour;
}


the reason that weren't displaied the colors was that ofFloatColor accept colours.red (or .green , .blue but has a different meaning)

Now i have my ofMesh coloured in the window!
ofxPolyvox development will continue... :lol:


Top
Offline Profile  
Reply with quote  
 Post subject: Re: how to set material?
PostPosted: Mon Nov 12, 2012 6:03 pm 

Joined: Mon Oct 15, 2012 4:33 pm
Posts: 52
anyway this wasn't the problem:
Code:
 ofFloatColor colour = convertMaterialIDToColour(int(material));


switching again to:
Code:
 ofFloatColor colour = convertMaterialIDToColour(material);


do the same . the core of the issue resided in the
Code:
colour = ofFloatColor(1.0f,0.0f,0.0f);
way. this is the most important thing!

thanks for your suggestions because(even if doesn't seem) this help me a lot!


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net