window.__require = function t(e, i, r) {
function o(c, n) {
if (!i[c]) {
if (!e[c]) {
var l = c.split("/");
l = l[l.length - 1];
if (!e[l]) {
var s = "function" == typeof __require && __require;
if (!n && s) return s(l, !0);
if (a) return a(l, !0);
throw new Error("Cannot find module '" + c + "'");
}
c = l;
}
var d = i[c] = {
exports: {}
};
e[c][0].call(d.exports, function(t) {
return o(e[c][1][t] || t);
}, d, d.exports, t, e, i, r);
}
return i[c].exports;
}
for (var a = "function" == typeof __require && __require, c = 0; c < r.length; c++) o(r[c]);
return o;
}({
Camera2DWorldRect: [ function(t, e, i) {
"use strict";
cc._RF.push(e, "e2e48xyyqRHy5s6xLJze03X", "Camera2DWorldRect");
Object.defineProperty(i, "__esModule", {
value: !0
});
var r = t("./LightWorldRect"), o = cc._decorator, a = o.ccclass, c = o.property, n = o.requireComponent, l = o.executeInEditMode, s = function(t) {
__extends(e, t);
function e() {
var e = null !== t && t.apply(this, arguments) || this;
e.debugSprite = null;
return e;
}
__decorate([ c(cc.Sprite) ], e.prototype, "debugSprite", void 0);
return __decorate([ a, l, n(cc.Camera) ], e);
}(r.default);
i.default = s;
cc._RF.pop();
}, {
"./LightWorldRect": "LightWorldRect"
} ],
Light2DManager: [ function(t, e, i) {
"use strict";
cc._RF.push(e, "fd114OUeUVCdpeRfTVy8cZg", "Light2DManager");
Object.defineProperty(i, "__esModule", {
value: !0
});
i.LightPassLayer = void 0;
var r = t("./Camera2DWorldRect"), o = t("./SpriteLight"), a = cc._decorator, c = a.ccclass, n = a.property, l = a.executeInEditMode, s = a.executionOrder;
i.LightPassLayer = "LightPass";
var d = function(t) {
__extends(e, t);
function e() {
var e = null !== t && t.apply(this, arguments) || this;
e.lightMats = [];
e.ambientMats = [];
e.lightCamera = null;
e.followCamera = null;
e.lightTextureDebugSprite = null;
e.lightRenderTargetScale = .25;
e.ambient = new cc.Color(1, 1, 1, 1);
e.lightTarget = null;
e.cameraWorldRect = null;
e.lights = [];
e.lightClones = [];
e.pos = cc.v2();
e.scale = cc.v3();
e.rot = cc.quat();
e.v1 = cc.v2();
return e;
}
i = e;
e.prototype.onLoad = function() {
i.Instance = this;
this.cameraWorldRect = this.lightCamera.node.getComponent(r.default);
this.cameraWorldRect || (this.cameraWorldRect = this.lightCamera.node.addComponent(r.default));
var t = cc.view.getVisibleSize();
console.log("size:", t.toString());
this.lightTarget = new cc.RenderTexture();
this.lightTarget.initWithSize(t.width * this.lightRenderTargetScale, t.height * this.lightRenderTargetScale);
this.lightCamera.targetTexture = this.lightTarget;
this.lightTextureDebugSprite && (this.lightTextureDebugSprite.spriteFrame = new cc.SpriteFrame(this.lightTarget));
};
e.prototype.onEnable = function() {
var t = this;
console.log("光照开启");
this.lightCamera.node.active = !0;
this.lightMats.forEach(function(e) {
e.define("USE_LIGHTMAP", 1, 0, !0);
e.setProperty("lightmap", t.lightTarget);
});
this.UpdateMaterialParams();
};
e.prototype.onDisable = function() {
console.log("光照关闭");
this.lightCamera.node.active = !1;
this.lightMats.forEach(function(t) {
t.define("USE_LIGHTMAP", 0, 0, !0);
});
};
e.prototype.onDestroy = function() {
i.Instance = null;
this.lightTarget && this.lightTarget.destroy();
this.lightTarget = null;
};
e.prototype.lateUpdate = function() {
this.followCamera && this.lightCamera.node.setPosition(this.followCamera.node.getPosition());
for (var t = this.lights.length - 1; t >= 0; t--) {
var e = this.lights[t], i = this.lightClones[t];
e.UpdateWorldRect();
var r = this.cameraWorldRect.IsVisible(e.worldRect);
i.node.active = e.node.active && r;
r && this.UpdateLight(e, i);
}
};
e.prototype.UpdateLight = function(t, e) {
var i = e.node, r = t.node;
e.spriteFrame = t.spriteFrame;
i.opacity = r.opacity;
i.color = r._color;
if (!t.isStatic) {
var o = i.__wPos;
if (!o) {
o = cc.v2(-99999);
i.__wPos = o;
}
var a = r.convertToWorldSpaceAR(this.pos, this.v1);
if (!a.equals(o)) {
o.set(a);
i.setWorldPosition.call(i, a);
if (t.updateWorldRot) {
var c = r.getWorldRotation.call(r, this.rot);
i.setWorldRotation.call(i, c);
} else i.angle = r.angle;
if (t.updateWorldScale) {
var n = r.getWorldScale.call(r, this.scale);
i.setWorldScale.call(i, n);
} else i.scale = r.scale;
}
}
};
e.prototype.UpdateMaterialParams = function() {
var t = this;
this.ambientMats.forEach(function(e) {
e.setProperty("ambient", t.ambient);
});
};
e.prototype.SetLightParams = function(t) {
t.define("USE_LIGHTMAP", 1, 0, !0);
t.setProperty("lightmap", this.lightTarget);
t.setProperty("ambient", this.ambient);
};
e.prototype.AddLight = function(t) {
this.lights.push(t);
var e = cc.instantiate(t.node), i = e.getComponent(o.default);
i.isClone = !0;
i.enabled = !0;
this.lightClones.push(i);
e.setParent(this.node);
this.UpdateLight(t, i);
t.enabled = !1;
};
e.prototype.RemoveLight = function(t) {
var e = this.lights.indexOf(t);
if (e >= 0) {
var i = this.lightClones[e];
this.lights.splice(e, 1);
this.lightClones.splice(e, 1);
i.node.destroy();
}
};
var i;
e.Instance = null;
__decorate([ n(cc.Material) ], e.prototype, "lightMats", void 0);
__decorate([ n(cc.Material) ], e.prototype, "ambientMats", void 0);
__decorate([ n(cc.Camera) ], e.prototype, "lightCamera", void 0);
__decorate([ n(cc.Camera) ], e.prototype, "followCamera", void 0);
__decorate([ n(cc.Sprite) ], e.prototype, "lightTextureDebugSprite", void 0);
__decorate([ n({
min: .01,
max: 1
}) ], e.prototype, "lightRenderTargetScale", void 0);
__decorate([ n(cc.Color) ], e.prototype, "ambient", void 0);
return i = __decorate([ c, l, s(100) ], e);
}(cc.Component);
i.default = d;
cc._RF.pop();
}, {
"./Camera2DWorldRect": "Camera2DWorldRect",
"./SpriteLight": "SpriteLight"
} ],
LightWorldRect: [ function(t, e, i) {
"use strict";
cc._RF.push(e, "3d81d7qWRdBZLQUlOHl5kIM", "LightWorldRect");
Object.defineProperty(i, "__esModule", {
value: !0
});
var r = cc._decorator, o = r.ccclass, a = r.executeInEditMode, c = function(t) {
__extends(e, t);
function e() {
var e = null !== t && t.apply(this, arguments) || this;
e.worldRect_ = new cc.Rect(0, 0, 0, 0);
e.isRectDirty = !0;
e.dirtyFrame = Number.MAX_VALUE;
e.v1 = cc.v2();
return e;
}
Object.defineProperty(e.prototype, "worldRect", {
get: function() {
if (!this.isRectDirty) return this.worldRect_;
var t = this.node.convertToWorldSpaceAR(cc.Vec2.ZERO, this.v1), e = cc.view.getVisibleSize(), i = .5 * e.width, r = .5 * e.height, o = t.x, a = t.y;
this.worldRect_.xMin = o - i;
this.worldRect_.yMin = a - r;
this.worldRect_.xMax = this.worldRect_.xMin + 2 * i;
this.worldRect_.yMax = this.worldRect_.yMin + 2 * r;
this.isRectDirty = !1;
return this.worldRect_;
},
enumerable: !1,
configurable: !0
});
e.prototype.onLoad = function() {
this.dirtyFrame = cc.director.getTotalFrames() + 1;
this.node.on(cc.Node.EventType.POSITION_CHANGED, this.onPositionChanged.bind(this));
};
e.prototype.onPositionChanged = function() {
this.isRectDirty = !0;
this.dirtyFrame = cc.director.getTotalFrames() + 1;
};
e.prototype.IsVisible = function(t) {
return this.worldRect.intersects(t);
};
return __decorate([ o, a ], e);
}(cc.Component);
i.default = c;
cc._RF.pop();
}, {} ],
SpriteLight: [ function(t, e, i) {
"use strict";
cc._RF.push(e, "6973836m8RMxbPX88G4fxty", "SpriteLight");
Object.defineProperty(i, "__esModule", {
value: !0
});
var r = t("./Light2DManager"), o = cc._decorator, a = o.ccclass, c = o.menu, n = o.property, l = function(t) {
__extends(e, t);
function e() {
var e = null !== t && t.apply(this, arguments) || this;
e.isStatic = !1;
e.updateWorldRot = !1;
e.updateWorldScale = !1;
e.isClone = !1;
e.enableCull = !0;
e.worldRect_ = cc.rect();
e.lastPos = cc.v2(Number.MIN_SAFE_INTEGER);
e.v1 = cc.v2();
return e;
}
Object.defineProperty(e.prototype, "worldRect", {
get: function() {
return this.worldRect_;
},
enumerable: !1,
configurable: !0
});
e.prototype.UpdateWorldRect = function() {
var t = this.node.convertToWorldSpaceAR(cc.Vec2.ZERO, this.v1);
if (Math.abs(t.x - this.lastPos.x) >= 2 || Math.abs(t.y - this.lastPos.y) >= 2) {
var e = .5 * this.node.width, i = .5 * this.node.height, r = t.x, o = t.y;
this.worldRect_.xMin = r - e;
this.worldRect_.yMin = o - i;
this.worldRect_.xMax = this.worldRect_.xMin + 2 * e;
this.worldRect_.yMax = this.worldRect_.yMin + 2 * i;
this.lastPos.set(t);
}
};
e.prototype.start = function() {
if (!this.isClone) {
this.node.group = r.LightPassLayer;
this.srcBlendFactor = cc.macro.BlendFactor.SRC_ALPHA;
this.dstBlendFactor = cc.macro.BlendFactor.ONE;
r.default.Instance && r.default.Instance.AddLight(this);
}
};
e.prototype.onDestroy = function() {
!this.isClone && r.default.Instance && r.default.Instance.RemoveLight(this);
t.prototype.onDestroy.call(this);
};
__decorate([ n() ], e.prototype, "isStatic", void 0);
__decorate([ n() ], e.prototype, "updateWorldRot", void 0);
__decorate([ n() ], e.prototype, "updateWorldScale", void 0);
__decorate([ n() ], e.prototype, "enableCull", void 0);
return __decorate([ a, c("2DLight/SpriteLitght") ], e);
}(cc.Sprite);
i.default = l;
cc._RF.pop();
}, {
"./Light2DManager": "Light2DManager"
} ]
}, {}, [ "Camera2DWorldRect", "Light2DManager", "LightWorldRect", "SpriteLight" ]);