Broken of3dPrimitive mesh append

Hi,

Messing around with of3dPrimitive and ofMeshes I encountered a strange bug.

It seems that you cannot freely append to a current of3dPrimitive any type of ofMesh, some images to explain…

Appending a box to an of3dPrimitive:

primitive.getMesh().append(ofMesh::box(10,10,10));

Appending a sphere to an of3dPrimitive:

primitive.getMesh().append(ofMesh::sphere(10));

Appending a cone to an of3dPrimitive:

 primitive.getMesh().append(ofMesh::cone(10,10));

There seems to be an issue with the winding of the faces when appending meshes.

Here you have a small test app to try it out:


#pragma once

#include "ofMain.h"
#include "EasyCam.h"

class testApp : public ofBaseApp
{
public:
	testApp();

	void setup();
	void draw();

	ofEasyCam camera;
	ofLight light;
	of3dPrimitive primitive;

};

#include "testApp.h"

testApp::testApp()
{
}

void testApp::setup()
{
	ofEnableDepthTest();
	camera.setDistance(30);

	light.setPointLight();
	light.setGlobalPosition(300,150,200);
	light.enable();

	//comment out appends to test
	primitive.getMesh().append(ofMesh::box(10,10,10));
	primitive.getMesh().append(ofMesh::sphere(10));
	primitive.getMesh().append(ofMesh::cone(10,10));
}

void testApp::draw()
{
	ofClear(0);
	camera.begin();
		primitive.draw();
	camera.end();
}

Never mind!!

Seems that one can solve this quite easily. As I said, the issue happens due to the winding, controlled by ofPrimitiveMode.

Setting the primitive mode to OF_PRIMITIVE_TRIANGLES solves this.

primitive.getMesh().append(ofMesh::box(10,10,10));
primitive.getMesh().append(ofMesh::sphere(10,12,ofPrimitiveMode::OF_PRIMITIVE_TRIANGLES));
primitive.getMesh().append(ofMesh::cone(10,10,12, 6, 2, ofPrimitiveMode::OF_PRIMITIVE_TRIANGLES));

Hope this helps someone out!

3 Likes