本文整理汇总了C++中ofMesh::getColors方法的典型用法代码示例。如果您正苦于以下问题:C++ ofMesh::getColors方法的具体用法?C++ ofMesh::getColors怎么用?C++ ofMesh::getColors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofMesh
的用法示例。
在下文中一共展示了ofMesh::getColors方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: vertexColorToFaceColor
void vertexColorToFaceColor(ofMesh& mesh)
{
vector<ofFloatColor> face_color;
vector<ofFloatColor> &color = mesh.getColors();
for (int i = 0; i < color.size(); i += 3)
{
ofFloatColor c0 = color[i + 0];
ofFloatColor c1 = color[i + 1];
ofFloatColor c2 = color[i + 2];
float r = (c0.r + c1.r + c2.r) / 3;
float g = (c0.g + c1.g + c2.g) / 3;
float b = (c0.b + c1.b + c2.b) / 3;
ofFloatColor c(r, g, b, 1);
face_color.push_back(c);
face_color.push_back(c);
face_color.push_back(c);
}
mesh.getColors() = face_color;
}
示例3: fromMesh
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();
}
}
示例4: toMesh
void ofxMesh::toMesh(ofMesh & mesh){
mesh.clear();
if (hasVertices()) {
mesh.getVertices()=getVertices();
}
if (hasColors()) {
mesh.getColors()=getColors();
}
if (hasNormals()) {
mesh.getNormals()=getNormals();
}
if (hasTexCoords()) {
mesh.getTexCoords()=getTexCoords();
}
if (hasIndices()) {
mesh.getIndices()=getIndices();
}
}
示例5: toGlm
glmMesh toGlm(const ofMesh &_mesh){
glmMesh mesh;
for (auto &it : _mesh.getColors()) {
mesh.addColor(toGlm(it));
}
for (auto &it : _mesh.getVertices()) {
mesh.addVertex(toGlm(it));
}
for (auto &it : _mesh.getNormals()) {
mesh.addNormal(toGlm(it));
}
for (auto &it : _mesh.getTexCoords()) {
mesh.addTexCoord(toGlm(it));
}
for (auto &it : _mesh.getIndices()) {
mesh.addIndex(toGlm(it));
}
GLenum drawMode = ofGetGLPrimitiveMode(_mesh.getMode());
if (drawMode == GL_POINTS) {
mesh.setDrawMode(POINTS);
} else if (drawMode == GL_LINES){
mesh.setDrawMode(LINES);
} else if (drawMode == GL_LINE_STRIP){
mesh.setDrawMode(LINE_STRIP);
} else if (drawMode == GL_TRIANGLES){
mesh.setDrawMode(TRIANGLES);
} else if (drawMode == GL_TRIANGLE_STRIP){
mesh.setDrawMode(TRIANGLE_STRIP);
}
return mesh;
}
示例6: faceColorToTexture
void faceColorToTexture(ofMesh& mesh, ofImage& image)
{
vector<ofFloatColor> &color = mesh.getColors();
int num_face = color.size() / 3;
int tex_size = ofNextPow2(ceil(sqrt(num_face)));
bool arb = ofGetUsingArbTex();
ofDisableArbTex();
image.allocate(tex_size, tex_size, OF_IMAGE_COLOR);
if (arb) ofEnableArbTex();
mesh.clearTexCoords();
image.getPixelsRef().set(0);
float texel_size = (1. / image.getWidth()) * 0.5;
for (int i = 0; i < num_face; i++)
{
int u = (i % tex_size);
int v = (i / tex_size);
ofColor c = color[i * 3];
image.setColor(u, v, c);
float uu = (float)u / image.getWidth() + texel_size;
float vv = (float)v / image.getHeight() + texel_size;
mesh.addTexCoord(ofVec2f(uu, vv));
mesh.addTexCoord(ofVec2f(uu, vv));
mesh.addTexCoord(ofVec2f(uu, vv));
}
image.update();
mesh.clearColors();
}
示例7: save
//--------------------------------------------------------------
void save(const string& path, const ofMesh& mesh)
{
ofFile file(path, ofFile::WriteOnly, true);
int numVerts = mesh.getNumVertices();
file.write((char *)(&numVerts), sizeof(int));
if (numVerts > 0) {
file.write((char *)(&(mesh.getVertices())[0]), sizeof(ofPoint) * numVerts);
}
int numNormals = mesh.getNumNormals();
file.write((char *)(&numNormals), sizeof(int));
if (numNormals > 0) {
file.write((char *)(&(mesh.getNormals())[0]), sizeof(ofPoint) * numNormals);
}
int numTexCoords = mesh.getNumTexCoords();
file.write((char *)(&numTexCoords), sizeof(int));
if (numTexCoords > 0) {
file.write((char *)(&(mesh.getTexCoords())[0]), sizeof(ofVec2f) * numTexCoords);
}
int numColors = mesh.getNumColors();
file.write((char *)(&numColors), sizeof(int));
if (numColors > 0) {
file.write((char *)(&(mesh.getColors())[0]), sizeof(ofFloatColor) * numColors);
}
int numIndices = mesh.getNumIndices();
file.write((char *)(&numIndices), sizeof(int));
if (numIndices > 0) {
file.write((char *)(&(mesh.getIndices())[0]), sizeof(ofIndexType) * numIndices);
}
file.close();
}