mirror of https://github.com/vitalif/openscad
Clifford Wolf:
Sphere bugfix and OpenCSG progress git-svn-id: http://svn.clifford.at/openscad/trunk@23 b57f626f-c46c-0410-a088-ec61d464b74cstl_dim
parent
a05c91bcec
commit
cdc62b4f28
|
@ -78,5 +78,7 @@ module test005()
|
|||
|
||||
// test005();
|
||||
|
||||
$fs_preview = 1;
|
||||
sphere(5);
|
||||
difference() {
|
||||
cube(8, center = true);
|
||||
sphere(5);
|
||||
}
|
||||
|
|
58
glview.cc
58
glview.cc
|
@ -47,6 +47,64 @@ void GLView::initializeGL()
|
|||
glDepthRange(-FAR_FAR_AWAY, +FAR_FAR_AWAY);
|
||||
|
||||
glClearColor(1.0, 1.0, 0.9, 0.0);
|
||||
|
||||
#if 0
|
||||
char *vs_source =
|
||||
"attribute float e1, e2, e3;\n"
|
||||
"varying float ve1, ve2, ve3;\n"
|
||||
"void main() {\n"
|
||||
" gl_FrontColor = gl_Color;\n"
|
||||
" gl_Position = ftransform();\n"
|
||||
" ve1 = e1; ve2 = e2; ve3 = e3;\n"
|
||||
"}\n";
|
||||
|
||||
char *fs_source =
|
||||
"#extension GL_EXT_gpu_shader4 : enable\n"
|
||||
"varying float ve1, ve2, ve3;\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n"
|
||||
" if (ve1 > 0.9 || ve2 > 0.9 || ve3 > 0.9)\n"
|
||||
" gl_FragColor = vec4(0.0,1.0,0.0,1.0);\n"
|
||||
" gl_FragColor = gl_FrontColor;\n"
|
||||
"}\n";
|
||||
|
||||
GLuint edgeshader_prog = glCreateProgram();
|
||||
|
||||
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vs, 1, (const GLchar**)&vs_source, NULL);
|
||||
glCompileShader(vs);
|
||||
glAttachShader(edgeshader_prog, vs);
|
||||
|
||||
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fs, 1, (const GLchar**)&fs_source, NULL);
|
||||
glCompileShader(fs);
|
||||
glAttachShader(edgeshader_prog, fs);
|
||||
|
||||
glLinkProgram(edgeshader_prog);
|
||||
|
||||
GLint status;
|
||||
glGetProgramiv(edgeshader_prog, GL_LINK_STATUS, &status);
|
||||
if (status == GL_FALSE) {
|
||||
int loglen;
|
||||
char logbuffer[1000];
|
||||
glGetProgramInfoLog(edgeshader_prog, sizeof(logbuffer), &loglen, logbuffer);
|
||||
fprintf(stderr, "OpenGL Program Linker Error:\n%.*s", loglen, logbuffer);
|
||||
} else {
|
||||
int loglen;
|
||||
char logbuffer[1000];
|
||||
glGetProgramInfoLog(edgeshader_prog, sizeof(logbuffer), &loglen, logbuffer);
|
||||
if (loglen > 0) {
|
||||
fprintf(stderr, "OpenGL Program Link OK:\n%.*s", loglen, logbuffer);
|
||||
}
|
||||
glValidateProgram(edgeshader_prog);
|
||||
glGetProgramInfoLog(edgeshader_prog, sizeof(logbuffer), &loglen, logbuffer);
|
||||
if (loglen > 0) {
|
||||
fprintf(stderr, "OpenGL Program Validation results:\n%.*s", loglen, logbuffer);
|
||||
}
|
||||
}
|
||||
|
||||
glUseProgram(edgeshader_prog);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GLView::resizeGL(int w, int h)
|
||||
|
|
96
mainwin.cc
96
mainwin.cc
|
@ -397,19 +397,15 @@ void MainWindow::viewModeActionsUncheck()
|
|||
|
||||
#ifdef ENABLE_OPENCSG
|
||||
|
||||
#include <GL/glut.h>
|
||||
|
||||
class DLPrim : public OpenCSG::Primitive
|
||||
class OpenCSGPrim : public OpenCSG::Primitive
|
||||
{
|
||||
public:
|
||||
DLPrim(OpenCSG::Operation operation, unsigned int convexity) :
|
||||
OpenCSG::Primitive(operation, convexity), id(0), color(0) { }
|
||||
OpenCSGPrim(OpenCSG::Operation operation, unsigned int convexity) :
|
||||
OpenCSG::Primitive(operation, convexity) { }
|
||||
PolySet *p;
|
||||
virtual void render() {
|
||||
if (id)
|
||||
glCallList(id);
|
||||
p->render_surface(PolySet::COLOR_NONE);
|
||||
}
|
||||
unsigned int id;
|
||||
unsigned int color;
|
||||
};
|
||||
|
||||
static void renderGLviaOpenCSG(void *vp)
|
||||
|
@ -421,24 +417,9 @@ static void renderGLviaOpenCSG(void *vp)
|
|||
glewInit();
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
|
||||
GLfloat light_position[] = {-0.3, -1.0, 0.3, 0.0};
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
if (m->root_chain) {
|
||||
std::vector<OpenCSG::Primitive*> primitives;
|
||||
int j = 0;
|
||||
for (int i = 0;; i++)
|
||||
{
|
||||
bool last = i == m->root_chain->polysets.size();
|
||||
|
@ -447,15 +428,17 @@ static void renderGLviaOpenCSG(void *vp)
|
|||
{
|
||||
OpenCSG::render(primitives, OpenCSG::Goldfeather, OpenCSG::NoDepthComplexitySampling);
|
||||
glDepthFunc(GL_EQUAL);
|
||||
for (unsigned int j = 0; j < primitives.size(); j++) {
|
||||
DLPrim *p = (DLPrim*)primitives[j];
|
||||
if (p->color)
|
||||
glColor3f(0.0, 0.8, 0);
|
||||
else
|
||||
glColor3f(0.8, 0, 0);
|
||||
glCallList(p->id);
|
||||
glDeleteLists(p->id, 1);
|
||||
delete p;
|
||||
for (; j < i; j++) {
|
||||
if (m->root_chain->types[j] == CSGTerm::DIFFERENCE) {
|
||||
m->root_chain->polysets[j]->render_surface(PolySet::COLOR_CUTOUT);
|
||||
m->root_chain->polysets[j]->render_edges(PolySet::COLOR_CUTOUT);
|
||||
} else {
|
||||
m->root_chain->polysets[j]->render_surface(PolySet::COLOR_MATERIAL);
|
||||
m->root_chain->polysets[j]->render_edges(PolySet::COLOR_MATERIAL);
|
||||
}
|
||||
}
|
||||
for (unsigned int k = 0; k < primitives.size(); k++) {
|
||||
delete primitives[k];
|
||||
}
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
|
@ -465,50 +448,11 @@ static void renderGLviaOpenCSG(void *vp)
|
|||
if (last)
|
||||
break;
|
||||
|
||||
|
||||
DLPrim *prim = new DLPrim(m->root_chain->types[i] == CSGTerm::DIFFERENCE ? OpenCSG::Subtraction : OpenCSG::Intersection, 1);
|
||||
|
||||
prim->id = glGenLists(1);
|
||||
prim->color = m->root_chain->types[i] == CSGTerm::DIFFERENCE ? 1 : 0;
|
||||
glNewList(prim->id, GL_COMPILE);
|
||||
m->root_chain->polysets[i]->render_surface(PolySet::COLOR_NONE);
|
||||
glEndList();
|
||||
|
||||
OpenCSGPrim *prim = new OpenCSGPrim(m->root_chain->types[i] == CSGTerm::DIFFERENCE ?
|
||||
OpenCSG::Subtraction : OpenCSG::Intersection, 1);
|
||||
prim->p = m->root_chain->polysets[i];
|
||||
primitives.push_back(prim);
|
||||
}
|
||||
} else {
|
||||
DLPrim *box = new DLPrim(OpenCSG::Intersection, 1);
|
||||
box->id = glGenLists(1);
|
||||
glNewList(box->id, GL_COMPILE);
|
||||
glutSolidCube(1.8);
|
||||
glEndList();
|
||||
|
||||
DLPrim *sphere = new DLPrim(OpenCSG::Subtraction, 1);
|
||||
sphere->id = glGenLists(1);
|
||||
sphere->color = 1;
|
||||
glNewList(sphere->id, GL_COMPILE);
|
||||
glutSolidSphere(1.2, 20, 20);
|
||||
glEndList();
|
||||
|
||||
std::vector<OpenCSG::Primitive*> primitives;
|
||||
|
||||
primitives.push_back(box);
|
||||
primitives.push_back(sphere);
|
||||
|
||||
OpenCSG::render(primitives, OpenCSG::Goldfeather, OpenCSG::NoDepthComplexitySampling);
|
||||
|
||||
glDepthFunc(GL_EQUAL);
|
||||
for (unsigned int i = 0; i < primitives.size(); i++) {
|
||||
DLPrim *p = (DLPrim*)primitives[i];
|
||||
if (p->color)
|
||||
glColor3f(0.0, 0.8, 0);
|
||||
else
|
||||
glColor3f(0.8, 0, 0);
|
||||
glCallList(p->id);
|
||||
glDeleteLists(p->id, 1);
|
||||
delete primitives[i];
|
||||
}
|
||||
glDepthFunc(GL_LESS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ DEFINES += "ENABLE_CGAL=1"
|
|||
LIBS += -lCGAL -lmpfr
|
||||
|
||||
DEFINES += "ENABLE_OPENCSG=1"
|
||||
LIBS += -lopencsg -lGLEW -lglut
|
||||
LIBS += -lopencsg -lGLEW
|
||||
|
||||
LEXSOURCES += lexer.l
|
||||
YACCSOURCES += parser.y
|
||||
|
|
12
primitive.cc
12
primitive.cc
|
@ -141,7 +141,7 @@ void register_builtin_primitive()
|
|||
|
||||
int get_fragments_from_r(double r, double fs, double fa)
|
||||
{
|
||||
return ceil(fmax(fmin(360.0 / fa, r*M_PI / fs), 5));
|
||||
return (int)ceil(fmax(fmin(360.0 / fa, r*M_PI / fs), 5));
|
||||
}
|
||||
|
||||
PolySet *PrimitiveNode::render_polyset(render_mode_e mode) const
|
||||
|
@ -234,7 +234,7 @@ PolySet *PrimitiveNode::render_polyset(render_mode_e mode) const
|
|||
|
||||
p->append_poly();
|
||||
for (int i = 0; i < ring[0].fragments; i++)
|
||||
p->insert_vertex(ring[0].points[i].x, ring[0].points[i].y, ring[0].z);
|
||||
p->append_vertex(ring[0].points[i].x, ring[0].points[i].y, ring[0].z);
|
||||
|
||||
for (int i = 0; i < rings-1; i++) {
|
||||
ring_s *r1 = &ring[i];
|
||||
|
@ -252,9 +252,9 @@ PolySet *PrimitiveNode::render_polyset(render_mode_e mode) const
|
|||
sphere_next_r1:
|
||||
p->append_poly();
|
||||
int r1j = (r1i+1) % r1->fragments;
|
||||
p->append_vertex(r1->points[r1i].x, r1->points[r1i].y, r1->z);
|
||||
p->append_vertex(r1->points[r1j].x, r1->points[r1j].y, r1->z);
|
||||
p->append_vertex(r2->points[r2i % r2->fragments].x, r2->points[r2i % r2->fragments].y, r2->z);
|
||||
p->insert_vertex(r1->points[r1i].x, r1->points[r1i].y, r1->z);
|
||||
p->insert_vertex(r1->points[r1j].x, r1->points[r1j].y, r1->z);
|
||||
p->insert_vertex(r2->points[r2i % r2->fragments].x, r2->points[r2i % r2->fragments].y, r2->z);
|
||||
r1i++;
|
||||
} else {
|
||||
sphere_next_r2:
|
||||
|
@ -270,7 +270,7 @@ sphere_next_r2:
|
|||
|
||||
p->append_poly();
|
||||
for (int i = 0; i < ring[rings-1].fragments; i++)
|
||||
p->append_vertex(ring[rings-1].points[i].x, ring[rings-1].points[i].y, ring[rings-1].z);
|
||||
p->insert_vertex(ring[rings-1].points[i].x, ring[rings-1].points[i].y, ring[rings-1].z);
|
||||
}
|
||||
|
||||
if (type == CYLINDER && h > 0 && r1 >=0 && r2 >= 0 && (r1 > 0 || r2 > 0))
|
||||
|
|
Loading…
Reference in New Issue