diff --git a/.vscode/dictionaries/code-entities.txt b/.vscode/dictionaries/code-entities.txt index adee22bdfe3d373..a8043f1661da887 100644 --- a/.vscode/dictionaries/code-entities.txt +++ b/.vscode/dictionaries/code-entities.txt @@ -168,6 +168,7 @@ daala dangi dataidx deviceproximity +DEVICETYPE devtools.aboutdebugging devtools.errorconsole DfltDwnld @@ -627,6 +628,7 @@ PINGOTHER pjpeg PlatformNaclArch platformversion +playcanvas pmatrix pmax pmin diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/index.md b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/index.md index 24d3de4f0026c53..082a86485007918 100644 --- a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/index.md +++ b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/index.md @@ -9,68 +9,67 @@ Instead of coding everything from scratch you can also use the online **PlayCanv ## Creating an account -The PlayCanvas Editor is free — all you have to do to begin with is [register](https://login.playcanvas.com/signup) your account and log in: +The PlayCanvas Editor is free to use for public projects — all you have to do to begin with is [sign up](https://login.playcanvas.com/signup) for an account and log in. -![PlayCanvas Editor - Login](playcanvas-editor-login.png) - -When you first sign up, you are taken straight into the editor and given a simple starter tutorial involving editing a 3D rolling ball game. You can finish this before you continue our tutorial if you like. When you are ready to continue with our tutorial, go to your canvas homepage — for example mine is `https://playcanvas.com/end3r`. Here's what the page looks like — you can create projects and manage them, change their settings etc. +Once you're logged in, you'll see your projects dashboard at `https://playcanvas.com/editor`. This is where you can create projects and manage them, change their settings, etc. ## Creating a new project -Start a brand new project by clicking on the _New_ button: +Start a brand new project by clicking on the _New project_ button in the sidebar: ![PlayCanvas Editor - Panel](playcanvas-editor-panel.png) The resulting dialog box will show a few different options. There are starter kits available, but we don't want to load models or start a platform game. -1. We want to start small, so we will use the empty project — click on the Blank Project option and enter a name for it (we are using "MDN Games demo".) +1. We want to start small, so we will use a blank project — click on the _Blank Project_ option and enter a name for it (we are using "MDN Games demo"). 2. Enter a description if you want — it is optional. -3. Click _Create_ to have it created. +3. Click _Create project_ to have it created. ![PlayCanvas Editor - New project](playcanvas-editor-newproject.png) -Next you'll see your project's page — there's not much yet. By clicking the _Editor_ button we'll launch the online PlayCanvas editor where we'll create our scene with the shapes. Do this now. - -![PlayCanvas Editor - Project](playcanvas-editor-project.png) +Once the project is ready, click _Open project_ in the confirmation that appears. Your new project opens in the online PlayCanvas editor in a new browser tab, which is where we'll create our scene with the shapes. ## Creating the scene -Here's how the scene looks initially in the editor. Even though it's a blank new project we don't have to start entirely from scratch — the camera and directional light are prepared already, so you don't have to worry about them. +Here's how the scene looks initially in the editor: ![PlayCanvas Editor - Scene](playcanvas-editor-scene.png) -Now onto the creative part. To add an entity to the scene you have to click on the big plus button located in the top left area of the editor, next to the Hierarchy text. When hovering over that button with your mouse the label will say 'Add Entity' — that's exactly what we want to do. An Entity is any object used in the scene — it can be an object like a box, cylinder or cone, but it can also be a camera, light or sound source. After clicking the button you'll see a dropdown list containing a lot of various entities to choose from. Go ahead and click _Box_ — it will be added to the scene. +Even though it's a blank new project we don't have to start entirely from scratch — the camera and directional light are prepared already, so you don't have to worry about them. +The scene also contains a box and a ground plane. We'll create our own shapes, so select the _Box_ and _Plane_ entities in the _Hierarchy_ panel (hold Ctrl to select both) and press Delete to remove them. + +Now onto the creative part. To add an entity to the scene you have to click on the plus button located at the top of the _Hierarchy_ panel. When hovering over that button with your mouse the label will say 'Add Entity' — that's exactly what we want to do. An Entity is any object used in the scene — it can be an object like a box, cylinder or cone, but it can also be a camera, light or sound source. After clicking the button you'll see a menu containing a lot of various entities to choose from. Go ahead and select _3D_ > _Box_ — it will be added to the scene. ![PlayCanvas Editor - New box](playcanvas-editor-newbox.png) -The box is created with the default values — width, height and depth are set to 1, and it is placed in the middle of the scene. You can drag it around or apply new values in the right panel. +The box is created with the default values — width, height and depth are set to 1, and it is placed in the middle of the scene. You can drag it around or apply new values in the _Inspector_ panel on the right. ![PlayCanvas Editor - Box](playcanvas-editor-box.png) -To add some colors to the scene we need a new material that will be used on the newly created box. Click on the plus button in the _Assets_ tab, and click on the _Material_ option in the dropdown list that appears to create a new material. +To add some colors to the scene we need a new material that will be used on the newly created box. Click on the plus button in the _Assets_ panel, and click on the _Material_ option in the menu that appears to create a new material. ![PlayCanvas Editor - New material](playcanvas-editor-newmaterial.png) -Click on your new material in the assets tab and its entity inspector will appear on the right-hand side of the display. Now edit the _Name_ text field to give it a unique name (we've chosen _boxMaterial_). A unique name will help us remember what this material is for — we will add more later! +Click on your new material in the _Assets_ panel and its properties will appear in the _Inspector_ panel on the right-hand side of the display. Now edit the _Name_ text field to give it a unique name (we've chosen _boxMaterial_). A unique name will help us remember what this material is for — we will add more later! ![PlayCanvas Editor - Box material](playcanvas-editor-boxmaterial.png) -To change its color we'll use the _Diffuse_ option in the entity inspector. Click _Diffuse_, then select the colored box next to the Color label — it will open a {{glossary("color wheel")}}. From here you can click your desired color or enter it in the bottom text field as a hex value. We've chosen a blue color with a hex value of `0095DD` — enter this code in the text field and press return for it to be accepted. +To change its color we'll use the _Diffuse_ section of the material's properties. Expand _Diffuse_, then select the colored box next to the _Color_ label — it will open a color picker. From here you can click your desired color or enter it in the bottom text field as a hex value. We've chosen a blue color with a hex value of `0095DD` — enter this code in the text field and press return for it to be accepted. > [!NOTE] > Yes, you read that right — you need to enter the hex value without the hash/pound symbol. ![PlayCanvas Editor - Diffuse color](playcanvas-editor-diffusecolor.png) -Now we can apply the colored material to the shape by clicking and dragging its icon from the bottom part of the screen (the little dot on the left-hand side of the material's name — it can be a bit fiddly to select; just persevere) onto the box on the scene. +Now we can apply the colored material to the shape by clicking and dragging its thumbnail from the _Assets_ panel at the bottom of the screen onto the box in the scene. The box turns blue: ![PlayCanvas Editor - Box drop](playcanvas-editor-boxdrop.png) -So, at this point we've created a blue box. Click on the box to bring up its entity sidebar — you'll see options for changing its position, rotation, and scale. Try applying the rotation values X: 10 and Y: 20. +So, at this point we've created a blue box. Click on the _Box_ entity in the _Hierarchy_ panel to show its properties in the _Inspector_ — you'll see options for changing its position, rotation, and scale. Try applying the rotation values X: 10 and Y: 20. ![PlayCanvas Editor - Rotate](playcanvas-editor-rotate.png) -Now click on the play arrow in the top right corner of the scene to launch and render the scene — it will be opened in a separate browser tab. +Now click on the _Launch_ button (the play icon) in the top right corner of the viewport to launch and render the scene — it will be opened in a separate browser tab. ![PlayCanvas Editor - Launch](playcanvas-editor-launch.png) @@ -82,51 +81,58 @@ This looks great! Let's add more shapes to the scene to make it look more intere To make way for more shapes, move the box to the left to make some room for the next shape. You can do this by giving it an X position value of -2. -Adding other shapes involves a very similar process to adding the box. Click on the Root folder in the hierarchy panel (to make sure that the new shape appears in the root, and not as a child of the Box) then Click on the big _Add Entity_ (plus) button and select cylinder from the dropdown list — it will add a new cylinder shape to the scene. +Adding other shapes involves a very similar process to adding the box. Click on the _Root_ entity in the _Hierarchy_ panel (to make sure that the new shape appears in the root, and not as a child of the Box) then click on the _Add Entity_ (plus) button and select _3D_ > _Cylinder_ from the menu — it will add a new cylinder shape to the scene. ![PlayCanvas Editor - Cylinder](playcanvas-editor-cylinder.png) Now follow the same steps as we did before when coloring the cube: -- Create a new material using the _Add Asset_ (plus) button. -- Make sure the New Material in the Assets panel is selected, to bring up the entity inspector. +- Create a new material using the plus button in the _Assets_ panel. +- Make sure the new material in the _Assets_ panel is selected, to show its properties in the _Inspector_. - Give the material a new name, along the lines of `cylinderMaterial`. -- Click diffuse, then click the color picker — give it an orange color (we used FF9500.) -- Drag and drop the `cylinderMaterial` icon onto the cylinder object on the screen to apply that color. +- Expand _Diffuse_, then click the color picker — give it an orange color (we used `FF9500`). +- Drag and drop the `cylinderMaterial` thumbnail onto the cylinder object on the screen to apply that color. ![PlayCanvas Editor - Cylinder material](playcanvas-editor-cylindermaterial.png) -Follow the same approach again to add a cone to the scene, giving it a grayish color (we used `#EAEFF2`.) You should now have three shapes on your scene, something like the below screenshot. +Follow the same approach again to add a cone to the scene, giving it a grayish color (we used `#EAEFF2`) and an X position value of 2. You should now have three shapes on your scene, something like the below screenshot. ![PlayCanvas Editor - Cone](playcanvas-editor-cone.png) ## Animating our scene -Animating 3D models might be considered an [advanced](https://developer.playcanvas.com/en/tutorials/anim-blending/) thing to do, but all we want to do is to control a few properties of a given object — we can use a script component to do that. Click on the plus button in the Assets panel, select the Script option, and name your new script file `boxAnimation.js`. +Animating 3D models might be considered an [advanced](https://developer.playcanvas.com/tutorials/anim-blending/) thing to do, but all we want to do is to control a few properties of a given object — we can use a script component to do that. Click on the plus button in the _Assets_ panel, select the _Script_ option, and name your new script file `boxAnimation.mjs`. The `.mjs` extension tells the editor to create the script as a JavaScript module, which is the recommended way to write PlayCanvas scripts. ![PlayCanvas Editor - Box animation](playcanvas-editor-boxanimation.png) If you double click on it, you'll be moved to a code editor. As you can see, the file contains some boilerplate code already: ```js -pc.script.create("boxAnimation", (app) => { - class BoxAnimation { - constructor(entity) { - this.entity = entity; - } - - // Called once after all resources are loaded and before the first update - initialize() {} - - // Called every frame, dt is time in seconds since last update - update(dt) {} - } - - return BoxAnimation; -}); +import { Script } from "playcanvas"; + +/** + * The {@link https://api.playcanvas.com/classes/Engine.Script.html | Script} class is + * the base class for all PlayCanvas scripts. Learn more about writing scripts in the + * {@link https://developer.playcanvas.com/user-manual/scripting/ | scripting guide}. + */ +export class BoxAnimation extends Script { + static scriptName = "boxAnimation"; + + /** + * Called when the script is about to run for the first time. + */ + initialize() {} + + /** + * Called for enabled (running state) scripts on each tick. + * + * @param {number} dt - The delta time in seconds since the last frame. + */ + update(dt) {} +} ``` -The most interesting part is the `update()` function, which is where we can put any code that we want repeated on every frame. Add the following line inside this function, to rotate the cube on every frame: +The script is a class that extends the engine's `Script` class, and its `scriptName` is the name that the editor uses to identify it. The most interesting part is the `update()` method, which is where we can put any code that we want repeated on every frame. Add the following line inside this method, to rotate the cube on every frame: ```js this.entity.rotate(dt * 10, dt * 20, dt * 30); @@ -134,10 +140,11 @@ this.entity.rotate(dt * 10, dt * 20, dt * 30); In the line above `this.entity` refers to the object to which the script will be attached (the box); using the `dt` variable, which contains the delta time passed since the previous frame, we can rotate the box by a different amount around all three axes. -1. Save the changes using the Save button in the top right of the code editor, then return to the main editor tab. Here, follow these steps: -2. Be sure you have the box selected on the scene. -3. Click on _Add component_, then _Script_ in the entity inspector. -4. At the bottom of the screen you can see the list of scripts available — for now there's only `boxAnimation.js` — clicking it will add the animation script to the box object. +Save the changes using the _Save File_ option in the code editor's _File_ menu (or by pressing Ctrl + S), then return to the main editor tab. Here, follow these steps: + +1. Be sure you have the box selected on the scene. +2. Click on _Add Component_, then _Script_ in the _Inspector_. +3. In the new _Script_ component, click _Add Script_ and choose `boxAnimation` from the list of available scripts — this will add the animation script to the box object. ![PlayCanvas Editor - Box script](playcanvas-editor-boxscript.png) @@ -146,37 +153,37 @@ In the line above `this.entity` refers to the object to which the script will be Now we'll do the same steps for cylinder. First: 1. Create a new Script asset. -2. Name it `cylinderAnimation.js`. +2. Name it `cylinderAnimation.mjs`. 3. Double click the script icon to launch the code editor. -This time instead of rotating the object we will try to scale it. For that we'll need a timer to store the total amount of time passed since the start of the animation. Add this code to the `initialize()` function: +This time instead of rotating the object we will try to scale it. For that we'll need a timer to store the total amount of time passed since the start of the animation. Add this code to the `initialize()` method: ```js this.timer = 0; ``` -And those two lines to the `update()` function: +And those two lines to the `update()` method: ```js this.timer += dt; this.entity.setLocalScale(1, Math.abs(Math.sin(this.timer)), 1); ``` -The `setLocalScale()` method applies the given values to the X, Y and Z axes of the object. In our case we're modifying the scale of the cylinder on the Y axis, giving it as a value the `Math.sin()` of the timer, with `Math.abs()` applied to the result of that to have the values always above zero (0-1; sin values are normally between -1 and 1.) This gives us a nice scaling effect as a result. +The `setLocalScale()` method applies the given values to the X, Y and Z axes of the object. In our case we're modifying the scale of the cylinder on the Y axis, giving it as a value the `Math.sin()` of the timer, with `Math.abs()` applied to the result of that to have the values always above zero (0-1; sin values are normally between -1 and 1). This gives us a nice scaling effect as a result. -Remember to add the `cylinderAnimation.js` file to the Cylinder object to apply the given animations. +Remember to add the `cylinderAnimation` script to the Cylinder object to apply the given animations. ### The cone -Time to play with the last object — the cone. Create a `coneAnimation.js` file and double click it to open it in the editor. +Time to play with the last object — the cone. Create a `coneAnimation.mjs` file and double click it to open it in the editor. -Next, add the following line to the `initialize()` function: +Next, add the following line to the `initialize()` method: ```js this.timer = 0; ``` -To move the cone up and down we will use the `setPosition()` method — add the code below to the `update()` function: +To move the cone up and down we will use the `setPosition()` method — add the code below to the `update()` method: ```js this.timer += dt; @@ -185,7 +192,7 @@ this.entity.setPosition(2, Math.sin(this.timer * 2), 0); The position of the cone will be animated on each frame by being passed the `Math.sin()` value of the `timer` at each point in time — we have doubled the `this.timer` value to make it move higher. -Add the `coneAnimation.js` script to the cone object, as before. +Add the `coneAnimation` script to the cone object, as before. ## Test the demo out diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-box.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-box.png index a5cffc5dd35eaab..77a0c5799bf1ceb 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-box.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-box.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxanimation.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxanimation.png index af22f21e883e446..fd859f4f34e667e 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxanimation.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxanimation.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxdrop.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxdrop.png index f0c9c11e977d6d1..8bde36e656339c8 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxdrop.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxdrop.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxmaterial.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxmaterial.png index f5112b2aee64d23..15fe3a9fb355c44 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxmaterial.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxmaterial.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxrender.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxrender.png index f033091140136c9..ef3471fbd634d91 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxrender.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxrender.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxscript.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxscript.png index 8668bb53ba31c5b..9a3b4cb6bbca48c 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxscript.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-boxscript.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cone.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cone.png index 76292b78bede145..ad73768ed1c71d5 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cone.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cone.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cylinder.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cylinder.png index 7d5abc170b8d3f1..7dfc987e0ec7b9c 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cylinder.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cylinder.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cylindermaterial.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cylindermaterial.png index 15ee83d4a6b0d9d..86ec26f1c147cce 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cylindermaterial.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-cylindermaterial.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-diffusecolor.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-diffusecolor.png index 5b4d6fd63b3c2b6..0539a8d2c1b65c3 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-diffusecolor.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-diffusecolor.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-launch.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-launch.png index a59a824ca4b4840..2db4a0c7a525407 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-launch.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-launch.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-login.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-login.png deleted file mode 100644 index 378cd7a55b918cb..000000000000000 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-login.png and /dev/null differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newbox.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newbox.png index 9a66dd45b730755..48d7bfea3db1b48 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newbox.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newbox.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newmaterial.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newmaterial.png index b9fc944ee46762c..d210dc0b716141e 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newmaterial.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newmaterial.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newproject.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newproject.png index 9d6a87681891437..cfc1367fc7230e7 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newproject.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-newproject.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-panel.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-panel.png index 9a642eb80f0b84f..ba1697c2a798711 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-panel.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-panel.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-project.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-project.png deleted file mode 100644 index 4234f0cc51f267b..000000000000000 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-project.png and /dev/null differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-rotate.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-rotate.png index 30f4f7f3f0c2a0c..ff9a51def139d14 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-rotate.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-rotate.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-scene.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-scene.png index 77c57205d8d05e5..6f99eca39c95623 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-scene.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-scene.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-shapes.png b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-shapes.png index 369172fec955ff1..985d94a70823c9d 100644 Binary files a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-shapes.png and b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/editor/playcanvas-editor-shapes.png differ diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/engine/index.md b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/engine/index.md index 34a7c32b95ba75e..cbdf59fb8083f27 100644 --- a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/engine/index.md +++ b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/engine/index.md @@ -5,28 +5,39 @@ page-type: guide sidebar: games --- -Built for modern browsers, **PlayCanvas** is a fully-featured 3D game engine with resource loading, an entity and component system, advanced graphics manipulation, collision and physics engine (built with [ammo.js](https://github.com/kripken/ammo.js/)), audio, and facilities to handle control inputs from various devices (including gamepads). +Built for modern browsers, **PlayCanvas** is a fully-featured 3D game engine that renders with [WebGL 2](/en-US/docs/Web/API/WebGL_API) or [WebGPU](/en-US/docs/Web/API/WebGPU_API). +It comes with resource loading, an entity and component system, advanced graphics features, a physics engine (built with [ammo.js](https://github.com/kripken/ammo.js/)), audio, and facilities to handle input from various devices (including gamepads). That's quite an impressive list of features — let's see some in action. We build a basic demo first — a cube rendered on the screen. If you have already worked through our [Building up a basic demo with Three.js](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_Three.js) article (or you are familiar with other 3D libraries) you'll notice that PlayCanvas has similar concepts: camera, light and objects. > [!NOTE] -> This guide was last updated in November 2024, and is compatible with PlayCanvas version `2.2.2`. +> This guide was last updated in November 2026, and is compatible with PlayCanvas version `2.24.2`. ## Development setup To start developing with PlayCanvas, make sure you are using a modern browser with good [WebGL](/en-US/docs/Web/API/WebGL_API) support. -It's useful to keep the [PlayCanvas documentation](https://developer.playcanvas.com/en/user-manual/) in a separate tab while you're working. +It's useful to keep the [PlayCanvas documentation](https://developer.playcanvas.com/user-manual/) open in a separate tab while you're working. -If you're developing locally in an IDE, make a directory to store your experiments in and save a copy of the [latest PlayCanvas engine](https://code.playcanvas.com/playcanvas-latest.js) inside that directory. -Alternatively, you can load PlayCanvas from a CDN: +The PlayCanvas engine is published as an ES module, which you can import from a CDN or install using npm. +If you're including it from a CDN, you can use the following URL in your HTML: ```html - + ``` -If you don't want to develop locally, you can use an online editor such as [CodePen](https://codepen.io/) or [JSFiddle](https://jsfiddle.net/). -With these editors, you can add `https://cdn.babylonjs.com/babylon.js` as a JavaScript source so it's available in your code. +A Node.js setup with PlayCanvas installed as a dependency is convenient if you want to develop against specific PlayCanvas versions, and it lets you use a build tool to bundle your code for production: + +```bash +npm install --save playcanvas +npm install --save-dev vite # For development +npx vite +``` + +Whichever way you choose, you'll need to load your page from a local web server, such as the one that `npx vite` starts, rather than opening the file directly. +See [Using the Engine Standalone](https://developer.playcanvas.com/user-manual/engine/standalone/) in the PlayCanvas documentation for more setup options. ### HTML starter for PlayCanvas @@ -51,13 +62,17 @@ If you're building your project locally in an IDE, here's the HTML structure to - - - - - - + @@ -65,28 +80,50 @@ If you're building your project locally in an IDE, here's the HTML structure to ``` -It contains information like the document {{htmlelement("title")}}, and some CSS to set the width and height of the {{htmlelement("canvas")}} element (that PlayCanvas will use) to 100%, so that it will fill the entire available viewport space. The first {{htmlelement("script")}} element includes the PlayCanvas library in the page; we will write our example code in the second one. There is one variable already included, which will store a reference to the {{htmlelement("canvas")}} element. +It contains information like the document {{htmlelement("title")}}, and some CSS to set the width and height of the {{htmlelement("canvas")}} element (that PlayCanvas will use) to 100%, so that it will fill the entire available viewport space. +The [import map](/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap) tells the browser where to load the `playcanvas` module from, so that we can import it by name; if you installed PlayCanvas using npm and are using Vite, you can remove the import map. +We will write our example code in the module script, which imports everything the engine exports into a `pc` object. +There is one variable already included, which will store a reference to the {{htmlelement("canvas")}} element. If you're developing in an IDE, copy this code to a new text file and save it in your working directory as `index.html`. ## PlayCanvas application -To begin developing our game we have to create the PlayCanvas application first (using the given {{htmlelement("canvas")}} element), and then start the update loop. Add the following code to the bottom of your second {{htmlelement("script")}} element: +To begin developing our game we have to create the PlayCanvas application first (using the given {{htmlelement("canvas")}} element), and then start the update loop. Add the following code to the bottom of your module script: ```js const app = new pc.Application(canvas); app.start(); ``` -The `pc` global object contains all the PlayCanvas functions available in the engine. +The `pc` object contains all the classes, functions, and constants available in the engine. -Next, we'll set the Canvas to fill the window, and automatically change its resolution to be the same as the Canvas size. Again, add the following lines at the bottom of your script. +Next, we'll set the canvas to fill the window, and automatically change its resolution to be the same as the canvas size. +PlayCanvas doesn't listen for the window being resized, so we also need to call `resizeCanvas()` whenever that happens. +Again, add the following lines at the bottom of your script: ```js app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW); app.setCanvasResolution(pc.RESOLUTION_AUTO); + +window.addEventListener("resize", () => app.resizeCanvas()); ``` +### Rendering with WebGPU + +By default, `pc.Application` renders with WebGL 2. +If you'd like to use WebGPU in browsers that support it, create the graphics device first and pass it to the application: + +```js +const device = await pc.createGraphicsDevice(canvas, { + deviceTypes: [pc.DEVICETYPE_WEBGPU], +}); +const app = new pc.Application(canvas, { graphicsDevice: device }); +``` + +If WebGPU isn't available, PlayCanvas automatically falls back to WebGL 2. +The rest of this tutorial works the same way with either graphics API. + ## Camera Now that the setup code is in place, we need to think about implementing the standard scene components: camera, lights and objects. Let's start with the camera — add these lines to your code, below the previous ones. @@ -103,6 +140,7 @@ camera.setPosition(0, 0, 7); The code above will create a new `Entity`. An Entity is any object used in the scene — it can be an object like a box, cylinder or cone, but it can also be a camera, light or sound source. +What an entity does depends on the components that are added to it. Then it adds a `camera` component to it with the light gray `clearColor` — the color will be visible as the background. Next, the `camera` object is added to the root of our application and positioned to be 7 units away from the center of the scene on the `z` axis. This allows us to make some space to visualize the objects that we will create later on. @@ -112,23 +150,24 @@ Try saving the file and loading it in your browser. You should now see a gray wi ## Geometry -Now the scene is properly rendering we can start adding 3D shapes to it. To speed up development PlayCanvas provides a bunch of predefined primitives that you can use to create shapes instantly in a single line of code. There are cubes, spheres, cylinders and more complicated shapes available. Drawing everything for given shape is taken care of by the engine, so we can focus on the high-level coding. Let's start by defining the geometry for a cube shape — add the following new code below your previous additions: +Now the scene is properly rendering we can start adding 3D shapes to it. To speed up development PlayCanvas provides a bunch of predefined primitives that you can use to create shapes instantly in a single line of code. There are boxes, spheres, cylinders, cones, capsules, planes, and tori available. Drawing everything for a given shape is taken care of by the engine, so we can focus on the high-level coding. Let's start by defining the geometry for a cube shape — add the following new code below your previous additions: ```js const box = new pc.Entity(); -box.addComponent("model", { type: "box" }); +box.addComponent("render", { type: "box" }); app.root.addChild(box); box.rotate(10, 15, 0); ``` -It will create an `Entity` with the `box` model component and add it to the root of the application, our scene. We also rotate the box a bit to show that it's actually a 3D cube and not a square. +It will create an `Entity` with a `render` component of type `box`, and add it to the root of the application, our scene. We also rotate the box a bit to show that it's actually a 3D cube and not a square. The cube is visible, but it is completely dark. To make it look better we need to shine some light onto it. ## Lights -The basic light types in PlayCanvas are directional and ambient. The first type is a directional light placed somewhere on the scene while the second one reflects the light from the first type, so it looks more natural; this can be set globally. Again, add the new code below your previous additions. +PlayCanvas supports directional, omni (point), and spot lights, as well as an ambient light that is set for the whole scene. +A directional light shines in a single direction across the entire scene, like sunlight, while the ambient light lights every surface equally, so the sides of objects facing away from the directional light don't look completely black. Again, add the new code below your previous additions. ```js const light = new pc.Entity(); @@ -137,30 +176,30 @@ app.root.addChild(light); light.rotate(45, 0, 0); ``` -It will create a light `Entity` component and add it to the scene. We can rotate the light on the `x` axis to make it shine on more than one side of the cube. It's time to add the ambient light: +It will create a light `Entity` and add it to the scene; a `light` component is directional by default. We can rotate the light on the `x` axis to make it shine on more than one side of the cube. It's time to add the ambient light: ```js app.scene.ambientLight = new pc.Color(0.2, 0.2, 0.2); ``` -The code above assign a dark gray ambient light for the whole scene. The box looks better now, but it could get some colors to look even better - for that we need to create material for it. +The code above assigns a dark gray ambient light for the whole scene. The box looks better now, but it could get some colors to look even better - for that we need to create a material for it. ## Material -This example uses a material called [Standard material](https://api.playcanvas.com/engine/classes/StandardMaterial.html), which is the main, general purpose material that is most often used for rendering. +This example uses a material called [Standard material](https://api.playcanvas.com/engine/classes/StandardMaterial.html), which is the main, general-purpose, physically based material that is most often used for rendering. Add the following lines to your code: ```js const boxMaterial = new pc.StandardMaterial(); boxMaterial.diffuse.set(0, 0.58, 0.86); boxMaterial.update(); -box.model.model.meshInstances[0].material = boxMaterial; +box.render.material = boxMaterial; ``` By diffusing the light on the object, we can give it its own color — we'll choose a nice familiar blue. In PlayCanvas, the color channel values are provided as floats in the range `0-1`, instead of integers of `0-255` as you might be used to using on the Web. -After the material is created and its color is set, it has to be updated so that our changes are applied. Then all we need to do is set the `box`'s material to the newly created `boxMaterial`. +After the material is created and its color is set, it has to be updated so that our changes are applied. Then all we need to do is set the `material` of the `box`'s render component to the newly created `boxMaterial`. ## PlayCanvas shape example @@ -170,46 +209,43 @@ You can click "Play" to view and edit the code in the MDN Playground: ```html hidden live-sample___play-canvas-intro - -``` - -```js hidden live-sample___play-canvas-intro -const canvas = document.getElementById("application-canvas"); - -// Start and init Application -const app = new pc.Application(canvas); -app.start(); -app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW); -app.setCanvasResolution(pc.RESOLUTION_AUTO); - -// Create camera -const camera = new pc.Entity(); -camera.addComponent("camera", { clearColor: new pc.Color(0.8, 0.8, 0.8) }); -app.root.addChild(camera); -camera.setPosition(0, 0, 7); - -// Create cube -const box = new pc.Entity(); -box.addComponent("model", { type: "box" }); -app.root.addChild(box); -box.rotate(10, 15, 0); - -// Create light -const light = new pc.Entity(); -light.addComponent("light"); -light.rotate(45, 0, 0); -app.root.addChild(light); -app.scene.ambientLight = new pc.Color(0.2, 0.2, 0.2); - -// Create cube's material -const boxMaterial = new pc.StandardMaterial(); -boxMaterial.diffuse.set(0, 0.58, 0.86); -boxMaterial.update(); -box.model.model.meshInstances[0].material = boxMaterial; - -window.addEventListener("resize", () => { - app.resizeCanvas(canvas.width, canvas.height); -}); + ``` ```css hidden live-sample___play-canvas-intro @@ -241,18 +277,18 @@ Add the following lines at the bottom of your JavaScript code: ```js const cylinder = new pc.Entity(); -cylinder.addComponent("model", { type: "cylinder" }); +cylinder.addComponent("render", { type: "cylinder" }); app.root.addChild(cylinder); cylinder.rotate(15, 0, 0); ``` -This looks very similar to the code we used for creating a cube, but instead of the `box` component we are adding a `cylinder`. It is also rotated around the `x` axis to show it's actually a 3D shape. To make the cylinder have a color, let's say yellow, we need to create the material for it, as before. Add the following lines: +This looks very similar to the code we used for creating a cube, but instead of the `box` type, the render component has the `cylinder` type. It is also rotated around the `x` axis to show it's actually a 3D shape. To make the cylinder have a color, let's say yellow, we need to create the material for it, as before. Add the following lines: ```js const cylinderMaterial = new pc.StandardMaterial(); cylinderMaterial.diffuse.set(1, 0.58, 0); cylinderMaterial.update(); -cylinder.model.model.meshInstances[0].material = cylinderMaterial; +cylinder.render.material = cylinderMaterial; ``` ### Cone @@ -261,14 +297,14 @@ Creating a cone and its material is done in almost exactly the same way as we di ```js const cone = new pc.Entity(); -cone.addComponent("model", { type: "cone" }); +cone.addComponent("render", { type: "cone" }); app.root.addChild(cone); cone.translate(2, 0, 0); const coneMaterial = new pc.StandardMaterial(); coneMaterial.diffuse.set(0.9, 0.9, 0.9); coneMaterial.update(); -cone.model.model.meshInstances[0].material = coneMaterial; +cone.render.material = coneMaterial; ``` The code above will create a new `cone`, add it to the `app` and move it by 2 units to the right so it's not overlapping the cylinder. Then the material is created, given a gray color, and assigned to the cone `Entity`. @@ -287,7 +323,7 @@ app.on("update", (deltaTime) => { }); ``` -The callback takes the `deltaTime` as the parameter, so we have the relative time that has passed since the previous invocation of this update. For time based animations we'll use a `timer` variable that will store the time that has passed since the start of the app by adding the `deltaTime` to it on every update. +The callback takes the `deltaTime` as the parameter, so we have the relative time (in seconds) that has passed since the previous invocation of this update. For time-based animations we'll use a `timer` variable that will store the time that has passed since the start of the app by adding the `deltaTime` to it on every update. ### Rotation @@ -297,7 +333,7 @@ Rotating is quite easy — all you need to do is to add a defined value to the g box.rotate(deltaTime * 10, deltaTime * 20, deltaTime * 30); ``` -It will rotate the `box` by `deltaTime*10` on the `x` axis, `deltaTime*20` on the `y` axis and `deltaTime*30` on the `z` axis, on very frame — giving us a smooth animation. +It will rotate the `box` by `deltaTime*10` degrees on the `x` axis, `deltaTime*20` degrees on the `y` axis and `deltaTime*30` degrees on the `z` axis, on every frame — giving us a smooth animation. ### Scaling @@ -307,7 +343,7 @@ We can also scale a given object — there's a function for that called `setLoca cylinder.setLocalScale(1, Math.abs(Math.sin(timer)), 1); ``` -Here we are using `Math.sin` to scale the cylinder in a cycle, bigger and smaller again. We're wrapping the `y` scale value in `Math.abs` to pass the absolute values (greater or equal to 0); `sin` varies between -1 and 0, and for negative values the cylinder scaling can render unexpectedly (in this case it looks black half the time.) +Here we are using `Math.sin` to scale the cylinder in a cycle, bigger and smaller again. We're wrapping the `y` scale value in `Math.abs` to pass the absolute values (greater or equal to 0); `sin` varies between -1 and 1, and for negative values the cylinder scaling can render unexpectedly (in this case it looks black half the time). Now onto the movement part. @@ -328,76 +364,77 @@ You can click "Play" to edit the example in the MDN Playground: ```html hidden live-sample___play-canvas-animation - -``` - -```js hidden live-sample___play-canvas-animation -const canvas = document.getElementById("application-canvas"); - -// Start and init Application -const app = new pc.Application(canvas); -app.start(); -app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW); -app.setCanvasResolution(pc.RESOLUTION_AUTO); - -// Create camera -const camera = new pc.Entity(); -camera.addComponent("camera", { clearColor: new pc.Color(0.8, 0.8, 0.8) }); -app.root.addChild(camera); -camera.setPosition(0, 0, 7); - -// Create cube -const box = new pc.Entity(); -box.addComponent("model", { type: "box" }); -app.root.addChild(box); -box.rotate(10, 15, 0); - -// Create light -const light = new pc.Entity(); -light.addComponent("light"); -light.rotate(45, 0, 0); -app.root.addChild(light); -app.scene.ambientLight = new pc.Color(0.2, 0.2, 0.2); - -// Create cube's material -const boxMaterial = new pc.StandardMaterial(); -boxMaterial.diffuse.set(0, 0.58, 0.86); -boxMaterial.update(); -box.model.model.meshInstances[0].material = boxMaterial; -box.translate(-2, 0, 0); - -// Create cylinder -const cylinder = new pc.Entity(); -cylinder.addComponent("model", { type: "cylinder" }); -app.root.addChild(cylinder); -cylinder.rotate(15, 0, 0); - -// Create cylinder's material -const cylinderMaterial = new pc.StandardMaterial(); -cylinderMaterial.diffuse.set(1, 0.58, 0); -cylinderMaterial.update(); -cylinder.model.model.meshInstances[0].material = cylinderMaterial; - -// Create cone -const cone = new pc.Entity(); -cone.addComponent("model", { type: "cone" }); -app.root.addChild(cone); -cone.translate(2, 0, 0); - -// Create cone's material -const coneMaterial = new pc.StandardMaterial(); -coneMaterial.diffuse.set(0.9, 0.9, 0.9); -coneMaterial.update(); -cone.model.model.meshInstances[0].material = coneMaterial; - -// Animate shapes -let timer = 0; -app.on("update", (deltaTime) => { - timer += deltaTime; - box.rotate(deltaTime * 10, deltaTime * 20, deltaTime * 3); - cylinder.setLocalScale(1, Math.abs(Math.sin(timer)), 1); - cone.setPosition(2, Math.sin(timer * 2), 0); -}); + ``` ```css hidden live-sample___play-canvas-animation @@ -416,4 +453,5 @@ canvas { ## Summary Now you know the basics of PlayCanvas engine; happy experimentation! +To see what else the engine can do, browse the [PlayCanvas engine examples](https://playcanvas.com/examples), each of which includes its source code. You can continue reading the [PlayCanvas editor](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_PlayCanvas/editor) article, go back to the [Building up a basic demo with PlayCanvas](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_PlayCanvas) page, or go back a level higher to the main [3D Games on the Web](/en-US/docs/Games/Techniques/3D_on_the_web) page. diff --git a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/index.md b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/index.md index 66ca2889d91bd2a..8b2bc4aa7749662 100644 --- a/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/index.md +++ b/files/en-us/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_playcanvas/index.md @@ -5,7 +5,7 @@ page-type: guide sidebar: games --- -**PlayCanvas** is a popular 3D WebGL game engine, originally created by Will Eastcott and Dave Evans. It is [open sourced on GitHub](https://github.com/playcanvas/engine), with an [editor](https://developer.playcanvas.com/user-manual/editor/) available online and good [documentation](https://developer.playcanvas.com/en/). The online editor is free for public projects with up to two team members, but there are also [paid plans](https://playcanvas.com/plans) if you'd like to run a commercial private project with more developers. +**PlayCanvas** is a popular 3D game engine for the web, originally created by Will Eastcott and Dave Evans. It renders with [WebGL 2](/en-US/docs/Web/API/WebGL_API) or [WebGPU](/en-US/docs/Web/API/WebGPU_API), and it is [open source on GitHub](https://github.com/playcanvas/engine) under the MIT license, with a browser-based [editor](https://developer.playcanvas.com/user-manual/editor/) and good [documentation](https://developer.playcanvas.com/). The editor is free to use for public projects, and there are also [paid plans](https://playcanvas.com/plans) that add private projects, more storage, and team management. ![PlayCanvas website.](playcanvas-cover.png) @@ -15,20 +15,22 @@ PlayCanvas has a few well-known demos published that showcase its possibilities. - [Tanx](https://tanx.io/) is a multiplayer tank game where you can drive your tank around, shooting at other players as you go. - [Swooop](https://playcanv.as/p/JtL2iqIH) is a flying game where you pilot your plane around a magical island, collecting jewels and fuel as you go. -- Visualizations like the [Star Lord](https://playcanv.as/b/FQbBsJTd) and [BMW i8](https://playcanv.as/p/RqJJ9oU9) also take advantage of the engine and showcase what's possible. +- Visualizations like the [Star-Lord](https://playcanv.as/p/SA7hVBLt/) and [BMW i8](https://playcanv.as/p/RqJJ9oU9) also take advantage of the engine and showcase what's possible. ![A list of PlayCanvas demos: Tanx, Swooop, Star Lord, BMW i8.](playcanvas-demos.png) > [!NOTE] -> Check out the list of [featured demos](https://playcanvas.com/explore) to find more examples. +> Check out the list of [featured projects](https://playcanvas.com/explore) to find more examples, or browse the [engine examples](https://playcanvas.com/examples) to see individual features in action. ## Engine vs. editor -The engine itself can be used as a standard library by including its JavaScript file directly in your HTML, so you can start coding right away; in addition the PlayCanvas toolset comes with an online editor that you can use to drag and drop components onto the scene — a great way to create games and other apps requiring scenes if you're more of a designer than a coder. Those approaches are different but work equally well regarding achieving end goals. +The engine itself can be used as a standard library by importing it from a CDN or installing it with npm, so you can start coding right away. PlayCanvas also offers [React](https://developer.playcanvas.com/user-manual/react/) and [Web Components](https://developer.playcanvas.com/user-manual/web-components/) wrappers around the engine, if you'd rather build scenes declaratively. + +In addition, the PlayCanvas toolset comes with an online editor that you can use to drag and drop components onto the scene, and to edit it together with other people in real time — a great way to create games and other apps requiring scenes if you're more of a designer than a coder. Those approaches are different but work equally well regarding achieving end goals. ## PlayCanvas engine -Built for modern browsers, PlayCanvas is a fully-featured 3D game engine with resource loading, an entity and component system, advanced graphics manipulation, collision and physics engine (built with [ammo.js](https://github.com/kripken/ammo.js/)), audio, and facilities to handle control inputs from various devices (including gamepads). That's quite an impressive list of features — let's see some in action, check out the [Building up a basic demo with PlayCanvas engine](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_PlayCanvas/engine) for details. +Built for modern browsers, PlayCanvas is a fully-featured 3D game engine with resource loading, an entity and component system, advanced graphics features, a physics engine (built with [ammo.js](https://github.com/kripken/ammo.js/)), audio, and facilities to handle input from various devices (including gamepads). That's quite an impressive list of features — let's see some in action, check out the [Building up a basic demo with PlayCanvas engine](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_PlayCanvas/engine) for details. ## PlayCanvas editor diff --git a/files/en-us/games/techniques/3d_on_the_web/index.md b/files/en-us/games/techniques/3d_on_the_web/index.md index f6280da3630f3de..bba3b684695334f 100644 --- a/files/en-us/games/techniques/3d_on_the_web/index.md +++ b/files/en-us/games/techniques/3d_on_the_web/index.md @@ -54,7 +54,7 @@ Babylon.js is one of the most popular 3D game engines used by developers. As wit ### Building up a basic demo with PlayCanvas -PlayCanvas is a popular 3D WebGL game engine open-sourced on GitHub, with an editor available online and good documentation. See the [Building up a basic demo with PlayCanvas](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_PlayCanvas) subpage for higher-level details, and further articles showing how to create demos using the PlayCanvas library, and the online editor. +PlayCanvas is a popular 3D game engine for WebGL and WebGPU, open-sourced on GitHub, with an editor available online and good documentation. See the [Building up a basic demo with PlayCanvas](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_PlayCanvas) subpage for higher-level details, and further articles showing how to create demos using the PlayCanvas library, and the online editor. ### Building up a basic demo with Three.js