Skip to content

Commit dc411a1

Browse files
authored
rename screenPosition to canvasPosition (#3932)
* rename screenPosition to canvasPosition * fixed broken link * fixed type declaration
1 parent 4bd8889 commit dc411a1

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

packages/model-viewer/src/features/annotation.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ const worldToModel = new Matrix4();
3030
const worldToModelNormal = new Matrix3();
3131

3232
export declare type HotspotData = {
33-
readonly position: Vector3D;
34-
readonly normal: Vector3D;
35-
readonly screenPosition: Vector3D;
36-
readonly facingCamera: boolean;
33+
position: Vector3D,
34+
normal: Vector3D,
35+
canvasPosition: Vector3D,
36+
facingCamera: boolean,
3737
}
3838

3939
export declare interface AnnotationInterface {
4040
updateHotspot(config: HotspotConfiguration): void;
41-
queryHotspot(name: string): HotspotData | null;
41+
queryHotspot(name: string): HotspotData|null;
4242
positionAndNormalFromPoint(pixelX: number, pixelY: number):
4343
{position: Vector3D, normal: Vector3D, uv: Vector2D|null}|null
4444
}
@@ -136,7 +136,7 @@ export const AnnotationMixin = <T extends Constructor<ModelViewerElementBase>>(
136136
* This method returns in-scene data about a requested hotspot including
137137
* its position in screen (canvas) space and its current visibility.
138138
*/
139-
queryHotspot(name: string): HotspotData | null {
139+
queryHotspot(name: string): HotspotData|null {
140140
const hotspot = this[$hotspotMap].get(name);
141141
if (hotspot == null) {
142142
return null;
@@ -159,18 +159,15 @@ export const AnnotationMixin = <T extends Constructor<ModelViewerElementBase>>(
159159
vector.x = (vector.x * widthHalf) + widthHalf;
160160
vector.y = -(vector.y * heightHalf) + heightHalf;
161161

162-
const screenPosition = toVector3D(
163-
new Vector3(
164-
vector.x,
165-
vector.y,
166-
vector.z
167-
));
162+
const canvasPosition =
163+
toVector3D(new Vector3(vector.x, vector.y, vector.z));
168164

169-
if (!Number.isFinite(screenPosition.x) || !Number.isFinite(screenPosition.y)) {
165+
if (!Number.isFinite(canvasPosition.x) ||
166+
!Number.isFinite(canvasPosition.y)) {
170167
return null;
171168
}
172169

173-
return {position, normal, screenPosition, facingCamera};
170+
return {position, normal, canvasPosition, facingCamera};
174171
}
175172

176173
/**

packages/model-viewer/src/test/features/annotation-spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,22 @@ suite('Annotation', () => {
9797
});
9898

9999
test('querying it returns valid data', () => {
100-
101-
// to test querying, place hotspot in the center and verify the screen position is
102-
// half the default width and height (300 x 150) with a depth value of ~1.
103-
const defaultDimensions = { width: 300, height: 150 };
104-
element.updateHotspot({ name: 'hotspot-1', position: `0m 0m 0m`});
100+
// to test querying, place hotspot in the center and verify the screen
101+
// position is half the default width and height (300 x 150) with a depth
102+
// value of ~1.
103+
const defaultDimensions = {width: 300, height: 150};
104+
element.updateHotspot({name: 'hotspot-1', position: `0m 0m 0m`});
105105

106106
const hotspotData = element.queryHotspot('hotspot-1');
107107

108-
expect(hotspotData?.screenPosition.x).to.be.closeTo(defaultDimensions.width / 2, 0.0001);
109-
expect(hotspotData?.screenPosition.y).to.be.closeTo(defaultDimensions.height / 2, 0.0001);
110-
expect(hotspotData?.position.toString()).to.equal(toVector3D(new Vector3(0, 0, 0)).toString());
111-
expect(hotspotData?.normal.toString()).to.equal(toVector3D(new Vector3(0, 0, -1)).toString());
108+
expect(hotspotData?.canvasPosition.x)
109+
.to.be.closeTo(defaultDimensions.width / 2, 0.0001);
110+
expect(hotspotData?.canvasPosition.y)
111+
.to.be.closeTo(defaultDimensions.height / 2, 0.0001);
112+
expect(hotspotData?.position.toString())
113+
.to.equal(toVector3D(new Vector3(0, 0, 0)).toString());
114+
expect(hotspotData?.normal.toString())
115+
.to.equal(toVector3D(new Vector3(0, 0, -1)).toString());
112116
expect(hotspotData?.facingCamera).to.be.true;
113117
});
114118

packages/modelviewer.dev/data/docs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,9 @@
766766
{
767767
"name": "queryHotspot(name)",
768768
"htmlName": "queryHotspot",
769-
"description": "Returns information about the current state of the hotspot corresponding to the hotspot name given as a read-only snapshot: The position, normal, screen (canvas) position and current visibility. The screen position is represented as a Vector3 with z as the OpenGL depth information. The function returns null if no hotspot is found.",
769+
"description": "Returns information about the current state of the hotspot corresponding to the hotspot name as a snapshot: the position, normal, canvasPosition, and facingCamera. The canvas position is represented as a Vector3D with z as the OpenGL depth information. The function returns null if no hotspot is found.",
770770
"links": [
771-
"<a href=\"../examples/annotations/#overlays\"><span class='attribute'>custom overlays</span> example</a>"
771+
"<a href=\"../examples/annotations/#dimensions\"><span class='attribute'>dimension lines</span> example</a>"
772772
]
773773
},
774774
{

packages/modelviewer.dev/examples/annotations/index.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ <h4 id="intro"><span class="font-medium">Show Dimensions. </span></h4>
136136
<p>
137137
Hotspots can be queried to build custom overlays in screen space.
138138
For example, by using an SVG canvas and updating the line nodes we
139-
can draw rudimentary dimensions lines. Note that this kind of
140-
extended functionality cannot support occlusion in the 3D scene as
141-
it is drawn on top.
139+
can draw rudimentary dimension lines. Note that this kind of
140+
extended functionality cannot support occlusion in the 3D scene, but
141+
you can cause it to draw behind the model by setting its CSS z-index
142+
to a negative value.
142143
</p>
143144
<p>
144145
By using WebXR mode, this markup works equally well in AR. Note that
@@ -279,10 +280,10 @@ <h4 id="intro"><span class="font-medium">Show Dimensions. </span></h4>
279280
// update svg
280281
function drawLine(svgLine, dotHotspot1, dotHotspot2, dimensionHotspot) {
281282
if (dotHotspot1 && dotHotspot1) {
282-
svgLine.setAttribute('x1', dotHotspot1.screenPosition.x);
283-
svgLine.setAttribute('y1', dotHotspot1.screenPosition.y);
284-
svgLine.setAttribute('x2', dotHotspot2.screenPosition.x);
285-
svgLine.setAttribute('y2', dotHotspot2.screenPosition.y);
283+
svgLine.setAttribute('x1', dotHotspot1.canvasPosition.x);
284+
svgLine.setAttribute('y1', dotHotspot1.canvasPosition.y);
285+
svgLine.setAttribute('x2', dotHotspot2.canvasPosition.x);
286+
svgLine.setAttribute('y2', dotHotspot2.canvasPosition.y);
286287

287288
// use provided optional hotspot to tie visibility of this svg line to
288289
if (dimensionHotspot && !dimensionHotspot.facingCamera) {

0 commit comments

Comments
 (0)