Skip to content

Commit bb21fb1

Browse files
committed
Merge branch 'cnr-isti-vclab-master'
Merge branch
2 parents b41264c + fe7417c commit bb21fb1

23 files changed

Lines changed: 398 additions & 231 deletions

.github/workflows/Linux.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ on:
66
jobs:
77
linux_build:
88
name: Build Nexus (Linux)
9-
runs-on: ubuntu-18.04 #in order to deploy, need to use oldest supported version
9+
runs-on: ubuntu-20.04 #in order to deploy, need to use oldest supported version
1010

1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
1313
with:
1414
submodules: recursive
1515
- name: Install Qt
16-
uses: jurplel/install-qt-action@v2
16+
uses: jurplel/install-qt-action@v3
17+
with:
18+
cache: true
19+
version: '5.15.2'
1720
- name: Install dependencies
1821
run: |
1922
sudo apt-get install -y mesa-common-dev libglu1-mesa-dev libglew-dev

.github/workflows/MacOS.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ jobs:
99
runs-on: macos-latest
1010

1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
1313
with:
1414
submodules: recursive
1515
- name: Install Qt
16-
uses: jurplel/install-qt-action@v2
16+
uses: jurplel/install-qt-action@v3
17+
with:
18+
cache: true
19+
version: '5.15.2'
1720
- name: Install dependencies
1821
run: |
1922
cd ..
@@ -36,7 +39,7 @@ jobs:
3639
rm -r lib
3740
tar -cvzf nxsview-macos.tar.gz *
3841
- name: Upload nxsview Portable
39-
uses: actions/upload-artifact@v2
42+
uses: actions/upload-artifact@v3
4043
with:
4144
name: nxsview_macos_portable
4245
path: install/nxsview-macos.tar.gz

.github/workflows/Windows.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ name: Windows
22

33
on:
44
[push, pull_request]
5-
5+
66
jobs:
77
linux_build:
88
name: Build Nexus (Windows)
99
runs-on: windows-latest
1010

1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
1313
with:
1414
submodules: recursive
1515
- name: Setup MSVC
1616
uses: ilammy/msvc-dev-cmd@v1
1717
- name: Install Qt
18-
uses: jurplel/install-qt-action@v2
18+
uses: jurplel/install-qt-action@v3
19+
with:
20+
cache: true
21+
version: '5.15.2'
1922
- name: Install dependencies
2023
run: |
2124
cd ..
@@ -38,7 +41,7 @@ jobs:
3841
cd ..
3942
mv bin nexus_portable
4043
- name: Uploading Nexus Portable
41-
uses: actions/upload-artifact@v2
44+
uses: actions/upload-artifact@v3
4245
with:
4346
name: nexus_windows_portable
4447
path: install/nexus_portable

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ ACM Trans. on Graphics, vol. 23(3), pp. 796-803, August 2004 (Siggraph '04)
116116
P.Cignoni, F.Ganovelli, E. Gobbetti, F.Marton, F. Ponchio, R. Scopigno
117117
Computer Graphics Forum, 22(3), pp. 505-514, September 2003
118118

119+
### Feedback
120+
121+
For documented and repeatable bugs, feature requests, etc., please use the [GitHub issues](https://github.com/cnr-isti-vclab/nexus/issues).
119122

120123
### Support and thanks
121124

README.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Nexus is a c++/javascript library for creation and visualization of a batched mu
66

77
Contact me @ federico.ponchio@isti.cnr.it
88

9-
See INSTALL.MD for compilation instructions.
9+
See [INSTALL.MD](INSTALL.md) for compilation instructions.
1010

1111
### Main features
1212

@@ -116,6 +116,9 @@ ACM Trans. on Graphics, vol. 23(3), pp. 796-803, August 2004 (Siggraph '04)
116116
P.Cignoni, F.Ganovelli, E. Gobbetti, F.Marton, F. Ponchio, R. Scopigno
117117
Computer Graphics Forum, 22(3), pp. 505-514, September 2003
118118

119+
### Feedback
120+
121+
For documented and repeatable bugs, feature requests, etc., please use the [GitHub issues](https://github.com/cnr-isti-vclab/nexus/issues).
119122

120123
### Support and thanks
121124

html/js/nexus_three.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,44 +249,51 @@ NexusObject.prototype.raycast = function(raycaster, intersects) {
249249
if(!intersect)
250250
return;
251251

252+
let face = {};
252253
if(!nexus.sink || !nexus.basei) {
253254
return;
254255
//no mesh loaded, we can still use the sphere.
255256
intersect.applyMatrix4(this.matrixWorld);
256-
var d = intersect.distanceTo(raycaster.ray.origin);
257+
let d = intersect.distanceTo(raycaster.ray.origin);
257258
if(d < raycaster.near || d > raycaster.far )
258259
distance = d;
259260
} else {
260-
var vert = nexus.basev;
261-
var face = nexus.basei;
261+
let vert = nexus.basev;
262+
let tri = nexus.basei;
262263

263264
let A = new THREE.Vector3(0, 0, 0);
264265
let B = new THREE.Vector3(0, 0, 0);
265266
let C = new THREE.Vector3(0, 0, 0);
266-
for(var j = 0; j < nexus.basei.length; j += 3) {
267-
var a = face[j];
268-
var b = face[j+1];
269-
var c = face[j+2];
267+
for(let j = 0; j < nexus.basei.length; j += 3) {
268+
let a = tri[j];
269+
let b = tri[j+1];
270+
let c = tri[j+2];
270271
A.set(vert[a*3], vert[a*3+1], vert[a*3+2]);
271272
B.set(vert[b*3], vert[b*3+1], vert[b*3+2]);
272273
C.set(vert[c*3], vert[c*3+1], vert[c*3+2]);
273274
//TODO use material to determine if using doubleface or not!
274-
var hit = ray.intersectTriangle( C, B, A, false, point );
275+
let hit = ray.intersectTriangle( C, B, A, false, point );
275276
if(!hit) continue;
276277

278+
277279
//check distances in world space
278280
hit.applyMatrix4(this.matrixWorld);
279-
var d = hit.distanceTo(raycaster.ray.origin);
281+
let d = hit.distanceTo(raycaster.ray.origin);
280282
if(d < raycaster.near || d > raycaster.far ) continue;
281283
if(distance == -1.0 || d < distance) {
282284
distance = d;
283285
intersect = hit.clone();
286+
287+
face = { a: a, b: b, c: c,
288+
normal: new THREE.Vector3(),
289+
};
290+
THREE.Triangle.getNormal( A, B, C, face.normal );
284291
}
285292
}
286293
}
287294

288295
if(distance == -1.0) return;
289-
intersects.push({ distance: distance, point: intersect, object: this} );
296+
intersects.push({ distance: distance, point: intersect, face: face, object: this} );
290297
return;
291298

292299
/* Kept for reference, should we want to implement a raycasting on the higher resolution nodes

html/raycast.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,14 @@
8888

8989
if (guiConfig.visualizePointFromRaycasting) {
9090
if (intersections.length) {
91+
let hit = intersections[0];
9192
raycastingIntersectionSphere.visible = true;
92-
raycastingIntersectionSphere.position.copy(intersections[0].point);
93+
raycastingIntersectionSphere.position.copy(hit.point);
94+
if(hit.face) {
95+
console.log("Face: ", hit.face.a, hit.face.b, hit.face.c);
96+
console.log("Normal: ", hit.face.normal);
97+
//TODO read also UV
98+
}
9399
} else {
94100
raycastingIntersectionSphere.visible = false;
95101
}

src/nxsbuild/nexusbuilder.cpp

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ NexusBuilder::NexusBuilder(Signature &signature): chunks("cache_chunks"), scalin
120120
header.nvert = header.nface = header.n_nodes = header.n_patches = header.n_textures = 0;
121121
}
122122

123-
void NexusBuilder::initAtlas(const std::vector<QImage>& textures) {
123+
void NexusBuilder::initAtlas(std::vector<QImage>& textures) {
124124
if(textures.size()) {
125125
atlas.addTextures(textures);
126126
}
@@ -143,7 +143,6 @@ void NexusBuilder::create(KDTree *tree, Stream *stream, uint top_node_size) {
143143
int level = 0;
144144
int last_top_level_size = 0;
145145
do {
146-
//cout << "Creating level " << level << endl;
147146
tree->clear();
148147
if(level % 2) tree->setAxesDiagonal();
149148
else tree->setAxesOrthogonal();
@@ -207,15 +206,17 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
207206
std::vector<int> vertex_to_box;
208207

209208

209+
//find connected pieces of triangles belonging to the same texture
210+
//iterate over the triangles and connect the vertices.
210211
UnionFind components;
211212
components.init(mesh.vert.size());
212213

213214
for(auto &face: mesh.face) {
214215
int v[3];
215216
for(int i = 0; i < 3; i++) {
216217
v[i] = face.V(i) - &*mesh.vert.begin();
217-
218-
218+
219+
219220
int &t = vertex_to_tex[v[i]];
220221

221222
if(t != -1 && t != face.tex) qDebug() << "Missing vertex replication across seams\n";
@@ -227,17 +228,15 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
227228
}
228229
int n_boxes = components.compact(vertex_to_box);
229230

231+
//assign a texture to each vertex (we already split)
230232
for(auto &face: mesh.face) {
231233
int v[3];
232234
for(int i = 0; i < 3; i++) {
233235
int v = face.V(i) - &*mesh.vert.begin();
234236
vertex_to_tex[v] = face.tex;
235237
}
236-
/* assert(vertex_to_box[v[0]] == vertex_to_box[v[1]]);
237-
assert(vertex_to_box[v[0]] == vertex_to_box[v[2]]);
238-
assert(components.root(v[0]) == components.root(v[2]));
239-
assert(components.root(v[0]) == components.root(v[1])); */
240238
}
239+
241240
//assign all boxes to a tex (and remove boxes where the tex is -1
242241

243242
//compute boxes
@@ -251,13 +250,15 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
251250
vcg::Box2f &box = boxes[b];
252251
box_texture[b] = tex;
253252
auto &t = mesh.vert[i].T().P();
254-
t[0] = fmod(t[0], 1.0);
255-
t[1] = fmod(t[1], 1.0);
256-
// if(isnan(t[0]) || isnan(t[1]) || t[0] < 0 || t[1] < 0 || t[0] > 1 || t[1] > 1)
257-
// cout << "T: " << t[0] << " " << t[1] << endl;
253+
if(t[0] != 1.0)
254+
t[0] = fmod(t[0], 1.0);
255+
if(t[1] != 1.0)
256+
t[1] = fmod(t[1], 1.0);
257+
258258
if(t[0] != 0.0f || t[1] != 0.0f)
259259
box.Add(t);
260260
}
261+
261262
//erase boxes assigned to no texture, and remap vertex_to_box
262263
int count = 0;
263264
std::vector<int> remap(mesh.vert.size(), -1);
@@ -277,9 +278,17 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
277278
std::vector<vcg::Point2i> origins(boxes.size());
278279
for(size_t b = 0; b < boxes.size(); b++) {
279280
auto &box = boxes[b];
281+
if(box.DimX() > 0.9) {
282+
for(auto &face: mesh.face) {
283+
int v[3];
284+
for(int i = 0; i < 3; i++) {
285+
auto v = face.V(i);
286+
int j = (i+1)%3;
287+
}
288+
}
289+
}
280290
int tex = box_texture[b];
281291

282-
//enlarge 1 pixel
283292
float w = atlas.width(tex, level); //img->size().width();
284293
float h = atlas.height(tex, level); //img->size().height();
285294
float px = 1/(float)w;
@@ -299,10 +308,6 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
299308
size[1] = std::min(h, ceil(box.max[1]/py)) - origin[1];
300309
if(size[0] <= 0) size[0] = 1;
301310
if(size[1] <= 0) size[1] = 1;
302-
303-
// cout << "Box: " << box_texture[b] << " [" << box.min[0] << " " << box.min[1] << " ] [ " << box.max[0] << " " << box.max[1] << "]" << std::endl;
304-
// cout << "Size: " << size[0] << " - " << size[1] << endl << endl;
305-
// getchar();
306311
}
307312

308313
//pack boxes;
@@ -342,7 +347,6 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
342347
finalSize[ 1 ] = (int) nextPowerOf2( finalSize[ 1 ] );
343348
}
344349

345-
// std::cout << "Boxes: " << boxes.size() << " Final size: " << finalSize[0] << " " << finalSize[1] << std::endl;
346350
QImage image(finalSize[0], finalSize[1], QImage::Format_RGB32);
347351
image.fill(QColor(127, 127, 127));
348352
//copy boxes using mapping
@@ -361,10 +365,9 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
361365
vcg::Point2i &o = origins[b];
362366
vcg::Point2i m = mapping[b];
363367

364-
//QImageReader &img = textures[box_texture[b]];
365368
int tex = box_texture[b];
366-
float w = atlas.width(tex, level); //img->size().width();
367-
float h = atlas.height(tex, level); //img->size().height();
369+
float w = atlas.width(tex, level);
370+
float h = atlas.height(tex, level);
368371
float px = 1/(float)w;
369372
float py = 1/(float)h;
370373

@@ -404,7 +407,7 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
404407
}
405408
pixelXedge = sqrt(pixelXedge/mesh.face.size()*3);
406409
error = sqrt(error/mesh.face.size()*3);
407-
410+
408411
double areausage = 0.0;
409412
//compute area waste
410413
for(int i = 0; i < mesh.face.size(); i++) {
@@ -416,7 +419,6 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
416419
auto V1 = face.V(1)->T().P();
417420
auto V2 = face.V(2)->T().P();
418421
areausage += (V2 - V0)^(V2 - V1)/2;
419-
420422
}
421423

422424
{
@@ -443,14 +445,14 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
443445
// boxid++;
444446
}
445447

446-
448+
447449
/* painter.setPen(QColor(255,0,255));
448450
for(int i = 0; i < mesh.face.size(); i++) {
449451
auto &face = mesh.face[i];
450452
int b = vertex_to_box[face.V(0) - &(mesh.vert[0])];
451453
vcg::Point2i &o = origins[b];
452454
vcg::Point2i m = mapping[b];
453-
455+
454456
for(int k = 0; k < 3; k++) {
455457
int j = (k==2)?0:k+1;
456458
auto V0 = face.V(k);
@@ -865,7 +867,6 @@ void NexusBuilder::reverseDag() {
865867

866868
void NexusBuilder::save(QString filename) {
867869

868-
//cout << "Saving to file " << qPrintable(filename) << endl;
869870
//cout << "Input squaresize " << sqrt(input_pixels) << " Output size " << sqrt(output_pixels) << "\n";
870871

871872
file.setFileName(filename);
@@ -1102,7 +1103,7 @@ void NexusBuilder::appendBorderVertices(uint32_t origin, uint32_t destination, s
11021103
uint16_t *face = (uint16_t *)(buffer + header.signature.vertex.size()*node.nvert);
11031104

11041105
NodeBox &nodebox = boxes[origin];
1105-
1106+
11061107
vector<bool> border = nodebox.markBorders(node, point, face);
11071108
for(int i = 0; i < node.nvert; i++) {
11081109
if(border[i])
@@ -1168,7 +1169,7 @@ void NexusBuilder::uniformNormals() {
11681169
uint start = 0;
11691170
while(start < vertices.size()) {
11701171
NVertex &v = vertices[start];
1171-
1172+
11721173
uint last = start+1;
11731174
while(last < vertices.size() && vertices[last].point == v.point)
11741175
last++;
@@ -1187,15 +1188,15 @@ void NexusBuilder::uniformNormals() {
11871188

11881189
for(uint k = start; k < last; k++)
11891190
*vertices[k].normal = normals;
1190-
1191+
11911192
} else //just copy from first one (coming from lower level due to sorting
11921193
for(uint k = start; k < last; k++)
11931194
*vertices[k].normal =*v.normal;
1194-
1195+
11951196
start = last;
11961197
}
11971198

1198-
1199+
11991200
/* for(uint k = 0; k < vertices.size(); k++) {
12001201
NVertex &v = vertices[k];
12011202
if(v.point != previous) {

0 commit comments

Comments
 (0)