-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added esm example script * moved rotator script to examples only * Added attribute tag to defined tags * renamed esm to esm-script and hid example
- Loading branch information
Showing
5 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Script } from 'playcanvas'; | ||
|
||
class Rotator extends Script { | ||
/** | ||
* @attribute | ||
*/ | ||
angle = 0; | ||
|
||
update(dt) { | ||
this.angle += dt; | ||
this.entity.setLocalEulerAngles(this.angle * 10, this.angle * 20, this.angle * 30); | ||
} | ||
} | ||
|
||
export { Rotator }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// @config HIDDEN | ||
import * as pc from 'playcanvas'; | ||
import { deviceType, rootPath, fileImport } from 'examples/utils'; | ||
|
||
const { Rotator } = await fileImport(rootPath + '/static/assets/scripts/misc/rotator.mjs'); | ||
|
||
const canvas = /** @type {HTMLCanvasElement} */ (document.getElementById('application-canvas')); | ||
window.focus(); | ||
|
||
const gfxOptions = { | ||
deviceTypes: [deviceType], | ||
glslangUrl: rootPath + '/static/lib/glslang/glslang.js', | ||
twgslUrl: rootPath + '/static/lib/twgsl/twgsl.js' | ||
}; | ||
|
||
const device = await pc.createGraphicsDevice(canvas, gfxOptions); | ||
device.maxPixelRatio = Math.min(window.devicePixelRatio, 2); | ||
|
||
const createOptions = new pc.AppOptions(); | ||
createOptions.graphicsDevice = device; | ||
|
||
createOptions.componentSystems = [pc.RenderComponentSystem, pc.CameraComponentSystem, pc.LightComponentSystem, pc.ScriptComponentSystem]; | ||
createOptions.resourceHandlers = [pc.TextureHandler, pc.ContainerHandler]; | ||
|
||
const app = new pc.AppBase(canvas); | ||
app.init(createOptions); | ||
app.start(); | ||
|
||
// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size | ||
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW); | ||
app.setCanvasResolution(pc.RESOLUTION_AUTO); | ||
|
||
// Ensure canvas is resized when window changes size | ||
const resize = () => app.resizeCanvas(); | ||
window.addEventListener('resize', resize); | ||
app.on('destroy', () => { | ||
window.removeEventListener('resize', resize); | ||
}); | ||
|
||
// create box entity | ||
const box = new pc.Entity('cube'); | ||
box.addComponent('render', { | ||
type: 'box' | ||
}); | ||
box.addComponent('script'); | ||
box.script.create(Rotator); | ||
app.root.addChild(box); | ||
|
||
// create camera entity | ||
const camera = new pc.Entity('camera'); | ||
camera.addComponent('camera', { | ||
clearColor: new pc.Color(0.5, 0.6, 0.9) | ||
}); | ||
app.root.addChild(camera); | ||
camera.setPosition(0, 0, 3); | ||
|
||
// create directional light entity | ||
const light = new pc.Entity('light'); | ||
light.addComponent('light'); | ||
app.root.addChild(light); | ||
light.setEulerAngles(45, 0, 0); | ||
|
||
export { app }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,8 @@ | |
"error", | ||
{ | ||
"definedTags": [ | ||
"category" | ||
"category", | ||
"attribute" | ||
] | ||
} | ||
] | ||
|