Skip to content

Commit 6869f22

Browse files
committed
fix(core): adjust a lot in renderer
1 parent 96892ad commit 6869f22

File tree

8 files changed

+75
-28
lines changed

8 files changed

+75
-28
lines changed

libs/core/src/lib/renderer/renderer.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ export class NgtRenderer2 implements Renderer2 {
375375
this.appendChild(parent, child);
376376
}
377377

378+
for (const platformChildNode of newChild['childNodes'] || []) {
379+
this.appendChild(parent, platformChildNode);
380+
}
381+
378382
return;
379383
}
380384

@@ -642,6 +646,17 @@ export class NgtRenderer2 implements Renderer2 {
642646
return rendererParentNode ?? this.delegateRenderer.parentNode(node);
643647
}
644648

649+
// removeAttribute = this.delegateRenderer.removeAttribute.bind(this.delegateRenderer);
650+
removeAttribute(el: NgtRendererNode, name: string, namespace?: string | null): void {
651+
const rS = el.__ngt_renderer__;
652+
if (!rS || rS[NgtRendererClassId.destroyed]) return this.delegateRenderer.removeAttribute(el, name, namespace);
653+
654+
if (rS[NgtRendererClassId.type] === 'three') {
655+
return;
656+
}
657+
return this.delegateRenderer.removeAttribute(el, name, namespace);
658+
}
659+
645660
setAttribute(el: NgtRendererNode, name: string, value: string, namespace?: string | null): void {
646661
const rS = el.__ngt_renderer__;
647662
if (!rS) return this.delegateRenderer.setAttribute(el, name, value, namespace);
@@ -817,7 +832,14 @@ export class NgtRenderer2 implements Renderer2 {
817832
};
818833
}
819834

820-
return iS.setPointerEvent?.(eventName as keyof NgtEventHandlers, callback) || (() => {});
835+
const cleanup = iS.setPointerEvent?.(eventName as keyof NgtEventHandlers, callback) || (() => {});
836+
837+
// this means the object has already been attaached to the parent and has its store propgated
838+
if (iS.store) {
839+
iS.addInteraction?.(iS.store);
840+
}
841+
842+
return cleanup;
821843
}
822844

823845
return this.delegateRenderer.listen(target, eventName, callback);
@@ -905,5 +927,4 @@ export class NgtRenderer2 implements Renderer2 {
905927
selectRootElement = this.delegateRenderer.selectRootElement.bind(this.delegateRenderer);
906928
nextSibling = this.delegateRenderer.nextSibling.bind(this.delegateRenderer);
907929
setValue = this.delegateRenderer.setValue.bind(this.delegateRenderer);
908-
removeAttribute = this.delegateRenderer.removeAttribute.bind(this.delegateRenderer);
909930
}

libs/core/src/lib/renderer/utils.ts

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,31 @@ export function kebabToPascal(str: string): string {
4646
return pascalStr;
4747
}
4848

49+
function propagateStoreRecursively(node: NgtInstanceNode, parentNode: NgtInstanceNode) {
50+
const iS = getInstanceState(node);
51+
const pIS = getInstanceState(parentNode);
52+
53+
if (!iS || !pIS) return;
54+
55+
// assign store on child if not already exist
56+
// or child store is not the same as parent store
57+
// or child store is the parent of parent store
58+
if (!iS.store || iS.store !== pIS.store || iS.store === pIS.store.snapshot.previousRoot) {
59+
iS.store = pIS.store;
60+
61+
// Call addInteraction if it exists
62+
iS.addInteraction?.(pIS.store);
63+
64+
// Collect all children (objects and nonObjects)
65+
const children = [...(iS.objects ? untracked(iS.objects) : []), ...(iS.nonObjects ? untracked(iS.nonObjects) : [])];
66+
67+
// Recursively reassign the store for each child
68+
for (const child of children) {
69+
propagateStoreRecursively(child, node);
70+
}
71+
}
72+
}
73+
4974
export function attachThreeNodes(parent: NgtInstanceNode, child: NgtInstanceNode) {
5075
const pIS = getInstanceState(parent);
5176
const cIS = getInstanceState(child);
@@ -57,25 +82,8 @@ export function attachThreeNodes(parent: NgtInstanceNode, child: NgtInstanceNode
5782
// whether the child is added to the parent with parent.add()
5883
let added = false;
5984

60-
// assign store on child if not already exist
61-
// or child store is not the same as parent store
62-
// or child store is the parent of parent store
63-
if (!cIS.store || cIS.store !== pIS.store || cIS.store === pIS.store.snapshot.previousRoot) {
64-
cIS.store = pIS.store;
65-
66-
cIS.addInteraction?.(cIS.store);
67-
68-
const grandChildren = [
69-
...(cIS.objects ? untracked(cIS.objects) : []),
70-
...(cIS.nonObjects ? untracked(cIS.nonObjects) : []),
71-
];
72-
for (const grandChild of grandChildren) {
73-
const grandChildIS = getInstanceState(grandChild);
74-
if (!grandChildIS) continue;
75-
grandChildIS.store = cIS.store;
76-
grandChildIS.addInteraction?.(cIS.store);
77-
}
78-
}
85+
// propagate store recursively
86+
propagateStoreRecursively(child, parent);
7987

8088
if (cIS.attach) {
8189
const attachProp = cIS.attach;

libs/core/src/lib/utils/apply-props.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export function applyProps<T extends NgtAnyRecord>(instance: NgtInstanceState<T>
4848
for (let i = 0; i < changes.length; i++) {
4949
let [key, value] = changes[i];
5050

51+
// Ignore setting undefined props
52+
// https://github.com/pmndrs/react-three-fiber/issues/274
53+
if (value === undefined) continue;
54+
5155
// Alias (output)encoding => (output)colorSpace (since r152)
5256
// https://github.com/pmndrs/react-three-fiber/pull/2829
5357
// if (is.colorSpaceExist(instance)) {

libs/soba/gizmos/src/lib/pivot-controls/pivot-controls.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ const defaultOptions: NgtsPivotControlsOptions = {
128128
selector: 'ngts-pivot-controls',
129129
template: `
130130
<ngt-group #parent>
131-
<ngt-group #group [matrix]="matrix()" [matrixAutoUpdate]="false" [parameters]="parameters()">
131+
<ngt-group
132+
#group
133+
[matrix]="matrix()"
134+
[matrixAutoUpdate]="false"
135+
[parameters]="parameters()"
136+
(pointerover)="(undefined)"
137+
>
132138
<ngt-group #gizmo [visible]="visible()" [position]="offset()" [rotation]="rotation()">
133139
@if (enabled()) {
134140
@let _disableAxes = disableAxes();

libs/soba/src/misc/animations.stories.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { NgtArgs } from 'angular-three';
1414
import { injectGLTF } from 'angular-three-soba/loaders';
1515
import { NgtsAnimation, injectAnimations } from 'angular-three-soba/misc';
1616
import { injectMatcapTexture } from 'angular-three-soba/staging';
17-
import { Bone, Group, MeshStandardMaterial, Object3D, SkinnedMesh } from 'three';
17+
import { Bone, Group, MeshStandardMaterial, Object3D, SRGBColorSpace, SkinnedMesh } from 'three';
1818
import { GLTF } from 'three-stdlib';
1919
import { select, storyDecorators, storyObject } from '../setup-canvas';
2020

@@ -78,8 +78,16 @@ class DefaultAnimationsStory {
7878
animation = input('Strut');
7979

8080
gltf = injectGLTF<BotGLTF>(() => './ybot.glb');
81-
matcapBody = injectMatcapTexture(() => '293534_B2BFC5_738289_8A9AA7');
82-
matcapJoints = injectMatcapTexture(() => '3A2412_A78B5F_705434_836C47');
81+
matcapBody = injectMatcapTexture(() => '293534_B2BFC5_738289_8A9AA7', {
82+
onLoad: (textures) => {
83+
textures[0].colorSpace = SRGBColorSpace;
84+
},
85+
});
86+
matcapJoints = injectMatcapTexture(() => '3A2412_A78B5F_705434_836C47', {
87+
onLoad: (textures) => {
88+
textures[0].colorSpace = SRGBColorSpace;
89+
},
90+
});
8391

8492
boneRef = viewChild<ElementRef<Bone>>('bone');
8593
}

libs/soba/src/performances/instances.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export default {
148148
} as Meta;
149149

150150
export const Default = storyObject(DefaultInstancesStory, {
151-
controls: false,
151+
controls: null,
152152
lights: false,
153153
background: 'white',
154154
camera: { position: [0, 0, 20], fov: 50 },

libs/soba/src/staging/bb-anchor.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class BBAnchorWrapper {
5252
template: `
5353
<bb-anchor-wrapper [options]="options()" [drawBoundingBox]="drawBoundingBox()">
5454
<ngts-html>
55-
<div [ngtsHTMLContent]="{ center: true, containerStyle: { color: 'white', whiteSpace: 'nowrap' } }">
55+
<div [htmlContent]="{ center: true, containerStyle: { color: 'white', whiteSpace: 'nowrap' } }">
5656
HTML content
5757
</div>
5858
</ngts-html>

libs/soba/src/staging/bounds.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ export default {
128128
export const Default = storyFunction(DefaultBoundsStory, {
129129
camera: { position: [0, -10, 80], fov: 50 },
130130
lights: false,
131-
controls: false,
131+
controls: null,
132132
});

0 commit comments

Comments
 (0)