MCPcopy
hub / github.com/sparkjsdev/spark / constructGenerator

Method constructGenerator

src/SplatMesh.ts:657–734  ·  view source on GitHub ↗
(context: SplatMeshContext)

Source from the content-addressed store, hash-verified

655 }
656
657 private constructGenerator(context: SplatMeshContext) {
658 if (this.covSplats) {
659 return this.constructCovGenerator(context);
660 }
661
662 const { transform, viewToObject, recolor } = context;
663 const generator = dynoBlock(
664 { index: "int" },
665 { gsplat: Gsplat },
666 ({ index }) => {
667 if (!index) {
668 throw new Error("index is undefined");
669 }
670
671 index = maybeLookupIndex(
672 context.lodIndices,
673 index,
674 context.numSplats,
675 context.enableLod,
676 this.showLodPageDyno,
677 );
678
679 // Read a Gsplat from the SplatSource
680 context.splats.setMaxSh(this.maxSh);
681 context.splats.prepareFetchSplat();
682 let gsplat = context.splats.fetchSplat({
683 index,
684 viewOrigin: viewToObject.translate,
685 });
686
687 if (this.splatRgba) {
688 // Overwrite RGBA with baked RGBA values
689 gsplat = maybeInjectSplatRgba(
690 gsplat,
691 this.splatRgba.dyno,
692 index,
693 context.enableLod,
694 );
695 }
696
697 if (this.skinning) {
698 // Transform according to bones + skinning weights
699 gsplat = this.skinning.modify(gsplat);
700 }
701
702 if (this.objectModifiers) {
703 // Inject object-space Gsplat modifier dyno
704 for (const modifier of this.objectModifiers) {
705 gsplat = modifier.apply({ gsplat }).gsplat;
706 }
707 }
708
709 // Transform from object to world-space
710 gsplat = transform.applyGsplat(gsplat);
711
712 // Apply any global recoloring and opacity
713 const recolorRgba = mul(recolor, splitGsplat(gsplat).outputs.rgba);
714 gsplat = combineGsplat({ gsplat, rgba: recolorRgba });

Callers 1

updateMethod · 0.95

Calls 13

constructCovGeneratorMethod · 0.95
dynoBlockFunction · 0.90
mulFunction · 0.90
splitGsplatFunction · 0.90
combineGsplatFunction · 0.90
maybeLookupIndexFunction · 0.85
maybeInjectSplatRgbaFunction · 0.85
applyGsplatMethod · 0.80
setMaxShMethod · 0.65
prepareFetchSplatMethod · 0.65
fetchSplatMethod · 0.65
modifyMethod · 0.45

Tested by

no test coverage detected