Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gl-mesh3d hover of mesh3d traces with face color and face intensity #21

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function SimplicialMesh(gl
this.contourColor = [0,0,0]
this.contourEnable = true

this.pickVertex = true;
this.pickId = 1
this.bounds = [
[ Infinity, Infinity, Infinity],
Expand Down Expand Up @@ -186,21 +187,6 @@ function genColormap(param, opacityscale) {
return ndarray(result, [256,256,4], [4,0,1])
}

function unpackIntensity(cells, numVerts, cellIntensity) {
var result = new Array(numVerts)
for(var i=0; i<numVerts; ++i) {
result[i] = 0
}
var numCells = cells.length
for(var i=0; i<numCells; ++i) {
var c = cells[i]
for(var j=0; j<c.length; ++j) {
result[c[j]] = cellIntensity[i]
}
}
return result
}

function takeZComponent(array) {
var n = array.length
var result = new Array(n)
Expand Down Expand Up @@ -391,11 +377,13 @@ proto.update = function(params) {
if(vertexIntensity) {
this.intensity = vertexIntensity
} else if(cellIntensity) {
this.intensity = unpackIntensity(cells, positions.length, cellIntensity)
this.intensity = cellIntensity
} else {
this.intensity = takeZComponent(positions)
}

this.pickVertex = !(cellIntensity || cellColors)

//Point size
var pointSizes = params.pointSizes
var meshPointSize = params.pointSize || 1.0
Expand Down Expand Up @@ -837,12 +825,34 @@ proto.pick = function(pickData) {
simplex[i] = positions[cell[i]]
}

var x = pickData.coord[0] * this.pixelRatio
var y = pickData.coord[1] * this.pixelRatio
var x = pickData.coord[0];
var y = pickData.coord[1];

if(!this.pickVertex) {
var A = this.positions[cell[0]];
var B = this.positions[cell[1]];
var C = this.positions[cell[2]];

var dataCoordinate = [
(A[0] + B[0] + C[0]) / 3,
(A[1] + B[1] + C[1]) / 3,
(A[2] + B[2] + C[2]) / 3
]

return {
_cellCenter : true,
position: [x, y],
index: cellId,
cell: cell,
cellId: cellId,
intensity: this.intensity[cellId],
dataCoordinate: dataCoordinate
}
}

var data = closestPoint(
simplex,
[x, this._resolution[1] - y],
[x * this.pixelRatio, this._resolution[1] - y * this.pixelRatio],
this._model,
this._view,
this._projection,
Expand Down