diff --git a/src/importmesh.cpp b/src/importmesh.cpp index 4b7e343a..7b5bf438 100644 --- a/src/importmesh.cpp +++ b/src/importmesh.cpp @@ -47,7 +47,7 @@ static void addUnique(std::vector &lv, Vector &p, Vector &n) { }; // Make a new point - type doesn't matter since we will make a copy later -static hEntity newPoint(EntityList *el, int id, Vector p) { +static hEntity newPoint(EntityList *el, int *id, Vector p) { Entity en = {}; en.type = Entity::Type::POINT_N_COPY; en.extraPoints = 0; @@ -59,7 +59,8 @@ static hEntity newPoint(EntityList *el, int id, Vector p) { en.actVisible = true; en.forceHidden = false; - en.h.v = id + en.group.v*65536; + en.h.v = *id + en.group.v*65536; + *id = *id+1; el->Add(&en); return en.h; } @@ -67,12 +68,34 @@ static hEntity newPoint(EntityList *el, int id, Vector p) { // check if a vertex is unique and add it via newPoint if it is. static void addVertex(EntityList *el, Vector v) { if(el->n < 15000) { - int id = el->n+2; - newPoint(el, id, v); + int id = el->n; + newPoint(el, &id, v); } } -static hEntity newLine(EntityList *el, int id, hEntity p0, hEntity p1) { +static hEntity newNormal(EntityList *el, int *id, Quaternion normal, hEntity p) { + // normals have parameters, but we don't need them to make a NORMAL_N_COPY from this + Entity en = {}; + en.type = Entity::Type::NORMAL_N_COPY; + en.extraPoints = 0; + en.timesApplied = 0; + en.group.v = 472; + en.actNormal = normal; + en.construction = false; + en.style.v = Style::NORMALS; + // to be visible we need to add a point. +// en.point[0] = newPoint(el, id, Vector::From(0,0,0)); + en.point[0] = p; + en.actVisible = true; + en.forceHidden = false; + + *id = *id+1; + en.h.v = *id + en.group.v*65536; + el->Add(&en); + return en.h; +} + +static hEntity newLine(EntityList *el, int *id, hEntity p0, hEntity p1) { Entity en = {}; en.type = Entity::Type::LINE_SEGMENT; en.point[0] = p0; @@ -85,7 +108,8 @@ static hEntity newLine(EntityList *el, int id, hEntity p0, hEntity p1) { en.actVisible = true; en.forceHidden = false; - en.h.v = id + en.group.v*65536; + en.h.v = *id + en.group.v*65536; + *id = *id + 1; el->Add(&en); return en.h; } @@ -115,9 +139,6 @@ bool LinkStl(const Platform::Path &filename, EntityList *el, SMesh *m, SShell *s float x,y,z; float xn,yn,zn; - //add the STL origin as an entity - addVertex(el, Vector::From(0.0, 0.0, 0.0)); - std::vector verts = {}; for(uint32_t i = 0; in+2; - p[0] = newPoint(el, id++, Vector::From(box.minp.x, box.minp.y, box.minp.z)); - p[1] = newPoint(el, id++, Vector::From(box.maxp.x, box.minp.y, box.minp.z)); - p[2] = newPoint(el, id++, Vector::From(box.minp.x, box.maxp.y, box.minp.z)); - p[3] = newPoint(el, id++, Vector::From(box.maxp.x, box.maxp.y, box.minp.z)); - p[4] = newPoint(el, id++, Vector::From(box.minp.x, box.minp.y, box.maxp.z)); - p[5] = newPoint(el, id++, Vector::From(box.maxp.x, box.minp.y, box.maxp.z)); - p[6] = newPoint(el, id++, Vector::From(box.minp.x, box.maxp.y, box.maxp.z)); - p[7] = newPoint(el, id++, Vector::From(box.maxp.x, box.maxp.y, box.maxp.z)); + p[0] = newPoint(el, &id, Vector::From(box.minp.x, box.minp.y, box.minp.z)); + p[1] = newPoint(el, &id, Vector::From(box.maxp.x, box.minp.y, box.minp.z)); + p[2] = newPoint(el, &id, Vector::From(box.minp.x, box.maxp.y, box.minp.z)); + p[3] = newPoint(el, &id, Vector::From(box.maxp.x, box.maxp.y, box.minp.z)); + p[4] = newPoint(el, &id, Vector::From(box.minp.x, box.minp.y, box.maxp.z)); + p[5] = newPoint(el, &id, Vector::From(box.maxp.x, box.minp.y, box.maxp.z)); + p[6] = newPoint(el, &id, Vector::From(box.minp.x, box.maxp.y, box.maxp.z)); + p[7] = newPoint(el, &id, Vector::From(box.maxp.x, box.maxp.y, box.maxp.z)); - newLine(el, id++, p[0], p[1]); - newLine(el, id++, p[0], p[2]); - newLine(el, id++, p[3], p[1]); - newLine(el, id++, p[3], p[2]); + newLine(el, &id, p[0], p[1]); + newLine(el, &id, p[0], p[2]); + newLine(el, &id, p[3], p[1]); + newLine(el, &id, p[3], p[2]); - newLine(el, id++, p[4], p[5]); - newLine(el, id++, p[4], p[6]); - newLine(el, id++, p[7], p[5]); - newLine(el, id++, p[7], p[6]); + newLine(el, &id, p[4], p[5]); + newLine(el, &id, p[4], p[6]); + newLine(el, &id, p[7], p[5]); + newLine(el, &id, p[7], p[6]); - newLine(el, id++, p[0], p[4]); - newLine(el, id++, p[1], p[5]); - newLine(el, id++, p[2], p[6]); - newLine(el, id++, p[3], p[7]); + newLine(el, &id, p[0], p[4]); + newLine(el, &id, p[1], p[5]); + newLine(el, &id, p[2], p[6]); + newLine(el, &id, p[3], p[7]); for(unsigned int i=0; i