本文整理汇总了C++中ofMesh::getNumIndices方法的典型用法代码示例。如果您正苦于以下问题:C++ ofMesh::getNumIndices方法的具体用法?C++ ofMesh::getNumIndices怎么用?C++ ofMesh::getNumIndices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofMesh
的用法示例。
在下文中一共展示了ofMesh::getNumIndices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
//----------------------------------------------------------
void ofGLRenderer::draw(ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals){
if (bSmoothHinted) startSmoothing();
#ifndef TARGET_OPENGLES
glPushAttrib(GL_POLYGON_BIT);
glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(renderType));
draw(vertexData,useColors,useTextures,useNormals);
glPopAttrib(); //TODO: GLES doesnt support polygon mode, add renderType to gl renderer?
#else
if(vertexData.getNumVertices()){
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(ofVec3f), vertexData.getVerticesPointer());
}
if(vertexData.getNumNormals() && useNormals){
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, vertexData.getNormalsPointer());
}
if(vertexData.getNumColors() && useColors){
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4,GL_FLOAT, sizeof(ofFloatColor), vertexData.getColorsPointer());
}
if(vertexData.getNumTexCoords() && useTextures){
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, vertexData.getTexCoordsPointer());
}
GLenum drawMode;
switch(renderType){
case OF_MESH_POINTS:
drawMode = GL_POINTS;
break;
case OF_MESH_WIREFRAME:
drawMode = GL_LINES;
break;
case OF_MESH_FILL:
drawMode = ofGetGLPrimitiveMode(vertexData.getMode());
break;
default:
drawMode = ofGetGLPrimitiveMode(vertexData.getMode());
break;
}
if(vertexData.getNumIndices()){
glDrawElements(drawMode, vertexData.getNumIndices(),GL_UNSIGNED_SHORT,vertexData.getIndexPointer());
}else{
glDrawArrays(drawMode, 0, vertexData.getNumVertices());
}
if(vertexData.getNumColors() && useColors){
glDisableClientState(GL_COLOR_ARRAY);
}
if(vertexData.getNumNormals() && useNormals){
glDisableClientState(GL_NORMAL_ARRAY);
}
if(vertexData.getNumTexCoords() && useTextures){
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
#endif
if (bSmoothHinted) endSmoothing();
}
示例2: fuseNeighbours
void MeshHelper::fuseNeighbours( ofMesh& mesh, float fuseDistance )
{
//@todo tex coords, normals
assert( mesh.getMode() == OF_PRIMITIVE_TRIANGLES );
int oldNumVerts = mesh.getNumVertices();
int oldNumIndices = mesh.getNumIndices();
if ( fuseDistance < 0 )
{
// fuse close-enough vertices
// first define 'close enough' as 1/10000 of smallest dimension of the bounding box width/height/depth
ofVec3f tlb, brf; // top left back, bottom right front
calculateAABoundingBox( mesh, tlb, brf );
float minDimension = min(brf.x-tlb.x,min(brf.y-tlb.y, brf.z-tlb.z));
fuseDistance = minDimension * 0.00001f;
}
// now fuse
map<ofIndexType,ofIndexType> fused;
vector<ofVec3f> newVertices;
vector<ofIndexType> remove;
for ( ofIndexType i=0; i<mesh.getNumVertices(); i++ )
{
const ofVec3f& vertex = mesh.getVertex(i);
// look at all the earlier vertices
bool didFuse = false;
for ( ofIndexType j=0; j<newVertices.size(); j++ ) {
if ( (vertex-newVertices[j]).length()<fuseDistance ) {
// fuse i to j
fused[i] = j;
remove.push_back(i);
didFuse = true;
break;
}
}
if ( !didFuse ) {
newVertices.push_back( vertex );
fused[i] = newVertices.size()-1;
}
}
// update indices
for ( int i=0; i<mesh.getNumIndices(); i++ ) {
ofIndexType originalIndex = mesh.getIndex(i);
assert( fused.find( originalIndex ) != fused.end() );
if ( fused.find(originalIndex) != fused.end() ) {
mesh.getIndices()[i] = fused[originalIndex];
}
}
// remove the fused
for ( int i=remove.size()-1; i>=0; i-- ) {
mesh.removeVertex( remove[i] );
}
ofLogNotice("MeshHelper") << "fuseNeighbours inplace: input " << oldNumVerts << " vertices/" << oldNumIndices << " indices, output " << mesh.getNumVertices() << " vertices/" << mesh.getNumIndices() << " indices";
}
示例3: save
void ofxObjLoader::save(string path, ofMesh& mesh){
path = ofToDataPath(path);
GLuint writeMode = GLM_NONE;
GLMmodel* m = new GLMmodel();
if(mesh.getNumVertices() > 0){
m->numvertices = mesh.getNumVertices();
m->vertices = new GLfloat[m->numvertices*3+1];
memcpy(&m->vertices[3], &mesh.getVertices()[0].x, sizeof(ofVec3f) * mesh.getNumVertices());
}
else {
ofLogError("ofxObjLoader::save -- No vertices to save!");
return;
}
if(mesh.getNumNormals() > 0){
m->numnormals = mesh.getNumNormals();
m->normals = new GLfloat[m->numnormals*3+1];
memcpy(&m->normals[3], &mesh.getNormals()[0].x, sizeof(ofVec3f)*mesh.getNumNormals());
writeMode |= GLM_SMOOTH;
}
if(mesh.getNumTexCoords() > 0){
m->numtexcoords = mesh.getNumTexCoords();
m->texcoords = new GLfloat[m->numtexcoords*2+1];
memcpy(&m->texcoords[2], &mesh.getTexCoords()[0].x, sizeof(ofVec2f)*mesh.getNumTexCoords());
writeMode |= GLM_TEXTURE;
}
if(mesh.getNumIndices() > 0){
//create triangles
m->numtriangles = mesh.getNumIndices()/3;
m->triangles = new GLMtriangle[m->numtriangles];
//add them all to one group
m->groups = new GLMgroup();
m->groups->next = NULL;
m->groups->material = NULL;
string name = "ofMesh";
m->groups->name = (char*)malloc(sizeof(char) * name.length()+1);
strcpy(m->groups->name, name.c_str());
m->groups->numtriangles = mesh.getNumIndices()/3;
m->groups->triangles = new GLuint[m->groups->numtriangles];
m->numgroups = 1;
for(int i = 0; i < mesh.getNumIndices()/3; i++){
memcpy(m->triangles[i].vindices, &mesh.getIndices()[i*3], sizeof(GLuint)*3);
memcpy(m->triangles[i].nindices, &mesh.getIndices()[i*3], sizeof(GLuint)*3);
memcpy(m->triangles[i].tindices, &mesh.getIndices()[i*3], sizeof(GLuint)*3);
m->groups->triangles[i] = i;
}
}
glmWriteOBJ(m, (char*)path.c_str(), writeMode);
glmDelete(m);
}
示例4: getClosestTripletOnMesh
int getClosestTripletOnMesh(const ofMesh& objectMesh,const ofMesh& imageMesh, float x, float y, float* distance) {
float bestDistance = numeric_limits<float>::infinity();
int bestChoice = 0;
for(int i = 0; i < objectMesh.getNumIndices()/3; i++) {
ofVec3f cur = ofVec3f(0,0,0);
for (int j=0;j<3;j++) {
cur+=imageMesh.getVerticesPointer()[objectMesh.getIndexPointer()[3*i+j]];
}
cur/=3.0;
float dx = x - cur.x;
float dy = y - cur.y;
float dz = 0 - cur.z;
float curDistance = dx * dx + dy * dy + dz * dz;
if(curDistance < bestDistance) {
bestDistance = curDistance;
bestChoice = i;
}
}
return bestChoice;
}
示例5: setNormals
void PyramidBrush::setNormals(ofMesh& mesh) {
int nV = mesh.getNumVertices();
int nT = mesh.getNumIndices() / 3;
vector<ofPoint> norm(nV);
for(int t=0; t < nT; t++) {
int i1 = mesh.getIndex(3*t);
int i2 = mesh.getIndex(3*t + 1);
int i3 = mesh.getIndex(3*t + 2);
const ofPoint &v1 = mesh.getVertex(i1);
const ofPoint &v2 = mesh.getVertex(i2);
const ofPoint &v3 = mesh.getVertex(i3);
ofPoint dir = ( (v2 - v1).crossed(v3 - v1)).normalized();
norm[i1] += dir;
norm[i2] += dir;
norm[i3] += dir;
}
for(int i = 0; i < nV; i++) {
norm[i].normalize();
}
mesh.clearNormals();
mesh.addNormals(norm);
}
示例6: setMesh
//--------------------------------------------------------------
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();
}
}
示例7: setMesh
//--------------------------------------------------------------
void ofVboByteColor::setMesh(const ofMesh & mesh, int usage){
setVertexData(mesh.getVerticesPointer(),mesh.getNumVertices(),usage);
setColorData(mesh.getColorsPointer(),mesh.getNumColors(),usage);
setNormalData(mesh.getNormalsPointer(),mesh.getNumNormals(),usage);
setTexCoordData(mesh.getTexCoordsPointer(),mesh.getNumTexCoords(),usage);
setIndexData(mesh.getIndexPointer(), mesh.getNumIndices(), usage);
}
示例8: updateMesh
//--------------------------------------------------------------
void ofxBulletTriMeshShape::updateMesh( btDiscreteDynamicsWorld* a_world, ofMesh& aMesh ) {
if( aMesh.getNumVertices() != totalVerts || aMesh.getNumIndices() != totalIndices ) {
ofLogWarning() << "updateMesh :: the verts or the indices are not the correct size, not updating";
return;
}
auto& tverts = aMesh.getVertices();
btVector3 aabbMin(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
btVector3 aabbMax(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
for( int i = 0; i < totalVerts; i++ ) {
auto& v = tverts[i];
bullet_vertices[i].setValue( v.x, v.y, v.z );
aabbMin.setMin( bullet_vertices[i] );
aabbMax.setMax( bullet_vertices[i] );
}
btBvhTriangleMeshShape* triShape = (btBvhTriangleMeshShape*)_shape;
// triShape->partialRefitTree( aabbMin, aabbMax );
triShape->refitTree( aabbMin, aabbMax );
//clear all contact points involving mesh proxy. Note: this is a slow/unoptimized operation.
a_world->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs( getRigidBody()->getBroadphaseHandle(), a_world->getDispatcher());
}
示例9: convertFromIndices
ofMesh convertFromIndices(const ofMesh& mesh) {
ofMesh result;
// have to do a const_cast because ofMesh::get*() is not const correct
ofMesh& cmesh = const_cast<ofMesh&>(mesh);
int vertices = mesh.getNumVertices();
int colors = mesh.getNumColors();
int normals = mesh.getNumNormals();
int texcoords = mesh.getNumTexCoords();
int indices = mesh.getNumIndices();
for(int i = 0; i < indices; i++) {
int cur = cmesh.getIndex(i);
if(vertices > 0) {
result.addVertex(cmesh.getVertex(cur));
}
if(colors > 0) {
result.addColor(cmesh.getColor(cur));
}
if(normals > 0) {
result.addNormal(cmesh.getNormal(cur));
}
if(texcoords > 0) {
result.addTexCoord(cmesh.getTexCoord(cur));
}
}
return result;
}
示例10: setNormals
//Universal function which sets normals for the triangle mesh
void ofxOcean::setNormals( ofMesh &mesh ){
//The number of the vertices
int nV = mesh.getNumVertices();
//The number of the triangles
int nT = mesh.getNumIndices() / 3;
vector<ofPoint> norm( nV ); //Array for the normals
//Scan all the triangles. For each triangle add its
//normal to norm's vectors of triangle's vertices
for (int t=0; t<nT; t++) {
//Get indices of the triangle t
int i1 = mesh.getIndex( 3 * t );
int i2 = mesh.getIndex( 3 * t + 1 );
int i3 = mesh.getIndex( 3 * t + 2 );
//Get vertices of the triangle
const ofPoint &v1 = mesh.getVertex( i1 );
const ofPoint &v2 = mesh.getVertex( i2 );
const ofPoint &v3 = mesh.getVertex( i3 );
//Compute the triangle's normal
ofPoint dir = ( (v2 - v1).getCrossed( v3 - v1 ) ).getNormalized();
//Accumulate it to norm array for i1, i2, i3
norm[ i1 ] += dir;
norm[ i2 ] += dir;
norm[ i3 ] += dir;
}
//Normalize the normal's length
for (int i=0; i<nV; i++) {
norm[i].normalize();
}
//Set the normals to mesh
mesh.clearNormals();
mesh.addNormals( norm );
}
示例11: setNormals
//--------------------------------------------------------------
//Universal function which sets normals for the triangle mesh
void setNormals( ofMesh &mesh ){
int nV = mesh.getNumVertices();//640
int nT = mesh.getNumIndices() / 3;//213
vector<ofPoint> norm( nV );
for (int t=0; t<nT; t++) {
int i1 = mesh.getIndex( 3 * t );
int i2 = mesh.getIndex( 3 * t + 1 );
int i3 = mesh.getIndex( 641 );
const ofPoint &v1 = mesh.getVertex( i1 );
const ofPoint &v2 = mesh.getVertex( i2 );
const ofPoint &v3 = mesh.getVertex( i3 );
//Compute the triangle's normal
ofPoint dir = ( (v2 - v1).crossed( v3 - v1 ) ).normalized();
norm[ i1 ] += dir;
norm[ i2 ] += dir;
norm[ i3 ] += dir;
}
//Normalize the normal's length
for (int i=0; i<nV; i++) {
norm[i].normalize();
}
//Set the normals to mesh
mesh.clearNormals();
mesh.addNormals( norm );
}
示例12: buildNormals
void buildNormals(ofMesh& mesh) {
if(mesh.getNumIndices() > 0) {
buildNormalsAverage(mesh);
} else {
buildNormalsFaces(mesh);
}
}
示例13: draw
//----------------------------------------------------------
void ofGLRenderer::draw(const ofMesh & vertexData, bool useColors, bool useTextures, bool useNormals) const{
if(vertexData.getNumVertices()){
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(ofVec3f), &vertexData.getVerticesPointer()->x);
}
if(vertexData.getNumNormals() && useNormals){
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(ofVec3f), &vertexData.getNormalsPointer()->x);
}
if(vertexData.getNumColors() && useColors){
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4,GL_FLOAT, sizeof(ofFloatColor), &vertexData.getColorsPointer()->r);
}
if(vertexData.getNumTexCoords() && useTextures){
set<int>::iterator textureLocation = textureLocationsEnabled.begin();
for(;textureLocation!=textureLocationsEnabled.end();textureLocation++){
glActiveTexture(GL_TEXTURE0+*textureLocation);
glClientActiveTexture(GL_TEXTURE0+*textureLocation);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(ofVec2f), &vertexData.getTexCoordsPointer()->x);
}
glActiveTexture(GL_TEXTURE0);
glClientActiveTexture(GL_TEXTURE0);
}
if(vertexData.getNumIndices()){
#ifdef TARGET_OPENGLES
glDrawElements(ofGetGLPrimitiveMode(vertexData.getMode()), vertexData.getNumIndices(),GL_UNSIGNED_SHORT,vertexData.getIndexPointer());
#else
glDrawElements(ofGetGLPrimitiveMode(vertexData.getMode()), vertexData.getNumIndices(),GL_UNSIGNED_INT,vertexData.getIndexPointer());
#endif
}else{
glDrawArrays(ofGetGLPrimitiveMode(vertexData.getMode()), 0, vertexData.getNumVertices());
}
if(vertexData.getNumColors() && useColors){
glDisableClientState(GL_COLOR_ARRAY);
}
if(vertexData.getNumNormals() && useNormals){
glDisableClientState(GL_NORMAL_ARRAY);
}
if(vertexData.getNumTexCoords() && useTextures){
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
示例14: create
//--------------------------------------------------------------
void ofxBulletSoftTriMesh::create( ofxBulletWorldSoft* a_world, ofMesh& aMesh, btTransform &a_bt_tr, float a_mass ) {
if(a_world == NULL) {
ofLogError("ofxBulletSoftTriMesh") << "create(): a_world param is NULL";
return;
}
if( aMesh.getMode() != OF_PRIMITIVE_TRIANGLES ) {
ofLogError("ofxBulletSoftTriMesh") << " only excepts meshes that are triangles";
return;
}
_world = a_world;
_cachedMesh.clear();
_cachedMesh = aMesh;
if( bullet_vertices != NULL ) {
delete bullet_vertices;
bullet_vertices = NULL;
}
int vertStride = sizeof(btVector3);
int indexStride = 3*sizeof(int);
int totalVerts = (int)aMesh.getNumVertices();
int totalIndices = (int)aMesh.getNumIndices();
bullet_vertices = new btScalar[ totalVerts * 3 ];
int* bullet_indices = new int[ totalIndices ];
auto& tverts = aMesh.getVertices();
vector< ofIndexType >& tindices = aMesh.getIndices();
for( int i = 0; i < totalVerts; i++ ) {
bullet_vertices[i*3+0] = tverts[i].x;
bullet_vertices[i*3+1] = tverts[i].y;
bullet_vertices[i*3+2] = tverts[i].z;
}
for( int i = 0; i < totalIndices; i++ ) {
bullet_indices[i] = tindices[i];
}
_softBody = btSoftBodyHelpers::CreateFromTriMesh( _world->getInfo(),
bullet_vertices,
bullet_indices,
totalIndices/3 );
_softBody->transform( a_bt_tr );
setMass( a_mass, true );
setCreated(_softBody);
createInternalUserData();
delete [] bullet_indices;
}
示例15: draw
//----------------------------------------------------------
void ofGLRenderer::draw(ofMesh & vertexData){
if(vertexData.getNumVertices()){
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(ofVec3f), vertexData.getVerticesPointer());
}
if(vertexData.getNumNormals()){
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, vertexData.getNormalsPointer());
}
if(vertexData.getNumColors()){
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4,GL_FLOAT, sizeof(ofColor), vertexData.getColorsPointer());
}
if(vertexData.getNumTexCoords()){
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, vertexData.getTexCoordsPointer());
}
if(vertexData.getNumIndices()){
#ifdef TARGET_OPENGLES
glDrawElements(ofGetGLPrimitiveMode(vertexData.getMode()), vertexData.getNumIndices(),GL_UNSIGNED_SHORT,vertexData.getIndexPointer());
#else
glDrawElements(ofGetGLPrimitiveMode(vertexData.getMode()), vertexData.getNumIndices(),GL_UNSIGNED_INT,vertexData.getIndexPointer());
#endif
}else{
glDrawArrays(ofGetGLPrimitiveMode(vertexData.getMode()), 0, vertexData.getNumVertices());
}
if(vertexData.getNumColors()){
glDisableClientState(GL_COLOR_ARRAY);
}
if(vertexData.getNumNormals()){
glDisableClientState(GL_NORMAL_ARRAY);
}
if(vertexData.getNumTexCoords()){
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}