本文整理汇总了C++中ofMesh::getVertices方法的典型用法代码示例。如果您正苦于以下问题:C++ ofMesh::getVertices方法的具体用法?C++ ofMesh::getVertices怎么用?C++ ofMesh::getVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofMesh
的用法示例。
在下文中一共展示了ofMesh::getVertices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ofxScale
void ofxScale(ofMesh &mesh, float x, float y, float z) {
for (int i=0; i<mesh.getNumVertices(); i++) {
mesh.getVertices()[i].x *= x;
mesh.getVertices()[i].y *= y;
mesh.getVertices()[i].z *= z;
}
}
示例2: colorFaces
//--------------------------------------------------------------
void ofApp::colorFaces(ofMesh & mesh){
for(int i = 0; i < mesh.getVertices().size(); i++){
const ofVec3f & v = mesh.getVertices()[i];
ofColor col;
col.setHsb(ofMap(v.x + v.y, -1000, 1000, 0, 255), 255, 255);
mesh.addColor(col);
}
}
示例3: buildNormalsFaces
void buildNormalsFaces(ofMesh& mesh) {
mesh.clearNormals();
for(int i = 0; i < mesh.getNumVertices(); i += 3) {
int i0 = i + 0, i1 = i + 1, i2 = i + 2;
ofVec3f normal = getNormal(mesh.getVertices()[i0], mesh.getVertices()[i1], mesh.getVertices()[i2]);
for(int j = 0; j < 3; j++) {
mesh.addNormal(normal);
}
}
}
示例4: returnMeshWarpedToThisMesh
ofMesh meshPointAdder::returnMeshWarpedToThisMesh(ofMesh & meshToMatch){
// this could / should be optimized;
ofMesh newMesh;
vector < ofPoint > newPoints;
vector < ofPoint > newTexPoints;
for (int i = 0; i < ptsList.size(); i++){
int who = ptsListBarycentric[i].whichTriangle;
float a = ptsListBarycentric[i].a;
float b = ptsListBarycentric[i].b;
float c = ptsListBarycentric[i].c;
ofPoint newPos = ApplyBarycentric(
meshToMatch.getVertices()[who*3+0],
meshToMatch.getVertices()[who*3+1],
meshToMatch.getVertices()[who*3+2],a,b,c);
ofVec2f newTex = ApplyBarycentric(
meshToMatch.getTexCoord(who*3+0),
meshToMatch.getTexCoord(who*3+0),
meshToMatch.getTexCoord(who*3+0),a,b,c);
newPoints.push_back(newPos);
newTexPoints.push_back(newTex);
}
ofMesh objectMesh;
for(int i = 0; i < triangles.size(); i++){
ofVec3f p1 = newPoints[triangles[i].a];
ofVec3f p2 = newPoints[triangles[i].b];
ofVec3f p3 = newPoints[triangles[i].c];
objectMesh.addVertex(p1);
objectMesh.addVertex(p2);
objectMesh.addVertex(p3);
ofVec3f t1 = newTexPoints[triangles[i].a];
ofVec3f t2 = newTexPoints[triangles[i].b];
ofVec3f t3 = newTexPoints[triangles[i].c];
objectMesh.addTexCoord(t1);
objectMesh.addTexCoord(t2);
objectMesh.addTexCoord(t3);
}
return objectMesh;
}
示例5: load
//--------------------------------------------------------------
bool load(const string& path, ofMesh& mesh)
{
ofFile file(path, ofFile::ReadOnly, true);
if (!file.exists()) {
ofLogError("ofxBinaryMesh::load") << "Cannot open file at " << path;
return false;
}
mesh.clear();
int numVerts = 0;
file.read((char *)(&numVerts), sizeof(int));
if (numVerts > 0) {
mesh.getVertices().resize(numVerts);
file.read((char *)(&(mesh.getVertices())[0]), sizeof(ofPoint) * numVerts);
}
int numNormals = 0;
file.read((char *)(&numNormals), sizeof(int));
if (numNormals > 0) {
mesh.getNormals().resize(numNormals);
file.read((char *)(&(mesh.getNormals())[0]), sizeof(ofPoint) * numNormals);
}
int numTexCoords = 0;
file.read((char *)(&numTexCoords), sizeof(int));
if (numTexCoords > 0) {
mesh.getTexCoords().resize(numTexCoords);
file.read((char *)(&(mesh.getTexCoords())[0]), sizeof(ofVec2f) * numTexCoords);
}
int numColors = 0;
file.read((char *)(&numColors), sizeof(int));
if (numColors > 0) {
mesh.getColors().resize(numColors);
file.read((char *)(&(mesh.getColors())[0]), sizeof(ofFloatColor) * numColors);
}
int numIndices = 0;
file.read((char *)(&numIndices), sizeof(int));
if (numIndices > 0) {
mesh.getIndices().resize(numIndices);
file.read((char *)(&(mesh.getIndices())[0]), sizeof(ofIndexType) * numIndices);
}
file.close();
return true;
}
示例6: buildNormalsAverage
void buildNormalsAverage(ofMesh& mesh) {
vector<ofIndexType>& indices = mesh.getIndices();
vector<ofVec3f> normals(mesh.getNumVertices());
for(int i = 0; i < indices.size(); i += 3) {
int i0 = indices[i + 0], i1 = indices[i + 1], i2 = indices[i + 2];
ofVec3f normal = getNormal(mesh.getVertices()[i0], mesh.getVertices()[i1], mesh.getVertices()[i2]);
normals[i0] += normal;
normals[i1] += normal;
normals[i2] += normal;
}
for(int i = 0; i < normals.size(); i++) {
normals[i].normalize();
}
mesh.addNormals(normals);
}
示例7: 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());
}
示例8: ofBitmapStringGetMesh
ofMesh & ofBitmapStringGetMesh(const string & text, int x, int y){
int len = (int)text.length();
//float yOffset = 0;
float fontSize = 8.0f;
bool bOrigin = false;
float sx = x;
float sy = y-fontSize;
ofDrawBitmapCharacterStart(text.size());
for(int c = 0; c < len; c++){
if(text[c] == '\n'){
sy += bOrigin ? -1 : 1 * (fontSize*1.7);
sx = x;
//glRasterPos2f(x,y + (int)yOffset);
} else if (text[c] >= 32){
// < 32 = control characters - don't draw
// solves a bug with control characters
// getting drawn when they ought to not be
ofDrawBitmapCharacter(text[c], (int)sx, (int)sy);
sx += fontSize;
}
}
//We do this because its way faster
charMesh.getVertices().resize(vC);
charMesh.getTexCoords().resize(vC);
return charMesh;
}
示例9: ofDrawBitmapCharacterEnd
//---------------------------------------------------------------------
void ofDrawBitmapCharacterEnd(){
if( vC > 0 ){
charMesh.getVertices().resize(vC);
charMesh.getTexCoords().resize(vC);
bitmappedFontTexture.bind();
ofPtr<ofGLProgrammableRenderer> programmableRenderer = ofGetGLProgrammableRenderer();
if (!programmableRenderer){
#ifndef TARGET_OPENGLES
// this temporarily enables alpha testing,
// which discards pixels unless their alpha is 1.0f
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0);
#endif
}else{
// glPush/PopAttrib is deprecated + we are doing the alpha test through a shader
programmableRenderer->setAlphaBitmapText(true);
}
charMesh.draw();
if (!programmableRenderer){
#ifndef TARGET_OPENGLES
glPopAttrib();
#endif
}else{
programmableRenderer->setAlphaBitmapText(false);
}
bitmappedFontTexture.unbind();
}
}
示例10: updateMesh
void updateMesh(ofMesh& mesh)
{
float t = ofGetElapsedTimef();
ofVec3f axis;
axis.x = ofSignedNoise(1, 0, 0, t);
axis.y = ofSignedNoise(0, 1, 0, t);
axis.z = ofSignedNoise(0, 0, 1, t);
axis.normalize();
vector<ofVec3f>& verts = mesh.getVertices();
vector<ofVec3f>& norms = mesh.getNormals();
for (int i = 0; i < verts.size(); i++)
{
ofVec3f& v = verts[i];
ofVec3f& n = norms[i];
ofVec3f vv = v;
float r = vv.y * fmodf(t, 10) * 0.1;
vv.rotate(r, axis);
n.rotate(r, axis);
v = vv;
}
}
示例11: updateMesh
//--------------------------------------------------------------
void ofxBulletSoftTriMesh::updateMesh( ofMesh& aMesh ) {
int totalNodes = getNumNodes();
auto& tverts = aMesh.getVertices();
if( _cachedMesh.getMode() == OF_PRIMITIVE_TRIANGLES ) {
if( tverts.size() != totalNodes ) {
tverts.resize( totalNodes );
}
auto& tnormals = aMesh.getNormals();
if( aMesh.getNumNormals() != totalNodes ) {
tnormals.resize( totalNodes );
}
for( int i = 0; i < totalNodes; i++ ) {
tverts[i].x = _softBody->m_nodes[i].m_x.x();
tverts[i].y = _softBody->m_nodes[i].m_x.y();
tverts[i].z = _softBody->m_nodes[i].m_x.z();
tnormals[i].x = _softBody->m_nodes[i].m_n.x();
tnormals[i].y = _softBody->m_nodes[i].m_n.y();
tnormals[i].z = _softBody->m_nodes[i].m_n.z();
}
}
_lastMeshUpdateFrame = ofGetFrameNum();
}
示例12: 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();
}
}
示例13: normalizeMesh
// this is important for avoiding slightl discrepencies when the mesh is
// projected, or processed by GL transforms vs OF transforms
void testApp::normalizeMesh(ofMesh& mesh) {
vector<ofVec3f>& vertices = mesh.getVertices();
for(int i = 0; i < vertices.size(); i++) {
vertices[i] *= normalizedMeshScale / normalizedWidth;
vertices[i] += ofVec2f(normalizedWidth, normalizedHeight) / 2.;
vertices[i].z = 0;
}
}
示例14: 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);
}
示例15: 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;
}