Skip to content

Commit 05ad6dc

Browse files
committed
fix(soba): set up an effect for setting position of gizmo instead
1 parent 0db0b1e commit 05ad6dc

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

Diff for: libs/soba/gizmos/src/lib/pivot-controls/pivot-controls.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ import {
88
output,
99
viewChild,
1010
} from '@angular/core';
11-
import { extend, getLocalState, injectBeforeRender, injectStore, NgtAnyRecord, omit, pick } from 'angular-three';
11+
import {
12+
applyProps,
13+
extend,
14+
getLocalState,
15+
injectBeforeRender,
16+
injectStore,
17+
NgtAnyRecord,
18+
omit,
19+
pick,
20+
} from 'angular-three';
1221
import { calculateScaleFactor } from 'angular-three-soba/misc';
1322
import { mergeInputs } from 'ngxtension/inject-inputs';
1423
import { Box3, Group, Matrix4, Mesh, Vector3 } from 'three';
@@ -128,7 +137,7 @@ const defaultOptions: NgtsPivotControlsOptions = {
128137
template: `
129138
<ngt-group #parent>
130139
<ngt-group #group [matrix]="matrix()" [matrixAutoUpdate]="false" [parameters]="parameters()">
131-
<ngt-group #gizmo [visible]="visible()" [position]="offset()" [rotation]="rotation()">
140+
<ngt-group #gizmo [visible]="visible()" [rotation]="rotation()">
132141
@if (enabled()) {
133142
@let _disableAxes = disableAxes();
134143
@let _disableSliders = disableSliders();
@@ -268,6 +277,17 @@ export class NgtsPivotControls {
268277
constructor() {
269278
extend({ Group });
270279

280+
effect(() => {
281+
const [anchor, offset] = [this.anchor(), this.offset()];
282+
// if there is anchor, then the below effect will handle the position
283+
if (anchor) return;
284+
// if not, then we'll use the offset to set the position for gizmo
285+
const gizmo = this.gizmoRef().nativeElement;
286+
if (!gizmo) return;
287+
288+
applyProps(gizmo, { position: offset });
289+
});
290+
271291
effect(() => {
272292
const anchor = this.anchor();
273293
if (!anchor) return;

Diff for: libs/soba/src/gizmos/pivot-controls.stories.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { makeDecorators, makeStoryObject } from '../setup-canvas';
99
<ngts-pivot-controls [options]="options()">
1010
<ngt-mesh>
1111
<ngt-box-geometry />
12-
<ngt-mesh-standard-material />
12+
<ngt-mesh-standard-material [wireframe]="true" />
1313
</ngt-mesh>
1414
</ngts-pivot-controls>
1515
<ngt-directional-light [position]="[10, 10, 5]" />

0 commit comments

Comments
 (0)