@@ -47,7 +47,7 @@ static void addUnique(std::vector<vertex> &lv, Vector &p, Vector &n) {
4747};
4848
4949// Make a new point - type doesn't matter since we will make a copy later
50- static hEntity newPoint (EntityList *el, int id, Vector p) {
50+ static hEntity newPoint (EntityList *el, int * id, Vector p) {
5151 Entity en = {};
5252 en.type = Entity::Type::POINT_N_COPY;
5353 en.extraPoints = 0 ;
@@ -59,20 +59,43 @@ static hEntity newPoint(EntityList *el, int id, Vector p) {
5959 en.actVisible = true ;
6060 en.forceHidden = false ;
6161
62- en.h .v = id + en.group .v *65536 ;
62+ en.h .v = *id + en.group .v *65536 ;
63+ *id = *id+1 ;
6364 el->Add (&en);
6465 return en.h ;
6566}
6667
6768// check if a vertex is unique and add it via newPoint if it is.
6869static void addVertex (EntityList *el, Vector v) {
6970 if (el->n < 15000 ) {
70- int id = el->n + 2 ;
71- newPoint (el, id, v);
71+ int id = el->n ;
72+ newPoint (el, & id, v);
7273 }
7374}
7475
75- static hEntity newLine (EntityList *el, int id, hEntity p0, hEntity p1) {
76+ static hEntity newNormal (EntityList *el, int *id, Quaternion normal, hEntity p) {
77+ // normals have parameters, but we don't need them to make a NORMAL_N_COPY from this
78+ Entity en = {};
79+ en.type = Entity::Type::NORMAL_N_COPY;
80+ en.extraPoints = 0 ;
81+ en.timesApplied = 0 ;
82+ en.group .v = 472 ;
83+ en.actNormal = normal;
84+ en.construction = false ;
85+ en.style .v = Style::NORMALS;
86+ // to be visible we need to add a point.
87+ // en.point[0] = newPoint(el, id, Vector::From(0,0,0));
88+ en.point [0 ] = p;
89+ en.actVisible = true ;
90+ en.forceHidden = false ;
91+
92+ *id = *id+1 ;
93+ en.h .v = *id + en.group .v *65536 ;
94+ el->Add (&en);
95+ return en.h ;
96+ }
97+
98+ static hEntity newLine (EntityList *el, int *id, hEntity p0, hEntity p1) {
7699 Entity en = {};
77100 en.type = Entity::Type::LINE_SEGMENT;
78101 en.point [0 ] = p0;
@@ -85,7 +108,8 @@ static hEntity newLine(EntityList *el, int id, hEntity p0, hEntity p1) {
85108 en.actVisible = true ;
86109 en.forceHidden = false ;
87110
88- en.h .v = id + en.group .v *65536 ;
111+ en.h .v = *id + en.group .v *65536 ;
112+ *id = *id + 1 ;
89113 el->Add (&en);
90114 return en.h ;
91115}
@@ -115,9 +139,6 @@ bool LinkStl(const Platform::Path &filename, EntityList *el, SMesh *m, SShell *s
115139 float x,y,z;
116140 float xn,yn,zn;
117141
118- // add the STL origin as an entity
119- addVertex (el, Vector::From (0.0 , 0.0 , 0.0 ));
120-
121142 std::vector<vertex> verts = {};
122143
123144 for (uint32_t i = 0 ; i<n; i++) {
@@ -173,6 +194,14 @@ bool LinkStl(const Platform::Path &filename, EntityList *el, SMesh *m, SShell *s
173194 }
174195 dbp (" %d vertices" , verts.size ());
175196
197+ int id = 1 ;
198+
199+ // add the STL origin and normals
200+ hEntity origin = newPoint (el, &id, Vector::From (0.0 , 0.0 , 0.0 ));
201+ newNormal (el, &id, Quaternion::From (Vector::From (1 ,0 ,0 ),Vector::From (0 ,1 ,0 )), origin);
202+ newNormal (el, &id, Quaternion::From (Vector::From (0 ,1 ,0 ),Vector::From (0 ,0 ,1 )), origin);
203+ newNormal (el, &id, Quaternion::From (Vector::From (0 ,0 ,1 ),Vector::From (1 ,0 ,0 )), origin);
204+
176205 BBox box = {};
177206 box.minp = verts[0 ].p ;
178207 box.maxp = verts[0 ].p ;
@@ -183,35 +212,34 @@ bool LinkStl(const Platform::Path &filename, EntityList *el, SMesh *m, SShell *s
183212 }
184213
185214 hEntity p[8 ];
186- int id = el->n +2 ;
187- p[0 ] = newPoint (el, id++, Vector::From (box.minp .x , box.minp .y , box.minp .z ));
188- p[1 ] = newPoint (el, id++, Vector::From (box.maxp .x , box.minp .y , box.minp .z ));
189- p[2 ] = newPoint (el, id++, Vector::From (box.minp .x , box.maxp .y , box.minp .z ));
190- p[3 ] = newPoint (el, id++, Vector::From (box.maxp .x , box.maxp .y , box.minp .z ));
191- p[4 ] = newPoint (el, id++, Vector::From (box.minp .x , box.minp .y , box.maxp .z ));
192- p[5 ] = newPoint (el, id++, Vector::From (box.maxp .x , box.minp .y , box.maxp .z ));
193- p[6 ] = newPoint (el, id++, Vector::From (box.minp .x , box.maxp .y , box.maxp .z ));
194- p[7 ] = newPoint (el, id++, Vector::From (box.maxp .x , box.maxp .y , box.maxp .z ));
195-
196- newLine (el, id++, p[0 ], p[1 ]);
197- newLine (el, id++, p[0 ], p[2 ]);
198- newLine (el, id++, p[3 ], p[1 ]);
199- newLine (el, id++, p[3 ], p[2 ]);
200-
201- newLine (el, id++, p[4 ], p[5 ]);
202- newLine (el, id++, p[4 ], p[6 ]);
203- newLine (el, id++, p[7 ], p[5 ]);
204- newLine (el, id++, p[7 ], p[6 ]);
205-
206- newLine (el, id++, p[0 ], p[4 ]);
207- newLine (el, id++, p[1 ], p[5 ]);
208- newLine (el, id++, p[2 ], p[6 ]);
209- newLine (el, id++, p[3 ], p[7 ]);
215+ p[0 ] = newPoint (el, &id, Vector::From (box.minp .x , box.minp .y , box.minp .z ));
216+ p[1 ] = newPoint (el, &id, Vector::From (box.maxp .x , box.minp .y , box.minp .z ));
217+ p[2 ] = newPoint (el, &id, Vector::From (box.minp .x , box.maxp .y , box.minp .z ));
218+ p[3 ] = newPoint (el, &id, Vector::From (box.maxp .x , box.maxp .y , box.minp .z ));
219+ p[4 ] = newPoint (el, &id, Vector::From (box.minp .x , box.minp .y , box.maxp .z ));
220+ p[5 ] = newPoint (el, &id, Vector::From (box.maxp .x , box.minp .y , box.maxp .z ));
221+ p[6 ] = newPoint (el, &id, Vector::From (box.minp .x , box.maxp .y , box.maxp .z ));
222+ p[7 ] = newPoint (el, &id, Vector::From (box.maxp .x , box.maxp .y , box.maxp .z ));
223+
224+ newLine (el, &id, p[0 ], p[1 ]);
225+ newLine (el, &id, p[0 ], p[2 ]);
226+ newLine (el, &id, p[3 ], p[1 ]);
227+ newLine (el, &id, p[3 ], p[2 ]);
228+
229+ newLine (el, &id, p[4 ], p[5 ]);
230+ newLine (el, &id, p[4 ], p[6 ]);
231+ newLine (el, &id, p[7 ], p[5 ]);
232+ newLine (el, &id, p[7 ], p[6 ]);
233+
234+ newLine (el, &id, p[0 ], p[4 ]);
235+ newLine (el, &id, p[1 ], p[5 ]);
236+ newLine (el, &id, p[2 ], p[6 ]);
237+ newLine (el, &id, p[3 ], p[7 ]);
210238
211239 for (unsigned int i=0 ; i<verts.size (); i++) {
212240 // create point entities for edge vertexes
213241 if (isEdgeVertex (verts[i])) {
214- addVertex (el, verts[i].p );
242+ addVertex (el, verts[i].p );
215243 }
216244 }
217245
0 commit comments