fisrt commit

This commit is contained in:
2026-01-17 11:49:36 +03:00
commit b2dfe51b9f
5379 changed files with 4408602 additions and 0 deletions

View File

@ -0,0 +1,13 @@
var fs = require('fs-extra');
var source = './plugins/camera3d/dist/';
var dest = '../phaser3-examples/public/plugins/';
if (fs.existsSync(dest))
{
fs.copySync(source, dest, { overwrite: true });
}
else
{
console.log('Copy-to-Examples failed: Phaser 3 Examples not present at ../phaser3-examples');
}

30532
node_modules/phaser/plugins/camera3d/dist/camera3d.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

93
node_modules/phaser/plugins/camera3d/readme.md generated vendored Normal file
View File

@ -0,0 +1,93 @@
Phaser 3 Camera 3D Plugin
=========================
Note: As of 26th August 2020 this plugin is now considered deprecated and will not be supported any further. It has been fixed to work with the Phaser 3.50 release, but will not be updated beyond this. You're free to use it as you see fit, but please do not open issues about it on GitHub, thank you.
In Phaser 3.12 Camera 3D support was moved to its own external plugin.
There are two ways to use this in your games:
## 1. External Plugin
You can copy the `dist/camera3d.min.js` file to your project folder and preload it into Phaser:
```
function preload ()
{
this.load.scenePlugin('Camera3DPlugin', 'plugins/camera3d.min.js', 'Camera3DPlugin', 'cameras3d');
}
```
Then you can use it like usual.
## 2. Bundled Plugin
If you prefer you can configure Phaser to include it when it builds its dist files.
To do this you need to edit the webpack config files and change the following:
```
"typeof PLUGIN_CAMERA3D": JSON.stringify(false)
```
to
```
"typeof PLUGIN_CAMERA3D": JSON.stringify(true)
```
Then rebuild Phaser via webpack. The plugin will now be included by default and can be called from your game code.
## Using the Plugin
Here is a basic example of using the plugin. You can find many more in the Phaser 3 Examples repo in the [cameras/3D Camera](https://github.com/photonstorm/phaser3-examples/tree/master/public/src/camera/3D%20camera) folder.
```
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
scene: {
preload: preload,
create: create,
update: update
}
};
var camera;
var transform;
var game = new Phaser.Game(config);
function preload ()
{
this.load.scenePlugin('Camera3DPlugin', 'plugins/camera3d.min.js', 'Camera3DPlugin', 'cameras3d');
this.load.image('particle', 'assets/sprites/mushroom2.png');
}
function create ()
{
camera = this.cameras3d.add(85).setZ(300).setPixelScale(128);
var sprites = camera.createRect({ x: 4, y: 4, z: 16 }, { x: 48, y: 48, z: 32 }, 'particle');
// Our rotation matrix
transform = new Phaser.Math.Matrix4().rotateX(-0.01).rotateY(-0.02).rotateZ(0.01);
}
function update ()
{
camera.transformChildren(transform);
}
```
## Building the External Plugin
If you wish to edit the plugin use the following files:
`src/Camera3DPlugin.js` is the entry point for the external plugin. Edit this file if you're loading the plugin at run-time. Once you have finished making your changes, run the command `npm run plugin.cam3d` from the command-line to build a new version of the external plugin with Webpack.
## Changing the Bundled Plugin
`src/index.js` is the entry point for the bundled plugin. In here you'll find the module exports that Phaser uses when including the plugin internally. The file `CameraManager.js` is the Scene System. All other files are shared between both the external and bundled versions of the plugin.

1071
node_modules/phaser/plugins/camera3d/src/Camera.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,340 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var BuildGameObject = require('../../../src/gameobjects/BuildGameObject');
var BuildGameObjectAnimation = require('../../../src/gameobjects/BuildGameObjectAnimation');
var Class = require('../../../src/utils/Class');
var GetAdvancedValue = require('../../../src/utils/object/GetAdvancedValue');
var OrthographicCamera = require('./OrthographicCamera');
var PerspectiveCamera = require('./PerspectiveCamera');
var ScenePlugin = require('../../../src/plugins/ScenePlugin');
var Sprite3D = require('./sprite3d/Sprite3D');
/**
* @classdesc
* The Camera 3D Plugin adds a new Camera type to Phaser that allows for movement and rendering
* in 3D space. It displays a special type of Sprite called a Sprite3D that is a billboard sprite,
* with a z-axis allowing for perspective depth.
*
* This is an external plugin which you can include in your game by preloading it:
*
* ```javascript
* this.load.scenePlugin({
* key: 'Camera3DPlugin',
* url: 'plugins/camera3d.min.js',
* sceneKey: 'cameras3d'
* });
* ```
*
* Once loaded you can create a 3D Camera using the `camera3d` property of a Scene:
*
* `var camera = this.cameras3d.add(85).setZ(500).setPixelScale(128);`
*
* See the examples for more information.
*
* @class Camera3DPlugin
* @constructor
*
* @param {Phaser.Scene} scene - The Scene to which this plugin is being installed.
* @param {Phaser.Plugins.PluginManager} pluginManager - A reference to the Phaser Plugin Manager.
*/
var Camera3DPlugin = new Class({
Extends: ScenePlugin,
initialize:
function Camera3DPlugin (scene, pluginManager)
{
ScenePlugin.call(this, scene, pluginManager);
/**
* An Array of the Camera objects being managed by this Camera Manager.
*
* @name Camera3DPlugin#cameras
* @type {Phaser.Cameras.Sprite3D.Camera[]}
* @since 3.0.0
*/
this.cameras = [];
// Register the Sprite3D Game Object
pluginManager.registerGameObject('sprite3D', this.sprite3DFactory, this.sprite3DCreator);
},
/**
* Creates a new Sprite3D Game Object and adds it to the Scene.
*
* @method Phaser.GameObjects.GameObjectFactory#sprite3D
* @since 3.0.0
*
* @param {number} x - The horizontal position of this Game Object.
* @param {number} y - The vertical position of this Game Object.
* @param {number} z - The z position of this Game Object.
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with.
*
* @return {Phaser.GameObjects.Sprite3D} The Game Object that was created.
*/
sprite3DFactory: function (x, y, z, key, frame)
{
var sprite = new Sprite3D(this.scene, x, y, z, key, frame);
this.displayList.add(sprite.gameObject);
this.updateList.add(sprite.gameObject);
return sprite;
},
/**
* Creates a new Sprite3D Game Object and returns it.
*
* @method Phaser.GameObjects.GameObjectCreator#sprite3D
* @since 3.0.0
*
* @param {object} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Sprite3D} The Game Object that was created.
*/
sprite3DCreator: function (config, addToScene)
{
if (config === undefined) { config = {}; }
var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null);
var sprite = new Sprite3D(this.scene, 0, 0, key, frame);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, sprite, config);
// Sprite specific config options:
BuildGameObjectAnimation(sprite, config);
return sprite;
},
/**
* This method is called automatically, only once, when the Scene is first created.
* Do not invoke it directly.
*
* @method Phaser.Cameras.Scene3D.CameraManager#boot
* @private
* @since 3.5.1
*/
boot: function ()
{
this.systems.events.once('destroy', this.destroy, this);
},
/**
* This method is called automatically by the Scene when it is starting up.
* It is responsible for creating local systems, properties and listening for Scene events.
* Do not invoke it directly.
*
* @method Camera3DPlugin#start
* @private
* @since 3.5.0
*/
start: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('update', this.update, this);
eventEmitter.once('shutdown', this.shutdown, this);
},
/**
* [description]
*
* @method Camera3DPlugin#add
* @since 3.0.0
*
* @param {number} [fieldOfView=80] - [description]
* @param {number} [width] - [description]
* @param {number} [height] - [description]
*
* @return {Phaser.Cameras.Sprite3D.PerspectiveCamera} [description]
*/
add: function (fieldOfView, width, height)
{
return this.addPerspectiveCamera(fieldOfView, width, height);
},
/**
* [description]
*
* @method Camera3DPlugin#addOrthographicCamera
* @since 3.0.0
*
* @param {number} width - [description]
* @param {number} height - [description]
*
* @return {Phaser.Cameras.Sprite3D.OrthographicCamera} [description]
*/
addOrthographicCamera: function (width, height)
{
var config = this.scene.sys.game.config;
if (width === undefined) { width = config.width; }
if (height === undefined) { height = config.height; }
var camera = new OrthographicCamera(this.scene, width, height);
this.cameras.push(camera);
return camera;
},
/**
* [description]
*
* @method Camera3DPlugin#addPerspectiveCamera
* @since 3.0.0
*
* @param {number} [fieldOfView=80] - [description]
* @param {number} [width] - [description]
* @param {number} [height] - [description]
*
* @return {Phaser.Cameras.Sprite3D.PerspectiveCamera} [description]
*/
addPerspectiveCamera: function (fieldOfView, width, height)
{
var config = this.scene.sys.game.config;
if (fieldOfView === undefined) { fieldOfView = 80; }
if (width === undefined) { width = config.width; }
if (height === undefined) { height = config.height; }
var camera = new PerspectiveCamera(this.scene, fieldOfView, width, height);
this.cameras.push(camera);
return camera;
},
/**
* [description]
*
* @method Camera3DPlugin#getCamera
* @since 3.0.0
*
* @param {string} name - [description]
*
* @return {(Phaser.Cameras.Sprite3D.OrthographicCamera|Phaser.Cameras.Sprite3D.PerspectiveCamera)} [description]
*/
getCamera: function (name)
{
for (var i = 0; i < this.cameras.length; i++)
{
if (this.cameras[i].name === name)
{
return this.cameras[i];
}
}
return null;
},
/**
* [description]
*
* @method Camera3DPlugin#removeCamera
* @since 3.0.0
*
* @param {(Phaser.Cameras.Sprite3D.OrthographicCamera|Phaser.Cameras.Sprite3D.PerspectiveCamera)} camera - [description]
*/
removeCamera: function (camera)
{
var cameraIndex = this.cameras.indexOf(camera);
if (cameraIndex !== -1)
{
this.cameras.splice(cameraIndex, 1);
}
},
/**
* [description]
*
* @method Camera3DPlugin#removeAll
* @since 3.0.0
*
* @return {(Phaser.Cameras.Sprite3D.OrthographicCamera|Phaser.Cameras.Sprite3D.PerspectiveCamera)} [description]
*/
removeAll: function ()
{
while (this.cameras.length > 0)
{
var camera = this.cameras.pop();
camera.destroy();
}
return this.main;
},
/**
* [description]
*
* @method Camera3DPlugin#update
* @since 3.0.0
*
* @param {number} timestep - [description]
* @param {number} delta - [description]
*/
update: function (timestep, delta)
{
for (var i = 0, l = this.cameras.length; i < l; ++i)
{
this.cameras[i].update(timestep, delta);
}
},
/**
* The Scene that owns this plugin is shutting down.
* We need to kill and reset all internal properties as well as stop listening to Scene events.
*
* @method Camera3DPlugin#shutdown
* @private
* @since 3.0.0
*/
shutdown: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.off('update', this.update, this);
eventEmitter.off('shutdown', this.shutdown, this);
this.removeAll();
},
/**
* The Scene that owns this plugin is being destroyed.
* We need to shutdown and then kill off all external references.
*
* @method Camera3DPlugin#destroy
* @private
* @since 3.0.0
*/
destroy: function ()
{
this.shutdown();
this.pluginManager = null;
this.game = null;
this.scene = null;
this.systems = null;
}
});
module.exports = Camera3DPlugin;

View File

@ -0,0 +1,277 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../../../src/utils/Class');
var OrthographicCamera = require('./OrthographicCamera');
var PerspectiveCamera = require('./PerspectiveCamera');
var PluginCache = require('../../../src/plugins/PluginCache');
/**
* @classdesc
* [description]
*
* @class CameraManager
* @memberOf Phaser.Cameras.Sprite3D
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*/
var CameraManager = new Class({
initialize:
function CameraManager (scene)
{
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D.CameraManager#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D.CameraManager#systems
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
this.systems = scene.sys;
/**
* An Array of the Camera objects being managed by this Camera Manager.
*
* @name Phaser.Cameras.Sprite3D.CameraManager#cameras
* @type {Phaser.Cameras.Sprite3D.Camera[]}
* @since 3.0.0
*/
this.cameras = [];
scene.sys.events.once('boot', this.boot, this);
scene.sys.events.on('start', this.start, this);
},
/**
* This method is called automatically, only once, when the Scene is first created.
* Do not invoke it directly.
*
* @method Phaser.Cameras.Scene3D.CameraManager#boot
* @private
* @since 3.5.1
*/
boot: function ()
{
this.systems.events.once('destroy', this.destroy, this);
},
/**
* This method is called automatically by the Scene when it is starting up.
* It is responsible for creating local systems, properties and listening for Scene events.
* Do not invoke it directly.
*
* @method Phaser.Cameras.Sprite3D.CameraManager#start
* @private
* @since 3.5.0
*/
start: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('update', this.update, this);
eventEmitter.once('shutdown', this.shutdown, this);
},
/**
* [description]
*
* @method Phaser.Cameras.Sprite3D.CameraManager#add
* @since 3.0.0
*
* @param {number} [fieldOfView=80] - [description]
* @param {number} [width] - [description]
* @param {number} [height] - [description]
*
* @return {Phaser.Cameras.Sprite3D.PerspectiveCamera} [description]
*/
add: function (fieldOfView, width, height)
{
return this.addPerspectiveCamera(fieldOfView, width, height);
},
/**
* [description]
*
* @method Phaser.Cameras.Sprite3D.CameraManager#addOrthographicCamera
* @since 3.0.0
*
* @param {number} width - [description]
* @param {number} height - [description]
*
* @return {Phaser.Cameras.Sprite3D.OrthographicCamera} [description]
*/
addOrthographicCamera: function (width, height)
{
var config = this.scene.sys.game.config;
if (width === undefined) { width = config.width; }
if (height === undefined) { height = config.height; }
var camera = new OrthographicCamera(this.scene, width, height);
this.cameras.push(camera);
return camera;
},
/**
* [description]
*
* @method Phaser.Cameras.Sprite3D.CameraManager#addPerspectiveCamera
* @since 3.0.0
*
* @param {number} [fieldOfView=80] - [description]
* @param {number} [width] - [description]
* @param {number} [height] - [description]
*
* @return {Phaser.Cameras.Sprite3D.PerspectiveCamera} [description]
*/
addPerspectiveCamera: function (fieldOfView, width, height)
{
var config = this.scene.sys.game.config;
if (fieldOfView === undefined) { fieldOfView = 80; }
if (width === undefined) { width = config.width; }
if (height === undefined) { height = config.height; }
var camera = new PerspectiveCamera(this.scene, fieldOfView, width, height);
this.cameras.push(camera);
return camera;
},
/**
* [description]
*
* @method Phaser.Cameras.Sprite3D.CameraManager#getCamera
* @since 3.0.0
*
* @param {string} name - [description]
*
* @return {(Phaser.Cameras.Sprite3D.OrthographicCamera|Phaser.Cameras.Sprite3D.PerspectiveCamera)} [description]
*/
getCamera: function (name)
{
for (var i = 0; i < this.cameras.length; i++)
{
if (this.cameras[i].name === name)
{
return this.cameras[i];
}
}
return null;
},
/**
* [description]
*
* @method Phaser.Cameras.Sprite3D.CameraManager#removeCamera
* @since 3.0.0
*
* @param {(Phaser.Cameras.Sprite3D.OrthographicCamera|Phaser.Cameras.Sprite3D.PerspectiveCamera)} camera - [description]
*/
removeCamera: function (camera)
{
var cameraIndex = this.cameras.indexOf(camera);
if (cameraIndex !== -1)
{
this.cameras.splice(cameraIndex, 1);
}
},
/**
* [description]
*
* @method Phaser.Cameras.Sprite3D.CameraManager#removeAll
* @since 3.0.0
*
* @return {(Phaser.Cameras.Sprite3D.OrthographicCamera|Phaser.Cameras.Sprite3D.PerspectiveCamera)} [description]
*/
removeAll: function ()
{
while (this.cameras.length > 0)
{
var camera = this.cameras.pop();
camera.destroy();
}
return this.main;
},
/**
* [description]
*
* @method Phaser.Cameras.Sprite3D.CameraManager#update
* @since 3.0.0
*
* @param {number} timestep - [description]
* @param {number} delta - [description]
*/
update: function (timestep, delta)
{
for (var i = 0, l = this.cameras.length; i < l; ++i)
{
this.cameras[i].update(timestep, delta);
}
},
/**
* The Scene that owns this plugin is shutting down.
* We need to kill and reset all internal properties as well as stop listening to Scene events.
*
* @method Phaser.Cameras.Sprite3D.CameraManager#shutdown
* @private
* @since 3.0.0
*/
shutdown: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.off('update', this.update, this);
eventEmitter.off('shutdown', this.shutdown, this);
this.removeAll();
},
/**
* The Scene that owns this plugin is being destroyed.
* We need to shutdown and then kill off all external references.
*
* @method Phaser.Cameras.Sprite3D.CameraManager#destroy
* @private
* @since 3.0.0
*/
destroy: function ()
{
this.shutdown();
this.scene.sys.events.off('start', this.start, this);
this.scene = null;
this.systems = null;
}
});
PluginCache.register('CameraManager3D', CameraManager, 'cameras3d');
module.exports = CameraManager;

View File

@ -0,0 +1,181 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Camera = require('./Camera');
var Class = require('../../../src/utils/Class');
var Vector3 = require('../../../src/math/Vector3');
// Local cache vars
var tmpVec3 = new Vector3();
/**
* @classdesc
* [description]
*
* @class OrthographicCamera
* @extends Phaser.Cameras.Sprite3D.Camera
* @memberOf Phaser.Cameras.Sprite3D
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
* @param {integer} [viewportWidth=0] - [description]
* @param {integer} [viewportHeight=0] - [description]
*/
var OrthographicCamera = new Class({
Extends: Camera,
initialize:
function OrthographicCamera (scene, viewportWidth, viewportHeight)
{
if (viewportWidth === undefined) { viewportWidth = 0; }
if (viewportHeight === undefined) { viewportHeight = 0; }
Camera.call(this, scene);
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D.OrthographicCamera#viewportWidth
* @type {integer}
* @since 3.0.0
*/
this.viewportWidth = viewportWidth;
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D.OrthographicCamera#viewportHeight
* @type {integer}
* @since 3.0.0
*/
this.viewportHeight = viewportHeight;
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D.OrthographicCamera#_zoom
* @type {number}
* @private
* @since 3.0.0
*/
this._zoom = 1.0;
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D.OrthographicCamera#near
* @type {number}
* @default 0
* @since 3.0.0
*/
this.near = 0;
this.update();
},
/**
* [description]
*
* @method Phaser.Cameras.Sprite3D.OrthographicCamera#setToOrtho
* @since 3.0.0
*
* @param {number} yDown - [description]
* @param {number} [viewportWidth] - [description]
* @param {number} [viewportHeight] - [description]
*
* @return {Phaser.Cameras.Sprite3D.OrthographicCamera} [description]
*/
setToOrtho: function (yDown, viewportWidth, viewportHeight)
{
if (viewportWidth === undefined) { viewportWidth = this.viewportWidth; }
if (viewportHeight === undefined) { viewportHeight = this.viewportHeight; }
var zoom = this.zoom;
this.up.set(0, (yDown) ? -1 : 1, 0);
this.direction.set(0, 0, (yDown) ? 1 : -1);
this.position.set(zoom * viewportWidth / 2, zoom * viewportHeight / 2, 0);
this.viewportWidth = viewportWidth;
this.viewportHeight = viewportHeight;
return this.update();
},
/**
* [description]
*
* @method Phaser.Cameras.Sprite3D.OrthographicCamera#update
* @since 3.0.0
*
* @return {Phaser.Cameras.Sprite3D.OrthographicCamera} [description]
*/
update: function ()
{
var w = this.viewportWidth;
var h = this.viewportHeight;
var near = Math.abs(this.near);
var far = Math.abs(this.far);
var zoom = this.zoom;
if (w === 0 || h === 0)
{
// What to do here... hmm?
return this;
}
this.projection.ortho(
zoom * -w / 2, zoom * w / 2,
zoom * -h / 2, zoom * h / 2,
near,
far
);
// Build the view matrix
tmpVec3.copy(this.position).add(this.direction);
this.view.lookAt(this.position, tmpVec3, this.up);
// Projection * view matrix
this.combined.copy(this.projection).multiply(this.view);
// Invert combined matrix, used for unproject
this.invProjectionView.copy(this.combined).invert();
this.billboardMatrixDirty = true;
this.updateChildren();
return this;
},
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D.OrthographicCamera#zoom
* @type {number}
* @since 3.0.0
*/
zoom: {
get: function ()
{
return this._zoom;
},
set: function (value)
{
this._zoom = value;
this.update();
}
}
});
module.exports = OrthographicCamera;

View File

@ -0,0 +1,134 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Camera = require('./Camera');
var Class = require('../../../src/utils/Class');
var Vector3 = require('../../../src/math/Vector3');
// Local cache vars
var tmpVec3 = new Vector3();
/**
* @classdesc
* [description]
*
* @class PerspectiveCamera
* @extends Phaser.Cameras.Sprite3D.Camera
* @memberOf Phaser.Cameras.Sprite3D
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
* @param {integer} [fieldOfView=80] - [description]
* @param {integer} [viewportWidth=0] - [description]
* @param {integer} [viewportHeight=0] - [description]
*/
var PerspectiveCamera = new Class({
Extends: Camera,
// FOV is converted to radians automatically
initialize:
function PerspectiveCamera (scene, fieldOfView, viewportWidth, viewportHeight)
{
if (fieldOfView === undefined) { fieldOfView = 80; }
if (viewportWidth === undefined) { viewportWidth = 0; }
if (viewportHeight === undefined) { viewportHeight = 0; }
Camera.call(this, scene);
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D.PerspectiveCamera#viewportWidth
* @type {integer}
* @default 0
* @since 3.0.0
*/
this.viewportWidth = viewportWidth;
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D.PerspectiveCamera#viewportHeight
* @type {integer}
* @default 0
* @since 3.0.0
*/
this.viewportHeight = viewportHeight;
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D.PerspectiveCamera#fieldOfView
* @type {integer}
* @default 80
* @since 3.0.0
*/
this.fieldOfView = fieldOfView * Math.PI / 180;
this.update();
},
/**
* [description]
*
* @method Phaser.Cameras.Sprite3D.PerspectiveCamera#setFOV
* @since 3.0.0
*
* @param {number} value - [description]
*
* @return {Phaser.Cameras.Sprite3D.PerspectiveCamera} [description]
*/
setFOV: function (value)
{
this.fieldOfView = value * Math.PI / 180;
return this;
},
/**
* [description]
*
* @method Phaser.Cameras.Sprite3D.PerspectiveCamera#update
* @since 3.0.0
*
* @return {Phaser.Cameras.Sprite3D.PerspectiveCamera} [description]
*/
update: function ()
{
var aspect = this.viewportWidth / this.viewportHeight;
// Create a perspective matrix for our camera
this.projection.perspective(
this.fieldOfView,
aspect,
Math.abs(this.near),
Math.abs(this.far)
);
// Build the view matrix
tmpVec3.copy(this.position).add(this.direction);
this.view.lookAt(this.position, tmpVec3, this.up);
// Projection * view matrix
this.combined.copy(this.projection).multiply(this.view);
// Invert combined matrix, used for unproject
this.invProjectionView.copy(this.combined).invert();
this.billboardMatrixDirty = true;
this.updateChildren();
return this;
}
});
module.exports = PerspectiveCamera;

18
node_modules/phaser/plugins/camera3d/src/index.js generated vendored Normal file
View File

@ -0,0 +1,18 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* @namespace Phaser.Cameras.Sprite3D
*/
module.exports = {
Camera: require('./Camera'),
CameraManager: require('./CameraManager'),
OrthographicCamera: require('./OrthographicCamera'),
PerspectiveCamera: require('./PerspectiveCamera')
};

View File

@ -0,0 +1,260 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../../../../src/utils/Class');
var GameObject = require('../../../../src/gameobjects/GameObject');
var Sprite = require('../../../../src/gameobjects/sprite/Sprite');
var Vector2 = require('../../../../src/math/Vector2');
var Vector4 = require('../../../../src/math/Vector4');
/**
* @classdesc
* A Sprite 3D Game Object.
*
* The Sprite 3D object is an encapsulation of a standard Sprite object, with additional methods to allow
* it to be rendered by a 3D Camera. The Sprite can be positioned anywhere within 3D space.
*
* @class Sprite3D
* @extends Phaser.GameObjects.Sprite
* @memberOf Phaser.GameObjects
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time.
* @param {number} x - The x position of this Game Object.
* @param {number} y - The y position of this Game Object.
* @param {number} z - The z position of this Game Object.
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with.
*/
var Sprite3D = new Class({
Extends: GameObject,
initialize:
function Sprite3D (scene, x, y, z, texture, frame)
{
GameObject.call(this, scene, 'Sprite3D');
/**
* The encapsulated Sprite.
*
* @name Phaser.GameObjects.Sprite3D#gameObject
* @type {Phaser.GameObjects.GameObject}
* @since 3.0.0
*/
this.gameObject = new Sprite(scene, 0, 0, texture, frame);
/**
* The position of the Sprite.
*
* @name Phaser.GameObjects.Sprite3D#position
* @type {Phaser.Math.Vector4}
* @since 3.0.0
*/
this.position = new Vector4(x, y, z);
/**
* The 2D size of the Sprite.
*
* @name Phaser.GameObjects.Sprite3D#size
* @type {Phaser.Math.Vector2}
* @since 3.0.0
*/
this.size = new Vector2(this.gameObject.width, this.gameObject.height);
/**
* The 2D scale of the Sprite.
*
* @name Phaser.GameObjects.Sprite3D#scale
* @type {Phaser.Math.Vector2}
* @since 3.0.0
*/
this.scale = new Vector2(1, 1);
/**
* Whether to automatically set the horizontal scale of the encapsulated Sprite.
*
* @name Phaser.GameObjects.Sprite3D#adjustScaleX
* @type {boolean}
* @default true
* @since 3.0.0
*/
this.adjustScaleX = true;
/**
* Whether to automatically set the vertical scale of the encapsulated Sprite.
*
* @name Phaser.GameObjects.Sprite3D#adjustScaleY
* @type {boolean}
* @default true
* @since 3.0.0
*/
this.adjustScaleY = true;
/**
* The visible state of the Game Object.
*
* @name Phaser.GameObjects.Sprite3D#_visible
* @type {boolean}
* @default true
* @private
* @since 3.0.0
*/
this._visible = true;
},
/**
* Project this Sprite onto the given 3D Camera.
*
* @method Phaser.GameObjects.Sprite3D#project
* @since 3.0.0
*
* @param {Phaser.Cameras.Sprite3D.Camera} camera - The 3D Camera onto which to project this Sprite.
*/
project: function (camera)
{
var pos = this.position;
var gameObject = this.gameObject;
camera.project(pos, gameObject);
camera.getPointSize(pos, this.size, this.scale);
if (this.scale.x <= 0 || this.scale.y <= 0)
{
gameObject.setVisible(false);
}
else
{
if (!gameObject.visible)
{
gameObject.setVisible(true);
}
if (this.adjustScaleX)
{
gameObject.scaleX = this.scale.x;
}
if (this.adjustScaleY)
{
gameObject.scaleY = this.scale.y;
}
gameObject.setDepth(gameObject.z * -1);
}
},
/**
* Set the visible state of the Game Object.
*
* @method Phaser.GameObjects.Sprite3D#setVisible
* @since 3.0.0
*
* @param {boolean} value - The visible state of the Game Object.
*
* @return {Phaser.GameObjects.Sprite3D} This Sprite3D Object.
*/
setVisible: function (value)
{
this.visible = value;
return this;
},
/**
* The visible state of the Game Object.
*
* An invisible Game Object will skip rendering, but will still process update logic.
*
* @name Phaser.GameObjects.Sprite3D#visible
* @type {boolean}
* @since 3.0.0
*/
visible: {
get: function ()
{
return this._visible;
},
set: function (value)
{
this._visible = value;
this.gameObject.visible = value;
}
},
/**
* The x position of this Game Object.
*
* @name Phaser.GameObjects.Sprite3D#x
* @type {number}
* @since 3.0.0
*/
x: {
get: function ()
{
return this.position.x;
},
set: function (value)
{
this.position.x = value;
}
},
/**
* The y position of this Game Object.
*
* @name Phaser.GameObjects.Sprite3D#y
* @type {number}
* @since 3.0.0
*/
y: {
get: function ()
{
return this.position.y;
},
set: function (value)
{
this.position.y = value;
}
},
/**
* The z position of this Game Object.
*
* @name Phaser.GameObjects.Sprite3D#z
* @type {number}
* @since 3.0.0
*/
z: {
get: function ()
{
return this.position.z;
},
set: function (value)
{
this.position.z = value;
}
}
});
module.exports = Sprite3D;

View File

@ -0,0 +1,49 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var BuildGameObject = require('../../../../src/gameobjects/BuildGameObject');
var BuildGameObjectAnimation = require('../../../../src/gameobjects/BuildGameObjectAnimation');
var GameObjectCreator = require('../../../../src/gameobjects/GameObjectCreator');
var GetAdvancedValue = require('../../../../src/utils/object/GetAdvancedValue');
var Sprite3D = require('./Sprite3D');
/**
* Creates a new Sprite3D Game Object and returns it.
*
* Note: This method will only be available if the Sprite3D Game Object has been built into Phaser.
*
* @method Phaser.GameObjects.GameObjectCreator#sprite3D
* @since 3.0.0
*
* @param {object} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Sprite3D} The Game Object that was created.
*/
GameObjectCreator.register('sprite3D', function (config, addToScene)
{
if (config === undefined) { config = {}; }
var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null);
var sprite = new Sprite3D(this.scene, 0, 0, key, frame);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, sprite, config);
// Sprite specific config options:
BuildGameObjectAnimation(sprite, config);
return sprite;
});
// When registering a factory function 'this' refers to the GameObjectCreator context.

View File

@ -0,0 +1,42 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Sprite3D = require('./Sprite3D');
var GameObjectFactory = require('../../../../src/gameobjects/GameObjectFactory');
/**
* Creates a new Sprite3D Game Object and adds it to the Scene.
*
* Note: This method will only be available if the Sprite3D Game Object has been built into Phaser.
*
* @method Phaser.GameObjects.GameObjectFactory#sprite3D
* @since 3.0.0
*
* @param {number} x - The horizontal position of this Game Object.
* @param {number} y - The vertical position of this Game Object.
* @param {number} z - The z position of this Game Object.
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with.
*
* @return {Phaser.GameObjects.Sprite3D} The Game Object that was created.
*/
GameObjectFactory.register('sprite3D', function (x, y, z, key, frame)
{
var sprite = new Sprite3D(this.scene, x, y, z, key, frame);
this.displayList.add(sprite.gameObject);
this.updateList.add(sprite.gameObject);
return sprite;
});
// When registering a factory function 'this' refers to the GameObjectFactory context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
// this.displayList - a reference to the Display List the Scene owns
// this.updateList - a reference to the Update List the Scene owns

63
node_modules/phaser/plugins/camera3d/webpack.config.js generated vendored Normal file
View File

@ -0,0 +1,63 @@
'use strict';
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const exec = require('child_process').exec;
const RemovePlugin = require('remove-files-webpack-plugin');
module.exports = {
mode: 'production',
context: `${__dirname}/src/`,
entry: {
camera3d: './Camera3DPlugin.js',
'camera3d.min': './Camera3DPlugin.js'
},
output: {
path: `${__dirname}/dist/`,
filename: '[name].js',
library: 'Camera3DPlugin',
libraryTarget: 'var'
},
performance: { hints: false },
optimization: {
minimizer: [
new UglifyJSPlugin({
include: /\.min\.js$/,
parallel: true,
sourceMap: false,
uglifyOptions: {
compress: true,
ie8: false,
ecma: 5,
output: {comments: false},
warnings: false
},
warningsFilter: () => false
})
]
},
plugins: [
new RemovePlugin({
before: {
root: './plugins/camera3d/dist/',
include: [ 'camera3d.js', 'camera3d.min.js' ]
}
}),
{
apply: (compiler) => {
compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => {
exec('node plugins/camera3d/copy-to-examples.js', (err, stdout, stderr) => {
if (stdout) process.stdout.write(stdout);
if (stderr) process.stderr.write(stderr);
});
});
}
}
]
};