diff --git a/docs/user-manual/react/examples/model-viewer.mdx b/docs/user-manual/react/examples/model-viewer.mdx new file mode 100644 index 00000000000..a68a9931e45 --- /dev/null +++ b/docs/user-manual/react/examples/model-viewer.mdx @@ -0,0 +1,20 @@ +--- +title: Model Viewer +description: Live PlayCanvas React example — a glb model viewer with environment lighting, shadows and orbit controls. +--- + +import { CodeExample } from '@site/src/components/playcanvas-react/CodeExample'; +import ModelViewerExample from '@site/src/components/playcanvas-react/examples/ModelViewerExample'; +import ModelViewerExampleSource from '!!raw-loader!@site/src/components/playcanvas-react/examples/ModelViewerExample.jsx'; + +A simple glb model viewer with environment lighting, a shadow catcher and auto-rotating orbit controls. Drag to orbit the camera around the model. + + + + diff --git a/docs/user-manual/react/examples/motion.mdx b/docs/user-manual/react/examples/motion.mdx new file mode 100644 index 00000000000..453f5c10c0f --- /dev/null +++ b/docs/user-manual/react/examples/motion.mdx @@ -0,0 +1,20 @@ +--- +title: Motion +description: Live PlayCanvas React example — animating entities and lights with springs from the Motion animation library. +--- + +import { CodeExample } from '@site/src/components/playcanvas-react/CodeExample'; +import MotionExample from '@site/src/components/playcanvas-react/examples/MotionExample'; +import MotionExampleSource from '!!raw-loader!@site/src/components/playcanvas-react/examples/MotionExample.jsx'; + +Hover over the capsule to see entities and lights animate with springs from the [Motion](https://motion.dev/) animation library. Motion values drive each entity's position, rotation and scale, while a script applies animated intensities to the lights. + + + + diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/user-manual/react/examples/model-viewer.mdx b/i18n/ja/docusaurus-plugin-content-docs/current/user-manual/react/examples/model-viewer.mdx new file mode 100644 index 00000000000..3e5147dc231 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/user-manual/react/examples/model-viewer.mdx @@ -0,0 +1,20 @@ +--- +title: モデルビューア +description: PlayCanvas Reactのライブサンプル — 環境ライティング、影、オービットコントロールを備えたglbモデルビューア。 +--- + +import { CodeExample } from '@site/src/components/playcanvas-react/CodeExample'; +import ModelViewerExample from '@site/src/components/playcanvas-react/examples/ModelViewerExample'; +import ModelViewerExampleSource from '!!raw-loader!@site/src/components/playcanvas-react/examples/ModelViewerExample.jsx'; + +環境ライティング、シャドウキャッチャー、自動回転するオービットコントロールを備えたシンプルなglbモデルビューアです。ドラッグしてモデルの周りでカメラを回転させてみましょう。 + + + + diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/user-manual/react/examples/motion.mdx b/i18n/ja/docusaurus-plugin-content-docs/current/user-manual/react/examples/motion.mdx new file mode 100644 index 00000000000..1f741d45821 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/user-manual/react/examples/motion.mdx @@ -0,0 +1,20 @@ +--- +title: モーション +description: PlayCanvas Reactのライブサンプル — Motionアニメーションライブラリのスプリングでエンティティとライトをアニメーション。 +--- + +import { CodeExample } from '@site/src/components/playcanvas-react/CodeExample'; +import MotionExample from '@site/src/components/playcanvas-react/examples/MotionExample'; +import MotionExampleSource from '!!raw-loader!@site/src/components/playcanvas-react/examples/MotionExample.jsx'; + +カプセルにホバーすると、[Motion](https://motion.dev/)アニメーションライブラリのスプリングでエンティティとライトがアニメーションします。モーション値が各エンティティの位置、回転、スケールを駆動し、スクリプトがアニメーションされた強度をライトに適用します。 + + + + diff --git a/package-lock.json b/package-lock.json index e01122c578f..2e74e8dd739 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "docusaurus-plugin-sass": "^0.2.6", "js-yaml": "^4.2.0", "leva": "^0.10.1", + "motion": "^12.40.0", "playcanvas": "^2.19.6", "prism-react-renderer": "^2.4.1", "raw-loader": "^4.0.2", @@ -12178,6 +12179,33 @@ "url": "https://github.com/sponsors/rawify" } }, + "node_modules/framer-motion": { + "version": "12.40.0", + "resolved": "https://registry.npmjs.org/framer-motion/-/framer-motion-12.40.0.tgz", + "integrity": "sha512-uaBd3qC1v3KQqBEjwTUd183K6PbS+j0yR9w9VmEOLWA/tnUcSn8Xa3uck7t4dgpDoUss8xQTcj8W2L07lrnLFg==", + "license": "MIT", + "dependencies": { + "motion-dom": "^12.40.0", + "motion-utils": "^12.39.0", + "tslib": "^2.4.0" + }, + "peerDependencies": { + "@emotion/is-prop-valid": "*", + "react": "^18.0.0 || ^19.0.0", + "react-dom": "^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@emotion/is-prop-valid": { + "optional": true + }, + "react": { + "optional": true + }, + "react-dom": { + "optional": true + } + } + }, "node_modules/fresh": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", @@ -17087,6 +17115,47 @@ "ufo": "^1.6.3" } }, + "node_modules/motion": { + "version": "12.40.0", + "resolved": "https://registry.npmjs.org/motion/-/motion-12.40.0.tgz", + "integrity": "sha512-yjrHUrBFW6kQvjJwRsoiPSAhC5tRwRqNGJWmiJ4CrGnbKp0V88AdzkhBmDoqIsIPfarOe0Uddd37Xq43/gIocA==", + "license": "MIT", + "dependencies": { + "framer-motion": "^12.40.0", + "tslib": "^2.4.0" + }, + "peerDependencies": { + "@emotion/is-prop-valid": "*", + "react": "^18.0.0 || ^19.0.0", + "react-dom": "^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@emotion/is-prop-valid": { + "optional": true + }, + "react": { + "optional": true + }, + "react-dom": { + "optional": true + } + } + }, + "node_modules/motion-dom": { + "version": "12.40.0", + "resolved": "https://registry.npmjs.org/motion-dom/-/motion-dom-12.40.0.tgz", + "integrity": "sha512-HxU3ZaBwNPVQUBQf1xxgq+7JrPNZvjLVxgbpEZL7RrWJnsxOf0/OM+yrHG9ogLQ31Do/r57Oz2gQWPK+6q62mg==", + "license": "MIT", + "dependencies": { + "motion-utils": "^12.39.0" + } + }, + "node_modules/motion-utils": { + "version": "12.39.0", + "resolved": "https://registry.npmjs.org/motion-utils/-/motion-utils-12.39.0.tgz", + "integrity": "sha512-8nadJAJjTtqRkmRF36FoJTrywK9nnFmnPwnSMyxaOCU7GDjN9RTMJIxx9De8ErM+vpPhMccr/6fo5WciyQLnMQ==", + "license": "MIT" + }, "node_modules/mrmime": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz", diff --git a/package.json b/package.json index 7f1183a8da7..39cbc867412 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "docusaurus-plugin-sass": "^0.2.6", "js-yaml": "^4.2.0", "leva": "^0.10.1", + "motion": "^12.40.0", "playcanvas": "^2.19.6", "prism-react-renderer": "^2.4.1", "raw-loader": "^4.0.2", diff --git a/sidebars.js b/sidebars.js index 30aa984836f..25566ec27e9 100644 --- a/sidebars.js +++ b/sidebars.js @@ -479,6 +479,8 @@ const sidebars = { id: 'user-manual/react/examples/index', }, items: [ + 'user-manual/react/examples/model-viewer', + 'user-manual/react/examples/motion', 'user-manual/react/examples/physics', ] }, diff --git a/src/components/playcanvas-react/examples/ModelViewerExample.jsx b/src/components/playcanvas-react/examples/ModelViewerExample.jsx new file mode 100644 index 00000000000..bd0a222fed8 --- /dev/null +++ b/src/components/playcanvas-react/examples/ModelViewerExample.jsx @@ -0,0 +1,66 @@ +import { Application, Entity } from '@playcanvas/react'; +import { Camera, Environment, Render, Script } from '@playcanvas/react/components'; +import { useEnvAtlas, useModel } from '@playcanvas/react/hooks'; +import { CameraControls } from 'playcanvas/scripts/esm/camera-controls.mjs'; +import { Vec2 } from 'playcanvas'; +import AutoRotate from '../AutoRotate'; +import Grid from '../Grid'; +import StaticPostEffects from '../PostEffects'; +import ShadowCatcher from '../ShadowCatcher'; + +const OrbitControls = ({ zoomRange = [1, 10], pitchRange = [-90, -5], ...props }) => ( +