cnr-isti-vclab / nexus

Nexus is a c++/javascript library for creation and visualization of a batched multiresolution mesh
GNU General Public License v3.0
216 stars 87 forks source link

nexus js: Fix displaying of textured models #126

Closed asmrcek closed 2 years ago

asmrcek commented 2 years ago

Fixes: #125

Description

This PR fixes displaying of textured models by using correct variables during the initialization of the texture request parameters.

Long story what problem this PR fixes

The requestNodeTexture initializes texture requests in the following way:

// nexus.js, around line 1088

function requestNodeTexture(context, node) {
  // (...)

  var n = node.id;
  var m = node.mesh;

  if(!m.vertex.texCoord) return;

  var tex = m.patches[m.nfirstpatch[n]*3+2];

  // (...)

  if(m.deepzoom) {
        request.url = m.baseurl + tex + '.jpg';
    } else {
        Object.assign(request, {
            url:m.url,
            start:m.noffsets[n], // ❗ THE PROBLEM
            end:m.noffsets[n+1], // ❗ THE PROBLEM
        });
    }

  // (...)
}

This way of initialization isn't correct, because m.noffsets and n are related to nodes, not textures. It seems that the bug was introduced in the commit 5f96f56.

The PR fixes the bug in the following way: