Prettified all files.
This commit is contained in:
@@ -1469,10 +1469,10 @@
|
||||
* const front = PIXI.Sprite.fromImage('./assets/front.jpg')
|
||||
* const back = PIXI.Sprite.fromImage('./assets/back.jpg')
|
||||
* app.scene.addChild(front)
|
||||
*
|
||||
*
|
||||
* // Create the flippable
|
||||
* const flippable = new Flippable(front, back, app.renderer)
|
||||
*
|
||||
*
|
||||
* front.interactive = true
|
||||
* front.on('click', event => flippable.toggle())
|
||||
*
|
||||
@@ -1482,7 +1482,6 @@
|
||||
* @see {@link https://www.iwm-tuebingen.de/iwmbrowser/lib/pixi/flippable.html|DocTest}
|
||||
*/
|
||||
export default class Flippable extends PIXI.projection.Camera3d {
|
||||
|
||||
/**
|
||||
* Creates an instance of a Flippable.
|
||||
*
|
||||
@@ -1508,30 +1507,38 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
* @param {function} [opts.onComplete=null] - A callback executed when the flip animation is finished.
|
||||
*/
|
||||
constructor(front, back, renderer, opts = {}) {
|
||||
|
||||
super()
|
||||
|
||||
this.opts = Object.assign({}, {
|
||||
front,
|
||||
back,
|
||||
renderer,
|
||||
duration: 1,
|
||||
ease: Power2.easeOut,
|
||||
shadow: false,
|
||||
eulerX: 0,
|
||||
eulerY: 0,
|
||||
eulerEase: Power1.easeOut,
|
||||
useBackTransforms: false,
|
||||
transformEase: Power2.easeOut,
|
||||
focus: 800,
|
||||
near: 10,
|
||||
far: 10000,
|
||||
orthographic: false
|
||||
}, opts)
|
||||
this.opts = Object.assign(
|
||||
{},
|
||||
{
|
||||
front,
|
||||
back,
|
||||
renderer,
|
||||
duration: 1,
|
||||
ease: Power2.easeOut,
|
||||
shadow: false,
|
||||
eulerX: 0,
|
||||
eulerY: 0,
|
||||
eulerEase: Power1.easeOut,
|
||||
useBackTransforms: false,
|
||||
transformEase: Power2.easeOut,
|
||||
focus: 800,
|
||||
near: 10,
|
||||
far: 10000,
|
||||
orthographic: false
|
||||
},
|
||||
opts
|
||||
)
|
||||
|
||||
// planes
|
||||
//--------------------
|
||||
this.setPlanes(this.opts.focus, this.opts.near, this.opts.far, this.opts.orthographic)
|
||||
this.setPlanes(
|
||||
this.opts.focus,
|
||||
this.opts.near,
|
||||
this.opts.far,
|
||||
this.opts.orthographic
|
||||
)
|
||||
|
||||
// flipped
|
||||
//--------------------
|
||||
@@ -1553,8 +1560,7 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
* @return {Flippable} A reference to the flippable for chaining.
|
||||
*/
|
||||
setup() {
|
||||
|
||||
const scale = .5
|
||||
const scale = 0.5
|
||||
|
||||
// filters
|
||||
//--------------------
|
||||
@@ -1571,16 +1577,18 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
|
||||
// shadow
|
||||
//--------------------
|
||||
const shadow = new PIXI.projection.Sprite3d(PIXI.Texture.fromImage('../../assets/images/shadow.png'))
|
||||
const shadow = new PIXI.projection.Sprite3d(
|
||||
PIXI.Texture.fromImage('../../assets/images/shadow.png')
|
||||
)
|
||||
shadow.renderable = false
|
||||
shadow.anchor.set(0.5)
|
||||
shadow.scale3d.set(.98)
|
||||
shadow.scale3d.set(0.98)
|
||||
shadow.alpha = 0.7
|
||||
shadow.filters = [blurFilter]
|
||||
shadow.visible = this.opts.shadow
|
||||
outer.addChild(shadow)
|
||||
this.objects.shadow = shadow
|
||||
|
||||
|
||||
// inner
|
||||
//--------------------
|
||||
const inner = new PIXI.projection.Container3d()
|
||||
@@ -1593,7 +1601,7 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
const front = new PIXI.projection.Sprite3d(PIXI.Texture.EMPTY)
|
||||
front.scale.set(-1 / scale, 1 / scale)
|
||||
front.renderable = true
|
||||
front.anchor.set(.5)
|
||||
front.anchor.set(0.5)
|
||||
inner.addChild(front)
|
||||
this.objects.front = front
|
||||
|
||||
@@ -1602,7 +1610,7 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
const back = new PIXI.projection.Sprite3d(PIXI.Texture.EMPTY)
|
||||
back.scale.set(1 / scale, 1 / scale)
|
||||
back.renderable = false
|
||||
back.anchor.set(.5)
|
||||
back.anchor.set(0.5)
|
||||
inner.addChild(back)
|
||||
this.objects.back = back
|
||||
|
||||
@@ -1618,7 +1626,6 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
return this._flipped
|
||||
}
|
||||
set flipped(toBack) {
|
||||
|
||||
this._flipped = toBack
|
||||
|
||||
// references
|
||||
@@ -1639,7 +1646,7 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
//--------------------
|
||||
front.texture = this.generateTexture(this.opts.front)
|
||||
back.texture = this.generateTexture(this.opts.back)
|
||||
|
||||
|
||||
// switch objects and set params for virtual objects
|
||||
//--------------------
|
||||
const fromCenter = this.anchorToCenter(fromObject)
|
||||
@@ -1664,11 +1671,21 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
y: this.opts.useBackTransforms ? toCenter.y : fromCenter.y,
|
||||
anchorX: this.opts.useBackTransforms ? toObject.x : fromObject.x,
|
||||
anchorY: this.opts.useBackTransforms ? toObject.y : fromObject.y,
|
||||
width: this.opts.useBackTransforms ? toObject.width * 2 : fromObject.width * 2,
|
||||
height: this.opts.useBackTransforms ? toObject.height * 2 : fromObject.height * 2,
|
||||
rotation: this.opts.useBackTransforms ? toObject.rotation : fromObject.rotation,
|
||||
skewX: this.opts.useBackTransforms ? toObject.skew.x : fromObject.skew.x,
|
||||
skewY: this.opts.useBackTransforms ? toObject.skew.y : fromObject.skew.y
|
||||
width: this.opts.useBackTransforms
|
||||
? toObject.width * 2
|
||||
: fromObject.width * 2,
|
||||
height: this.opts.useBackTransforms
|
||||
? toObject.height * 2
|
||||
: fromObject.height * 2,
|
||||
rotation: this.opts.useBackTransforms
|
||||
? toObject.rotation
|
||||
: fromObject.rotation,
|
||||
skewX: this.opts.useBackTransforms
|
||||
? toObject.skew.x
|
||||
: fromObject.skew.x,
|
||||
skewY: this.opts.useBackTransforms
|
||||
? toObject.skew.y
|
||||
: fromObject.skew.y
|
||||
}
|
||||
|
||||
// set toObject end values
|
||||
@@ -1745,20 +1762,24 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
// camera
|
||||
//--------------------
|
||||
new TimelineMax()
|
||||
.to(this.euler, half, {x: this.opts.eulerX, y: this.opts.eulerY, ease})
|
||||
.to(this.euler, half, {x: 0, y: 0, ease})
|
||||
.to(this.euler, half, {
|
||||
x: this.opts.eulerX,
|
||||
y: this.opts.eulerY,
|
||||
ease
|
||||
})
|
||||
.to(this.euler, half, { x: 0, y: 0, ease })
|
||||
|
||||
// shadow
|
||||
//--------------------
|
||||
new TimelineMax()
|
||||
.to(shadow, half, {alpha: .3, ease})
|
||||
.to(shadow, half, {alpha: .7, ease})
|
||||
|
||||
.to(shadow, half, { alpha: 0.3, ease })
|
||||
.to(shadow, half, { alpha: 0.7, ease })
|
||||
|
||||
// blurfilter
|
||||
//--------------------
|
||||
new TimelineMax()
|
||||
.to(blurFilter, half, {blur: 6, ease})
|
||||
.to(blurFilter, half, {blur: .2, ease})
|
||||
.to(blurFilter, half, { blur: 6, ease })
|
||||
.to(blurFilter, half, { blur: 0.2, ease })
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1767,18 +1788,18 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
* @return {Flippable} A reference to the flippable for chaining.
|
||||
*/
|
||||
layout() {
|
||||
|
||||
const front = this.objects.front
|
||||
const back = this.objects.back
|
||||
const shadow = this.objects.shadow
|
||||
const inner = this.objects.inner
|
||||
|
||||
inner.position3d.z = -Math.sin(inner.euler.y) * front.texture.baseTexture.width * 2
|
||||
|
||||
inner.position3d.z =
|
||||
-Math.sin(inner.euler.y) * front.texture.baseTexture.width * 2
|
||||
|
||||
//this.objects.shadow.euler = this.objects.inner.euler
|
||||
shadow.euler.x = -inner.euler.x
|
||||
shadow.euler.y = -inner.euler.y
|
||||
|
||||
|
||||
if (this.frontSideInFront) {
|
||||
front.renderable = true
|
||||
back.renderable = false
|
||||
@@ -1838,13 +1859,25 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
* @return {PIXI.Texture} The generated PIXI.Texture.
|
||||
*/
|
||||
generateTexture(displayObject) {
|
||||
|
||||
// renderTexture
|
||||
//--------------------
|
||||
const renderTexture = PIXI.RenderTexture.create(displayObject.width, displayObject.height)
|
||||
const renderTexture = PIXI.RenderTexture.create(
|
||||
displayObject.width,
|
||||
displayObject.height
|
||||
)
|
||||
|
||||
// save position
|
||||
const transform = [displayObject.x, displayObject.y, displayObject.scale.x, displayObject.scale.y, displayObject.rotation, displayObject.skew.x, displayObject.skew.y, displayObject.pivot.x, displayObject.pivot.y]
|
||||
const transform = [
|
||||
displayObject.x,
|
||||
displayObject.y,
|
||||
displayObject.scale.x,
|
||||
displayObject.scale.y,
|
||||
displayObject.rotation,
|
||||
displayObject.skew.x,
|
||||
displayObject.skew.y,
|
||||
displayObject.pivot.x,
|
||||
displayObject.pivot.y
|
||||
]
|
||||
|
||||
displayObject.position.set(0, 0)
|
||||
displayObject.skew.set(0, 0)
|
||||
@@ -1853,7 +1886,7 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
// render
|
||||
//--------------------
|
||||
this.opts.renderer.render(displayObject, renderTexture)
|
||||
|
||||
|
||||
// restore position
|
||||
displayObject.setTransform(...transform)
|
||||
|
||||
@@ -1892,7 +1925,7 @@ export default class Flippable extends PIXI.projection.Camera3d {
|
||||
|
||||
<footer class="content-size">
|
||||
<div class="footer">
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.2</a> on Wed Jul 10 2019 11:54:25 GMT+0200 (Mitteleuropäische Sommerzeit)
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Jul 18 2019 12:16:18 GMT+0200 (Mitteleuropäische Sommerzeit)
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user