Skip to content

Commit e1a1f6f

Browse files
committed
points
1 parent 9a51990 commit e1a1f6f

File tree

16 files changed

+31855
-23534
lines changed

16 files changed

+31855
-23534
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ class NgtRenderer implements Renderer2 {
296296
(pRS[NgtRendererClassId.type] === 'compound' && !pRS[NgtRendererClassId.compounded])) &&
297297
(cRS[NgtRendererClassId.type] === 'dom' ||
298298
(cRS[NgtRendererClassId.type] === 'compound' && !cRS[NgtRendererClassId.compounded]))) ||
299-
(pRS[NgtRendererClassId.type] === 'dom' &&
299+
// or the parent is a non-compounded compound
300+
// and the child is a compounded compound
301+
((pRS[NgtRendererClassId.type] === 'dom' ||
302+
(pRS[NgtRendererClassId.type] === 'compound' && !pRS[NgtRendererClassId.compounded])) &&
300303
cRS[NgtRendererClassId.type] === 'compound' &&
301304
!!cRS[NgtRendererClassId.compounded]);
302305

libs/soba/materials/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# angular-three-soba/materials
2+
3+
Secondary entry point of `angular-three-soba`. It can be used by importing from `angular-three-soba/materials`.

libs/soba/materials/ng-package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"lib": {
3+
"entryFile": "src/index.ts"
4+
}
5+
}

libs/soba/materials/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './point-material/point-material';
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { CUSTOM_ELEMENTS_SCHEMA, Component, Input } from '@angular/core';
2+
import { NgtArgs, injectNgtRef, type NgtPointsMaterial } from 'angular-three';
3+
import * as THREE from 'three';
4+
5+
const opaque_fragment = parseInt(THREE.REVISION.replace(/\D+/g, '')) >= 154 ? 'opaque_fragment' : 'output_fragment';
6+
7+
export class PointMaterial extends THREE.PointsMaterial {
8+
constructor(parameters: THREE.PointsMaterialParameters) {
9+
super(parameters);
10+
this.onBeforeCompile = (shader, renderer) => {
11+
const { isWebGL2 } = renderer.capabilities;
12+
shader.fragmentShader = shader.fragmentShader.replace(
13+
`#include <${opaque_fragment}>`,
14+
`
15+
${
16+
!isWebGL2
17+
? `#extension GL_OES_standard_derivatives : enable\n#include <${opaque_fragment}>`
18+
: `#include <${opaque_fragment}>`
19+
}
20+
vec2 cxy = 2.0 * gl_PointCoord - 1.0;
21+
float r = dot(cxy, cxy);
22+
float delta = fwidth(r);
23+
float mask = 1.0 - smoothstep(1.0 - delta, 1.0 + delta, r);
24+
gl_FragColor = vec4(gl_FragColor.rgb, mask * gl_FragColor.a );
25+
#include <tonemapping_fragment>
26+
#include <${parseInt(THREE.REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
27+
`,
28+
);
29+
};
30+
}
31+
}
32+
33+
declare global {
34+
interface HTMLElementTagNameMap {
35+
/**
36+
* @extends ngt-points-material
37+
*/
38+
'ngt-point-material': NgtPointsMaterial;
39+
/**
40+
* @extends ngt-points-material
41+
*/
42+
'ngts-point-material': NgtPointsMaterial;
43+
}
44+
}
45+
46+
@Component({
47+
selector: 'ngts-point-material',
48+
standalone: true,
49+
template: `<ngt-primitive ngtCompound [ref]="pointMaterialRef" *args="[material]" attach="material" />`,
50+
imports: [NgtArgs],
51+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
52+
})
53+
export class NgtsPointMaterial {
54+
@Input() pointMaterialRef = injectNgtRef<PointMaterial>();
55+
56+
material = new PointMaterial({});
57+
}

libs/soba/misc/src/html/html-wrapper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ export class NgtsHtmlWrapper {
293293

294294
let contentRef: EmbeddedViewRef<unknown>;
295295
let contentParent: HTMLElement;
296+
/**
297+
* NOTE: utilizing rAF here so that renderAnchor (ViewContainerRef) has a chance to be resolved
298+
* TODO: Another approach is to call render() in ngOnInit and pass in an injector to the effect
299+
*/
296300
const rAF = requestAnimationFrame(() => {
297301
if (content && this.renderAnchor) {
298302
contentRef = this.renderAnchor.createEmbeddedView(content);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"lib": {
3-
"entryFile": "src/index.ts"
4-
}
2+
"lib": {
3+
"entryFile": "src/index.ts"
4+
}
55
}

libs/soba/performances/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './adaptive-dpr/adaptive-dpr';
22
export * from './adaptive-events/adaptive-events';
3+
export * from './points/points';
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Directive, Input } from '@angular/core';
2+
import { injectNgtRef, signalStore } from 'angular-three';
3+
import type { Points } from 'three';
4+
5+
export type NgtsPointsInstancesState = {
6+
limit: number;
7+
range?: number;
8+
};
9+
10+
export type NgtsPointsBuffersState = {
11+
// a buffer containing all points position
12+
positions: Float32Array;
13+
colors?: Float32Array;
14+
sizes?: Float32Array;
15+
// The size of the points in the buffer
16+
stride: 2 | 3;
17+
};
18+
19+
@Directive()
20+
export abstract class NgtsPointsInput {
21+
protected inputs = signalStore<NgtsPointsBuffersState & NgtsPointsInstancesState>({
22+
stride: 3,
23+
limit: 1000,
24+
});
25+
26+
@Input() pointsRef = injectNgtRef<Points>();
27+
28+
@Input({ alias: 'range' }) set _range(range: number) {
29+
this.inputs.set({ range });
30+
}
31+
32+
@Input({ alias: 'limit' }) set _limit(limit: number) {
33+
this.inputs.set({ limit });
34+
}
35+
36+
@Input({ alias: 'positions' }) set _positions(positions: Float32Array) {
37+
this.inputs.set({ positions });
38+
}
39+
40+
@Input({ alias: 'colors' }) set _colors(colors: Float32Array) {
41+
this.inputs.set({ colors });
42+
}
43+
44+
@Input({ alias: 'sizes' }) set _sizes(sizes: Float32Array) {
45+
this.inputs.set({ sizes });
46+
}
47+
48+
@Input({ alias: 'stride' }) set _stride(stride: 2 | 3) {
49+
this.inputs.set({ stride });
50+
}
51+
52+
limit = this.inputs.select('limit');
53+
range = this.inputs.select('range');
54+
positions = this.inputs.select('positions');
55+
colors = this.inputs.select('colors');
56+
sizes = this.inputs.select('sizes');
57+
stride = this.inputs.select('stride');
58+
}

0 commit comments

Comments
 (0)