Voxel Probe domElement position
See original GitHub issueThe positioning of the element containing voxel data only works when the renderer’s parent element is positioned at the top-left corner of the document. If the the renderer parent is contained in another element and its positioning with respect to the document is not at the top-left corner you should take in account its offset.
I made a little patch to the “updateRaycaster” function but I’m not sure if it’s the correct way to address the problem, neither if it conforms to your code conventions…
Anyway, here’s my patch:
updateRaycaster(raycaster, event, container) {
// calculate mouse position in normalized device coordinates
// (-1 to +1) for both components
var offsets = this.getContainerOffsets();
this._mouse = {
x: (event.clientX - offsets.left) / container.offsetWidth * 2 - 1,
y: -((event.clientY - offsets.top) / container.offsetHeight) * 2 + 1,
screenX: event.clientX - offsets.left,
screenY: event.clientY - offsets.top
};
// update the raycaster
raycaster.setFromCamera(this._mouse, this._camera);
}
getContainerOffsets() { // crossbrowser version
//Taken from http://stackoverflow.com/a/26230989/6172502
var box = container.getBoundingClientRect();
var body = document.body;
var docEl = document.documentElement;
var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
var scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;
var clientTop = docEl.clientTop || body.clientTop || 0;
var clientLeft = docEl.clientLeft || body.clientLeft || 0;
var top = box.top + scrollTop - clientTop;
var left = box.left + scrollLeft - clientLeft;
return { top: Math.round(top), left: Math.round(left) };
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Three.js Voxel Painter / groundbear - Observable
renderer = hg {domElement: HTMLCanvasElement, debug: Object, autoClear: true, ... voxel.position.copy(intersect.point).add(intersect.face.normal);.
Read more >Voxel Probe - Documentation - Unigine Developer
Voxel Probe is a light source which provides static voxel lighting and shading on an object inside Voxel Probe by using a prebaked...
Read more >API Docs - Cornerstone Tools
Returns an array of voxel values masked by the segment for each frame, as well as the real world volume of a voxel...
Read more >Manipulating DOM Elements with html() and position() - p5.js ...
This video shows how to change the content of an HTML element using html() or set its position using position (). These functions...
Read more >How To Bake Global Illumination to Voxel Probes - unigine
Voxel Probe is one of the light baking technologies available in UNIGINE 2 that provides static voxel lighting and object shading using a ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, I’m working on it… Expect a pull request on a couple of days…
Thanks @okrad that would be very useful!