Beispiel #1
0
//--------------------------------------------------------------
void ofVbo::setMesh(const ofMesh & mesh, int usage, bool useColors, bool useTextures, bool useNormals){
	if(mesh.getVertices().empty()){
		ofLogWarning("ofVbo") << "setMesh(): ignoring mesh with no vertices";
		return;
	}
	setVertexData(mesh.getVerticesPointer(),mesh.getNumVertices(),usage);
	if(mesh.hasColors() && useColors){
		setColorData(mesh.getColorsPointer(),mesh.getNumColors(),usage);
		enableColors();
	}else{
		disableColors();
	}
	if(mesh.hasNormals() && useNormals){
		setNormalData(mesh.getNormalsPointer(),mesh.getNumNormals(),usage);
		enableNormals();
	}else{
		disableNormals();
	}
	if(mesh.hasTexCoords() && useTextures){
		setTexCoordData(mesh.getTexCoordsPointer(),mesh.getNumTexCoords(),usage);
		enableTexCoords();
	}else{
		disableTexCoords();
	}
	if(mesh.hasIndices()){
		setIndexData(mesh.getIndexPointer(), mesh.getNumIndices(), usage);
		enableIndices();
	}else{
		disableIndices();
	}
}
Beispiel #2
0
void ofxMesh::fromMesh(const ofMesh & mesh){
    if (mesh.hasVertices()) {
        getVertices()=mesh.getVertices();
    }
    if (mesh.hasColors()) {
        getColors()=mesh.getColors();
    }
    if (mesh.hasNormals()) {
        getNormals()=mesh.getNormals();
    }
    if (mesh.hasTexCoords()) {
        getTexCoords()=mesh.getTexCoords();
    }
    if (mesh.hasIndices()) {
        getIndices()=mesh.getIndices();
    }
}
Beispiel #3
0
//--------------------------------------------------------------
void ofVbo::setMesh(const ofMesh & mesh, int usage){
	setMesh(mesh,usage,mesh.hasColors(),mesh.hasTexCoords(),mesh.hasNormals());
}
Beispiel #4
0
void ofxPolyvox::polyvoxToOfMesh(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh, ofMesh& polyvxToOfMesh, bool setColor){

    //Convienient access to the vertices and indices
	const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
	const vector<PositionMaterialNormal>& vecVertices = surfaceMesh.getVertices();//surfaceMesh.getRawVertexData();

	ofIndexType ofVecIndices;
	const void* pIndices = static_cast<const void*>(&(vecIndices[0]));

	int* indices = (int*)pIndices;

    vector<int> indx;


     for (int i = 0; i < surfaceMesh.getNoOfIndices(); i++ ){

     indx.push_back(indices[i]);
     //cout << "indices:" << indices[i] << endl;
    polyvxToOfMesh.addIndex(indx[i]);
     }

	ofLog(OF_LOG_NOTICE, "ofMesh: number of indices is %d", polyvxToOfMesh.getNumIndices());

    ofVec3f ofVecVertices;


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


    PositionMaterialNormal vert0 = vecVertices[i];


    ofVecVertices = ofVec3f(vert0.getPosition().getX(),vert0.getPosition().getY(),vert0.getPosition().getZ());

    polyvxToOfMesh.addVertex(ofVecVertices);

    }

	 ofLog(OF_LOG_NOTICE, "ofMesh: number of vertices is %d", polyvxToOfMesh.getNumVertices());

    ofVec3f ofVecNormals;

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


    PositionMaterialNormal vert0 = vecVertices[i];


    ofVecNormals = ofVec3f(vert0.getNormal().getX(),vert0.getNormal().getY(),vert0.getNormal().getZ());

    polyvxToOfMesh.addNormal(ofVecNormals);

    }

	ofLog(OF_LOG_NOTICE, "ofMesh: number of normals is %d", polyvxToOfMesh.getNumNormals());


    if(setColor){

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

        PositionMaterialNormal vert0 = vecVertices[i];

        uint8_t material = static_cast<uint8_t>(vert0.getMaterial() + 0.5);

        //cout << "material:" << int(material) << endl;

        ofFloatColor colour = convertMaterialIDToColour(material);

        //cout << colour << endl;

        polyvxToOfMesh.addColor(colour);

        bool col = polyvxToOfMesh.hasColors();

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

    }

}