-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #479 from xBimTeam/feature/animated-icons-movement
Added ability to animate icons movements to different locations in the model
- Loading branch information
Showing
13 changed files
with
438 additions
and
9 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>3D Tracking example</title> | ||
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> | ||
|
||
<style> | ||
html, | ||
body { | ||
height: 100%; | ||
padding: 0; | ||
margin: 0; | ||
font-family: Arial, Helvetica, sans-serif; | ||
} | ||
|
||
canvas { | ||
height: 100%; | ||
width: 100%; | ||
display: block; | ||
border: none; | ||
} | ||
|
||
#viewer-container { | ||
flex: 6; | ||
width: 100%; | ||
overflow: hidden; | ||
} | ||
|
||
.flex-container { | ||
display: flex; | ||
flex-direction: column; | ||
height: 100%; | ||
overflow: hidden; | ||
} | ||
|
||
.left-panel { | ||
position: absolute; | ||
top: 40px; | ||
z-index: 1; | ||
padding: 2em; | ||
background-color: white; | ||
box-shadow: 0 0 10px darkgray; | ||
border-radius: 10px; | ||
left: 20px; | ||
width: 500px; | ||
max-width: 500px; | ||
user-select: none; | ||
pointer-events: fill; | ||
} | ||
.left-panel div { | ||
font-weight: 600; | ||
padding-top: 1em; | ||
} | ||
|
||
#gradient{ | ||
margin-top: 10px; | ||
width: 100%; | ||
} | ||
|
||
#gradient-parent{ | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
#channels{ | ||
width: 100%; | ||
height: 20px; | ||
} | ||
|
||
.ranges-class { | ||
display: flex; | ||
justify-content: center; | ||
gap: 10px; | ||
padding: 10px; | ||
} | ||
|
||
.ranges-class div { | ||
width: 160px; | ||
height: 15px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
color: white; | ||
font-size: 12px; | ||
text-align: center; | ||
font-weight: bold; | ||
border-radius: 10px; | ||
padding: 10px; | ||
} | ||
|
||
.clipping-controls{ | ||
margin-bottom: 20px; | ||
} | ||
|
||
</style> | ||
|
||
</head> | ||
<body> | ||
<div class="flex-container"> | ||
<div id="viewer-container"> | ||
<canvas id="viewer"></canvas> | ||
</div> | ||
</div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import { Viewer, Heatmap, InteractiveClippingPlane, ContinuousHeatmapChannel, ValueRange, ValueRangesHeatmapChannel, HeatmapSource, Icons, CameraType, ViewType, ClippingPlane, ProductType, IHeatmapChannel, ChannelType, } from '../..'; | ||
import { Icon } from '../../src/plugins/DataVisualization/Icons/icon'; | ||
import { IconsData } from './icons'; | ||
|
||
const viewer = new Viewer("viewer"); | ||
const heatmap = new Heatmap(); | ||
const icons = new Icons(); | ||
viewer.addPlugin(heatmap); | ||
viewer.addPlugin(icons); | ||
|
||
var plane = new InteractiveClippingPlane(); | ||
viewer.addPlugin(plane); | ||
|
||
const sourceIcon = new Icon("Digger #1", "Tracking digger location along the bridge", 1, null, IconsData.diggerIcon); | ||
|
||
viewer.on('loaded', args => { | ||
try { | ||
|
||
viewer.camera = CameraType.PERSPECTIVE; | ||
clipModel(); | ||
viewer.resetState(ProductType.IFCSPACE) | ||
viewer.show(ViewType.DEFAULT); | ||
|
||
const wcs = viewer.getCurrentWcs(); | ||
var courses = viewer.getProductsOfType(ProductType.IFCCOURSE, 1); | ||
var centroids = courses.map(id => { | ||
const bb : Float32Array = viewer.getProductBoundingBox(id, 1); | ||
|
||
return [ | ||
bb[0] - wcs[0] + (bb[3] / 2), | ||
bb[1] - wcs[1] + (bb[4] / 2), | ||
bb[2] - wcs[2] + (bb[5] / 2) | ||
]; | ||
}); | ||
centroids = removeDuplicateXYPoints(centroids); | ||
sourceIcon.location = new Float32Array([centroids[0][0], centroids[0][1], centroids[0][2]]) | ||
icons.addIcon(sourceIcon); | ||
|
||
let currentIndex = 0; | ||
let progress = 0; | ||
const speed = 50; | ||
const intervalTime = 2000; // this controls the rate of incoming changes to the digger location | ||
let direction = 1; | ||
|
||
setInterval(function () { | ||
if (centroids.length < 2) return; | ||
let nextIndex = (currentIndex + direction + centroids.length) % centroids.length; | ||
if (progress >= 1) { | ||
progress = 0; | ||
currentIndex = nextIndex; | ||
|
||
if (currentIndex === 0 || currentIndex === centroids.length - 1) { | ||
direction *= -1; | ||
} | ||
|
||
nextIndex = (currentIndex + direction + centroids.length) % centroids.length; | ||
} | ||
const nextCentroid = centroids[nextIndex]; | ||
progress += speed; | ||
icons.moveIconTo(sourceIcon, new Float32Array([nextCentroid[0], nextCentroid[1], nextCentroid[2]]), speed); | ||
}, intervalTime); | ||
|
||
} catch (e) { | ||
|
||
} | ||
}); | ||
|
||
viewer.on("pick", (arg) => { | ||
console.log(`Product id: ${arg.id}, model: ${arg.model}`) | ||
}); | ||
|
||
|
||
viewer.loadAsync('/tests/data/v4/Viadotto Acerno.wexbim') | ||
viewer.hoverPickEnabled = true; | ||
viewer.adaptivePerformanceOn = false; | ||
viewer.highlightingColour = [0, 0, 255, 255]; | ||
viewer.start(); | ||
window['viewer'] = viewer; | ||
|
||
let clipModel = () => { | ||
var planes: ClippingPlane[] = [ | ||
{ | ||
direction: [1, 0, 0], | ||
location: [10000, 0, 0] | ||
}, | ||
{ | ||
direction: [0, 1, 0], | ||
location: [0, 10000, 0] | ||
}, | ||
{ | ||
direction: [0, 0, 1], | ||
location: [0, 0, 2000] | ||
}, | ||
{ | ||
direction: [-1, 0, 0], | ||
location: [-10000, 0, 0] | ||
}, | ||
{ | ||
direction: [0, -1, 0], | ||
location: [0, -10000, 0] | ||
}, | ||
{ | ||
direction: [0, 0, -1], | ||
location: [0, 0, -10000] | ||
} | ||
]; | ||
|
||
viewer.sectionBox.setToPlanes(planes); | ||
} | ||
|
||
document['clip'] = () => { | ||
plane.stopped = false; | ||
}; | ||
document['hideClippingControl'] = () => { | ||
plane.stopped = true; | ||
}; | ||
document['unclip'] = () => { | ||
viewer.unclip(); | ||
plane.stopped = true; | ||
}; | ||
|
||
window['clipBox'] = () => { | ||
var planes: ClippingPlane[] = [ | ||
{ | ||
direction: [1, 0, 0], | ||
location: [5000, 0, 0] | ||
}, | ||
{ | ||
direction: [0, 1, 0], | ||
location: [0, 2000, 0] | ||
}, | ||
{ | ||
direction: [0, 0, 1], | ||
location: [0, 0, 2100] | ||
}, | ||
{ | ||
direction: [-1, 0, 0], | ||
location: [-100, 0, 0] | ||
}, | ||
{ | ||
direction: [0, -1, 0], | ||
location: [0, -2000, 0] | ||
}, | ||
{ | ||
direction: [0, 0, -1], | ||
location: [0, 0, -1000] | ||
} | ||
]; | ||
|
||
viewer.sectionBox.setToPlanes(planes); | ||
viewer.zoomTo(); | ||
}; | ||
|
||
window['releaseClipBox'] = () => { | ||
clipModel(); | ||
viewer.zoomTo(); | ||
}; | ||
|
||
function removeDuplicateXYPoints(centroids: number[][]): number[][] { | ||
const filteredCentroids: number[][] = []; | ||
const tolerance = 1; | ||
|
||
centroids.forEach(centroid => { | ||
const isUnique = filteredCentroids.every(existing => { | ||
const dx = Math.abs(centroid[0] - existing[0]); | ||
const dy = Math.abs(centroid[1] - existing[1]); | ||
return dx > tolerance || dy > tolerance; // Check if the point is outside the tolerance | ||
}); | ||
|
||
if (isUnique) { | ||
filteredCentroids.push(centroid); | ||
} | ||
}); | ||
|
||
return filteredCentroids; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.