Skip to content

Commit 8348361

Browse files
authored
Updates @playcanvas/blocks to 2.8.0 (#172)
* Update playcanvas dependency to v2.8.0 and refactor related components - Reintroduced playcanvas dependency in pnpm-lock.yaml and package.json for blocks. - Updated imports in SmartCamera and SplatViewer components to include new playcanvas entities. - Adjusted rotation values in example documentation for consistency. - Enhanced GSplat component to validate asset prop as an Asset instance. * changeset
1 parent 0c708dd commit 8348361

File tree

7 files changed

+30
-15
lines changed

7 files changed

+30
-15
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@playcanvas/blocks": patch
3+
---
4+
5+
Updated @playcanvas/blocks to use 2.8.0 of the engine

packages/blocks/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"devDependencies": {
6868
"@types/react": "19.1.8",
6969
"@types/react-dom": "19.1.6",
70+
"playcanvas": "2.8.0",
7071
"tsc-alias": "1.8.16"
7172
},
7273
"peerDependencies": {

packages/blocks/src/splat-viewer/smart-camera.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useEffect, useRef, useState } from "react";
44
import { Entity } from "@playcanvas/react";
55
import { Camera, Script } from "@playcanvas/react/components";
66
import { useTimeline, useAssetViewer } from "./splat-viewer-context";
7-
import { Vec3 } from "playcanvas";
7+
import { Vec3, Entity as PcEntity } from "playcanvas";
88

99
import { AnimationTrack, AnimCamera, createRotationTrack } from "./utils/animation"; // assumed
1010
import { computeStartingPose, Pose, PoseType } from "./utils/pose";
@@ -72,7 +72,7 @@ export function SmartCamera({
7272
variant?: "paris" | "neutral" | "noir" | "none" | PostEffectsSettings;
7373
}) {
7474

75-
const entityRef = useRef<pc.Entity>(null);
75+
const entityRef = useRef<PcEntity>(null);
7676
const { subscribe, isPlaying } = useTimeline();
7777
const { mode, subscribeCameraReset } = useAssetViewer();
7878
const timeoutRef = useRef(0);
@@ -83,9 +83,10 @@ export function SmartCamera({
8383
useEffect(() => {
8484
timeoutRef.current = setTimeout(() => {
8585
setShouldUseRenderOnCameraChange(true);
86+
app.renderNextFrame = true;
8687
}, 200);
8788
return () => clearTimeout(timeoutRef.current);
88-
}, []);
89+
});
8990

9091
useRenderOnCameraChange(shouldUseRenderOnCameraChange ? entityRef.current : null);
9192

packages/blocks/src/splat-viewer/splat-viewer.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client"
22

3-
import { Application } from "@playcanvas/react"
3+
import { Application, Entity } from "@playcanvas/react"
44
import { useApp, useSplat } from "@playcanvas/react/hooks"
55
import { GSplat } from "@playcanvas/react/components"
66
import { Suspense, useCallback, useEffect, useRef, useState } from "react"
@@ -10,8 +10,7 @@ import { cn } from "@lib/utils"
1010
import { AnimationTrack } from "./utils/animation"
1111
import { SmartCamera } from "./smart-camera"
1212
import { HelpDialog } from "./help-dialog"
13-
import { FILLMODE_NONE } from "playcanvas"
14-
import { RESOLUTION_AUTO } from "playcanvas"
13+
import { RESOLUTION_AUTO, FILLMODE_NONE } from "playcanvas"
1514
import { useSubscribe } from "./hooks/use-subscribe"
1615
export type CameraMode = 'orbit' | 'fly';
1716

@@ -160,7 +159,9 @@ function SplatComponent({
160159
// <InteractiveCamera fov={30} type={type} />
161160
<SmartCamera fov={30} variant={variant} />
162161
}
163-
<GSplat asset={asset} />
162+
<Entity rotation={[0, 0, 180]}>
163+
<GSplat asset={asset} />
164+
</Entity>
164165
</>
165166
)
166167
}

packages/docs/content/examples/splats.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export const Example = () => {
33
/**
44
* Loading a Gaussian Splat ply
55
*/
6-
76
const splatURL = "https://6rpjo46zo7.ufs.sh/f/dTTBXSHFOX4z7irrg5DfZElT6yeQYKvdjgi5IsoB0cmu9OtF"
87
const { data: splat } = useSplat(splatURL);
98

@@ -19,7 +18,7 @@ export const Example = () => {
1918
</Entity>
2019
{/* Create the splat entity */}
2120
<Entity
22-
rotation={[0, -40, 0]}
21+
rotation={[0, 40, 180]}
2322
position={[0.2, -1.7, -6]}>
2423
{ splat && <GSplat asset={splat}/> }
2524
</Entity>

packages/lib/src/components/GSplat.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { FC } from "react";
44
import { useComponent } from "../hooks";
5-
import { Entity, GSplatComponent } from "playcanvas";
5+
import { Asset, Entity, GSplatComponent } from "playcanvas";
66
import { PublicProps } from "../utils/types-utils";
77
import { validatePropsWithDefaults, createComponentDefinition, getStaticNullApplication } from "../utils/validation";
88
/**
@@ -16,7 +16,6 @@ import { validatePropsWithDefaults, createComponentDefinition, getStaticNullAppl
1616
export const GSplat: FC<GSplatProps> = (props) => {
1717

1818
const safeProps = validatePropsWithDefaults<GSplatProps, GSplatComponent>(props, componentDefinition);
19-
2019
useComponent("gsplat", safeProps, componentDefinition.schema);
2120
return null
2221

@@ -29,4 +28,13 @@ const componentDefinition = createComponentDefinition(
2928
() => new Entity("mock-gsplat", getStaticNullApplication()).addComponent('gsplat') as GSplatComponent,
3029
(component) => (component as GSplatComponent).system.destroy(),
3130
"GSplatComponent"
32-
)
31+
)
32+
33+
componentDefinition.schema = {
34+
...componentDefinition.schema,
35+
asset: {
36+
validate: (val: unknown) => val instanceof Asset,
37+
errorMsg: (val: unknown) => `Invalid value for prop "asset": "${JSON.stringify(val)}". Expected an Asset.`,
38+
default: null
39+
}
40+
}

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)