Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement flatNormals() for polyhedrons and low-poly meshes #5651

Merged
merged 1 commit into from
Jul 4, 2017
Merged

Implement flatNormals() for polyhedrons and low-poly meshes #5651

merged 1 commit into from
Jul 4, 2017

Conversation

hamoid
Copy link
Contributor

@hamoid hamoid commented Jun 8, 2017

Implement mesh.flatNormals(); to give it a flat look.

Works only when mode = OF_PRIMITIVE_TRIANGLES, same as existing smoothNormals() method.

ofLight light;
ofMaterial material;
vector<ofMesh> meshes;

//--------------------------------------------------------------
void ofApp::setup() {
    ofSetBackgroundColor(10, 10, 10);
    ofEnableDepthTest();

    //directional light
    light.setDirectional();
    light.setSpecularColor(ofColor(255));
    light.setDiffuseColor(ofColor(255));
    light.setAmbientColor(ofColor(100));
    light.setOrientation(ofVec3f(0, 180, 0));

    //material
    material.setShininess(120);
    material.setSpecularColor(ofColor(0));
    material.setDiffuseColor(ofColor(200));
    material.setAmbientColor(ofColor(0));

    //mesh
    meshes.push_back(ofMesh::sphere(100, 12, OF_PRIMITIVE_TRIANGLES));
    meshes.push_back(ofMesh::sphere(100, 12, OF_PRIMITIVE_TRIANGLES));
    meshes.push_back(ofMesh::icosphere(100));
    meshes.push_back(ofMesh::icosphere(100));
    meshes.push_back(ofMesh::icosahedron(100));
    meshes.push_back(ofMesh::icosahedron(100));

    meshes[0].flatNormals();
    meshes[2].flatNormals();
    meshes[4].flatNormals();
}

//--------------------------------------------------------------
void ofApp::draw() {
    ofEnableLighting();
    light.enable();
    material.begin();

    for(size_t i = 0; i < meshes.size(); i++) {
        ofPushMatrix();
        ofTranslate(
            ofMap(i / 2, 0, 2, ofGetWidth() * 0.25f, ofGetWidth() * 0.75f),
            ofMap(i % 2, 0, 1, ofGetHeight() * 0.25f, ofGetHeight() * 0.75f)
        );
        ofRotateDeg(ofGetFrameNum(), 1, 1, 1);
        meshes[i].draw();
        ofPopMatrix();
    }

    material.end();
    light.disable();
    ofDisableLighting();
}

2017-06-08-113913_1024x768_scrot

Screenshot taken after applying both this pull request and #5650

@arturoc
Copy link
Member

arturoc commented Jun 8, 2017

thath's great! the name is a little strange though, perhaps something like?

ofMesh::smoothNormals();
ofMesh::flatNormals();

@hamoid
Copy link
Contributor Author

hamoid commented Jun 8, 2017

Yeah I wasn't sure about the name. I'll use flatNormals() if no one complains :)

@hamoid hamoid changed the title Implement noSmoothNormals() for polyhedrons and low-poly meshes Implement flatNormals() for polyhedrons and low-poly meshes Jun 8, 2017
@hamoid
Copy link
Contributor Author

hamoid commented Jun 8, 2017

Ok I renamed noSmoothNormals() to flatNormals() :)

@arturoc arturoc merged commit f369978 into openframeworks:master Jul 4, 2017
@arturoc
Copy link
Member

arturoc commented Jul 4, 2017

thanks!!

@hamoid hamoid deleted the meshNoSmooth branch March 31, 2018 10:17
@artificiel artificiel mentioned this pull request Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants