Merge branch 'next' of github.com:cocos-creator/engine into next-runtime

This commit is contained in:
James Chen
2018-03-12 16:42:55 +08:00
14 changed files with 263 additions and 194 deletions
+5 -5
View File
@@ -148,7 +148,7 @@ cc.CardinalSplineTo = cc.Class({
cc.ActionInterval.prototype.startWithTarget.call(this, target);
// Issue #1441 from cocos2d-iphone
this._deltaT = 1 / (this._points.length - 1);
this._previousPosition = cc.p(this.target.getPositionX(), this.target.getPositionY());
this._previousPosition = cc.p(this.target.x, this.target.y);
this._accumulatedDiff = cc.p(0, 0);
},
@@ -178,8 +178,8 @@ cc.CardinalSplineTo = cc.Class({
if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
var tempX, tempY;
tempX = this.target.getPositionX() - this._previousPosition.x;
tempY = this.target.getPositionY() - this._previousPosition.y;
tempX = this.target.x - this._previousPosition.x;
tempY = this.target.y - this._previousPosition.y;
if (tempX !== 0 || tempY !== 0) {
var locAccDiff = this._accumulatedDiff;
tempX = locAccDiff.x + tempX;
@@ -270,8 +270,8 @@ cc.CardinalSplineBy = cc.Class({
startWithTarget:function (target) {
cc.CardinalSplineTo.prototype.startWithTarget.call(this, target);
this._startPosition.x = target.getPositionX();
this._startPosition.y = target.getPositionY();
this._startPosition.x = target.x;
this._startPosition.y = target.y;
},
reverse:function () {
+16 -18
View File
@@ -1101,8 +1101,8 @@ cc.MoveBy = cc.Class({
startWithTarget:function (target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);
var locPosX = target.getPositionX();
var locPosY = target.getPositionY();
var locPosX = target.x;
var locPosY = target.y;
this._previousPosition.x = locPosX;
this._previousPosition.y = locPosY;
this._startPosition.x = locPosX;
@@ -1116,8 +1116,8 @@ cc.MoveBy = cc.Class({
var y = this._positionDelta.y * dt;
var locStartPosition = this._startPosition;
if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
var targetX = this.target.getPositionX();
var targetY = this.target.getPositionY();
var targetX = this.target.x;
var targetY = this.target.y;
var locPreviousPosition = this._previousPosition;
locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x;
@@ -1213,8 +1213,8 @@ cc.MoveTo = cc.Class({
startWithTarget:function (target) {
cc.MoveBy.prototype.startWithTarget.call(this, target);
this._positionDelta.x = this._endPosition.x - target.getPositionX();
this._positionDelta.y = this._endPosition.y - target.getPositionY();
this._positionDelta.x = this._endPosition.x - target.x;
this._positionDelta.y = this._endPosition.y - target.y;
}
});
@@ -1471,8 +1471,8 @@ cc.JumpBy = cc.Class({
startWithTarget:function (target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);
var locPosX = target.getPositionX();
var locPosY = target.getPositionY();
var locPosX = target.x;
var locPosY = target.y;
this._previousPosition.x = locPosX;
this._previousPosition.y = locPosY;
this._startPosition.x = locPosX;
@@ -1489,8 +1489,8 @@ cc.JumpBy = cc.Class({
var x = this._delta.x * dt;
var locStartPosition = this._startPosition;
if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
var targetX = this.target.getPositionX();
var targetY = this.target.getPositionY();
var targetX = this.target.x;
var targetY = this.target.y;
var locPreviousPosition = this._previousPosition;
locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x;
@@ -1672,8 +1672,8 @@ cc.BezierBy = cc.Class({
startWithTarget:function (target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);
var locPosX = target.getPositionX();
var locPosY = target.getPositionY();
var locPosX = target.x;
var locPosY = target.y;
this._previousPosition.x = locPosX;
this._previousPosition.y = locPosY;
this._startPosition.x = locPosX;
@@ -1699,8 +1699,8 @@ cc.BezierBy = cc.Class({
var locStartPosition = this._startPosition;
if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
var targetX = this.target.getPositionX();
var targetY = this.target.getPositionY();
var targetX = this.target.x;
var targetY = this.target.y;
var locPreviousPosition = this._previousPosition;
locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x;
@@ -2268,12 +2268,10 @@ cc.TintTo = cc.Class({
dt = this._computeEaseTime(dt);
var locFrom = this._from, locTo = this._to;
if (locFrom) {
this.target.setColor(
cc.color(
this.target.color = cc.color(
locFrom.r + (locTo.r - locFrom.r) * dt,
locFrom.g + (locTo.g - locFrom.g) * dt,
locFrom.b + (locTo.b - locFrom.b) * dt)
);
locFrom.b + (locTo.b - locFrom.b) * dt);
}
}
});
+5 -6
View File
@@ -790,12 +790,11 @@ cc.Director.prototype = {
* @deprecated
*/
setClearColor: function (clearColor) {
renderer._camera.setColor(
clearColor.r / 255,
clearColor.g / 255,
clearColor.b / 255,
clearColor.a / 255
);
if (!cc.Camera.main) {
return;
}
cc.Camera.main.backgroundColor = clearColor;
},
/**
+3 -2
View File
@@ -42,6 +42,7 @@ const POSITION_CHANGED = 'position-changed';
const SIZE_CHANGED = 'size-changed';
const ANCHOR_CHANGED = 'anchor-changed';
const ROTATION_CHANGED = 'rotation-changed';
const WORLD_MATRIX_CHANGED = 'world-matrix-changed';
const SCALE_CHANGED = 'scale-changed';
const CHILD_REORDER = 'child-reorder';
@@ -963,8 +964,7 @@ var Node = cc.Class({
this._localMatDirty = true;
this._worldMatDirty = true;
this._cullingMask = 1;
this._inheritMask = 1;
this._cullingMask = 1 << this.groupIndex;
},
statics: {
@@ -1941,6 +1941,7 @@ var Node = cc.Class({
else {
math.mat4.copy(this._worldMatrix, this._matrix);
}
this.emit(WORLD_MATRIX_CHANGED);
this._worldMatDirty = false;
for (let i = 0, len = this._children.length; i < len; ++i) {
+152 -88
View File
@@ -31,8 +31,6 @@ const mat4 = cc.vmath.mat4;
const vec2 = cc.vmath.vec2;
const vec3 = cc.vmath.vec3;
let _static_culling_mask = 1;
let _mat4_temp_1 = mat4.create();
let _mat4_temp_2 = mat4.create();
let _vec3_temp_1 = vec3.create();
@@ -40,6 +38,17 @@ let _vec3_temp_2 = vec3.create();
let _cameras = [];
/**
* !#en Values for Camera.clearFlags, determining what to clear when rendering a Camera.
* !#zh 摄像机清除标记位,决定摄像机渲染时会清除哪些状态
* @enum Camera.ClearFlags
*/
let ClearFlags = cc.Enum({
COLOR: 1,
DEPTH: 2,
STENCIL: 4,
});
/**
* !#en
* Camera is usefull when making reel game or other games which need scroll screen.
@@ -61,8 +70,6 @@ let Camera = cc.Class({
'transparent'
]);
camera.setClearFlags(0);
this._fov = Math.PI * 60 / 180;
camera.setFov(this._fov);
camera.setNear(0.1);
@@ -72,23 +79,23 @@ let Camera = cc.Class({
camera.view = view;
camera.dirty = true;
this.cullingMask = 1 << _static_culling_mask++;
camera._cullingMask = view._cullingMask = this.cullingMask;
this._matrixDirty = true;
this._camera = camera;
},
editor: CC_EDITOR && {
menu: 'i18n:MAIN_MENU.component.others/Camera',
inspector: 'packages://inspector/inspectors/comps/camera.js',
executeInEditMode: false
},
properties: {
_targets: {
default: [],
type: cc.Node,
visible: true
},
_cullingMask: 0xffffffff,
_clearFlags: 0,
_backgroundColor: cc.color(51, 77, 120, 255),
_depth: 0,
_zoomRatio: 1,
/**
* !#en
@@ -97,22 +104,116 @@ let Camera = cc.Class({
* 摄像机缩放比率
* @property {Number} zoomRatio
*/
zoomRatio: 1,
zoomRatio: {
get () {
return this._zoomRatio;
},
set (value) {
this._zoomRatio = value;
this._matrixDirty = true;
}
},
/**
* !#en
* This is used to render parts of the scene selectively.
* !#zh
* 决定摄像机会渲染场景的哪一部分。
* @property {Number} cullingMask
*/
cullingMask: {
get () {
return this._cullingMask;
},
set (value) {
this._cullingMask = value;
this._updateCameraMask();
}
},
/**
* !#en
* Determining what to clear when camera rendering.
* !#zh
* 决定摄像机渲染时会清除哪些状态。
* @property {Number} clearFlags
*/
clearFlags: {
get () {
return this._clearFlags;
},
set (value) {
this._clearFlags = value;
this._camera.setClearFlags(value);
}
},
/**
* !#en
* The color with which the screen will be cleared.
* !#zh
* 摄像机用于清除屏幕的背景色。
*/
backgroundColor: {
get () {
return this._backgroundColor;
},
set (value) {
this._backgroundColor = value;
this._updateBackgroundColor();
}
},
/**
* !#en
* Camera's depth in the camera rendering order.
* !#zh
* 摄像机深度,用于决定摄像机的渲染顺序。
*/
depth: {
get () {
return this._depth;
},
set (value) {
this._depth = value;
this._camera.setDepth(value);
}
}
},
statics: {
/**
* !#en
* Current active camera, the scene should only have one active camera at the same time.
* The first enabled camera.
* !#zh
* 当前激活的摄像机,场景中在同一时间内只能有一个激活的摄像机。
* 第一个被激活的摄像机。
* @property {Camera} main
* @static
*/
main: null,
/**
* !#en
* All enabled cameras.
* !#zh
* 激活的所有摄像机。
* @property {[Camera]} cameras
* @static
*/
cameras: _cameras,
ClearFlags: ClearFlags,
/**
* !#en
* Get the first camera which the node belong to.
* !#zh
* 获取节点所在的第一个摄像机。
* @method findCamera
* @param {Node} node
* @return {Camera}
* @static
*/
findCamera (node) {
for (let i = 0, l = _cameras.length; i < l; i++) {
let camera = _cameras[i];
@@ -125,88 +226,48 @@ let Camera = cc.Class({
}
},
_updateCameraMask () {
this._camera._cullingMask = this._cullingMask;
this._camera.view._cullingMask = this._cullingMask;
},
_updateBackgroundColor () {
let color = this._backgroundColor;
this._camera.setColor(
color.r / 255,
color.g / 255,
color.b / 255,
color.a / 255,
);
},
_onMatrixDirty () {
this._matrixDirty = true;
},
onLoad () {
this._camera.setNode(this.node);
this._camera.setClearFlags(this._clearFlags);
this._camera.setDepth(this._depth);
this._updateBackgroundColor();
this._updateCameraMask();
},
onEnable () {
if (CC_EDITOR) return;
if (!Camera.main) {
Camera.main = this;
}
let targets = this._targets;
for (let i = 0, l = targets.length; i < l; i++) {
targets[i]._cullingMask = this.cullingMask;
}
this.node.on('world-matrix-changed', this._onMatrixDirty, this);
this._matrixDirty = true;
renderer.scene.addCamera(this._camera);
_cameras.push(this);
},
onDisable () {
if (CC_EDITOR) return;
if (Camera.main === this) {
Camera.main = null;
}
let targets = this._targets;
for (let i = 0, l = targets.length; i < l; i++) {
targets[i]._cullingMask = 1;
}
this.node.off('world-matrix-changed', this._onMatrixDirty, this);
renderer.scene.removeCamera(this._camera);
cc.js.array.remove(_cameras, this);
},
/**
* !#en
* Add the specified target to camera.
* !#zh
* 将指定的节点添加到摄像机中。
* @method addTarget
* @param {Node} target
*/
addTarget (target) {
if (this._targets.indexOf(target) !== -1) {
return;
}
target._cullingMask = this.cullingMask;
this._targets.push(target);
},
/**
* !#en
* Remove the specified target from camera.
* !#zh
* 将指定的节点从摄像机中移除。
* @method removeTarget
* @param {Node} target
*/
removeTarget (target) {
if (this._targets.indexOf(target) === -1) {
return;
}
target._cullingMask = 1;
cc.js.array.remove(this._targets, target);
},
/**
* !#en
* Get all camera targets.
* !#zh
* 获取所有摄像机目标节点。
* @method getTargets
* @return {[Node]}
*/
getTargets () {
return this._targets;
},
/**
* !#en
* Returns the matrix that transform the node's (local) space coordinates into the camera's space coordinates.
@@ -315,25 +376,28 @@ let Camera = cc.Class({
* @return {Boolean}
*/
containsNode (node) {
return node._inheritMask === this.cullingMask;
return node._cullingMask === this.cullingMask;
},
lateUpdate: !CC_EDITOR && function () {
let node = this.node;
let zoomRatio = this.zoomRatio;
let min = -(zoomRatio/2-0.5);
this._camera.setRect(min,min,zoomRatio,zoomRatio);
node.z = renderer.canvas.height / cc.view.getScaleY() / 1.1566;
node.getWorldMatrix(_mat4_temp_1);
if (!this._matrixDirty) return;
let camera = this._camera;
let fov = Math.atan(Math.tan(this._fov/2) / this.zoomRatio)*2;
camera.setFov(fov);
_vec3_temp_1.x = _mat4_temp_1.m12;
_vec3_temp_1.y = _mat4_temp_1.m13;
_vec3_temp_1.z = 0;
node.z = cc.visibleRect.height / 1.1566;
node.lookAt(_vec3_temp_1);
this._camera.dirty = true;
this._matrixDirty = false;
camera.dirty = true;
}
});
@@ -339,15 +339,6 @@ let CollisionManager = cc.Class({
}
},
attachDebugDrawToCamera: function (camera) {
if (!this._debugDrawer) return;
camera.addTarget(this._debugDrawer);
},
detachDebugDrawFromCamera: function (camera) {
if (!this._debugDrawer) return;
camera.removeTarget(this._debugDrawer);
},
onNodeGroupChanged: function (event) {
let node = event.currentTarget;
let colliders = node.getComponents(cc.Collider);
+16
View File
@@ -162,6 +162,22 @@ var Canvas = cc.Class({
this.applySettings();
this.onResized();
let cameraNode = cc.find('Main Camera', this.node);
if (!cameraNode) {
cameraNode = new cc.Node('Main Camera');
cameraNode.parent = this.node;
cameraNode.setSiblingIndex(0);
}
let camera = cameraNode.getComponent(cc.Camera);
if (!camera) {
camera = cameraNode.addComponent(cc.Camera);
let ClearFlags = cc.Camera.ClearFlags;
camera.clearFlags = ClearFlags.COLOR | ClearFlags.DEPTH;
camera.depth = -1;
}
cc.Camera.main = camera;
},
onDestroy: function () {
+2 -2
View File
@@ -138,8 +138,8 @@ var Scrollbar = cc.Class({
_setOpacity: function(opacity) {
if (this.handle) {
this.node.setOpacity(opacity);
this.handle.node.setOpacity(opacity);
this.node.opacity = opacity;
this.handle.node.opacity = opacity;
}
},
-27
View File
@@ -347,33 +347,6 @@ var PhysicsManager = cc.Class({
}
},
/**
* !#en
* Attach physics debug draw to camera
* !#zh
* 将物理的调试绘制信息附加到指定摄像机上
* @method attachDebugDrawToCamera
* @param {Camera} camera
*/
attachDebugDrawToCamera: function (camera) {
if (!this.debugDrawFlags) return;
this._checkDebugDrawValid();
camera.addTarget(this._debugDrawer.node);
},
/**
* !#en
* Detach physics debug draw to camera
* !#zh
* 将物理的调试绘制信息从指定摄像机上移除
* @method detachDebugDrawFromCamera
* @param {Camera} camera
*/
detachDebugDrawFromCamera: function (camera) {
if (!this.debugDrawFlags) return;
this._checkDebugDrawValid();
camera.removeTarget(this._debugDrawer.node);
},
_registerContactFixture: function (fixture) {
this._contactListener.registerContactFixture(fixture);
},
+25 -22
View File
@@ -83,26 +83,28 @@ module.exports = {
this._walker = new RenderComponentWalker(this.device, this.scene);
this._cameraNode = new cc.Node();
this._camera = new renderEngine.Camera();
this._camera.setColor(0, 0, 0, 1);
this._camera.setFov(Math.PI * 60 / 180);
this._camera.setNear(0.1);
this._camera.setFar(1024);
this._camera.setNode(this._cameraNode);
let view = new renderEngine.View();
this._camera.view = view;
this._camera.dirty = true;
if (CC_EDITOR) {
this._camera.setColor(0, 0, 0, 0);
this._cameraNode = new cc.Node();
this._camera = new renderEngine.Camera();
this._camera.setColor(0, 0, 0, 1);
this._camera.setFov(Math.PI * 60 / 180);
this._camera.setNear(0.1);
this._camera.setFar(1024);
this._camera.setNode(this._cameraNode);
let view = new renderEngine.View();
this._camera.view = view;
this._camera.dirty = true;
if (CC_EDITOR) {
this._camera.setColor(0, 0, 0, 0);
}
this._camera.setStages([
'transparent'
]);
this.scene.addCamera(this._camera);
}
this._camera.setStages([
'transparent'
]);
this.scene.addCamera(this._camera);
let builtins = _initBuiltins(this.device);
this._forward = new renderEngine.ForwardRenderer(this.device, builtins);
@@ -135,16 +137,17 @@ module.exports = {
this._camera.tx = vp.x;
this._camera.ty = vp.y + vp.height;
}
else if (this.canvas) {
let node = this._cameraNode;
else if (CC_EDITOR && this.canvas) {
let canvas = this.canvas;
let scaleX = cc.view.getScaleX();
let scaleY = cc.view.getScaleY();
let zeye = canvas.height / scaleY / 1.1566;
let node = this._cameraNode;
_pos.x = node.x = canvas.width / scaleX / 2;
_pos.y = node.y = canvas.height / scaleY / 2;
node.z = zeye;
_pos.z = 0;
node.z = canvas.height / scaleY / 1.1566;
node.lookAt(_pos);
this._camera.dirty = true;
}
@@ -97,6 +97,11 @@ var RenderComponentWalker = function (device, renderScene) {
this._batchedModels = [];
this._dummyNode = new cc.Node();
this._sortKey = 0;
this._curCameraNode = null;
this._handleRender = this._handleRender.bind(this);
this._postHandleRender = this._postHandleRender.bind(this);
};
RenderComponentWalker.prototype = {
@@ -136,16 +141,12 @@ RenderComponentWalker.prototype = {
},
_handleRender (node) {
if (node._cullingMask !== 1) {
if (node.groupIndex !== 0) {
this._curCameraNode = node;
}
if (this._curCameraNode) {
node._inheritMask = this._curCameraNode._cullingMask;
}
else {
node._inheritMask = 1;
}
let group = this._curCameraNode ? this._curCameraNode.groupIndex : node.groupIndex;
node._cullingMask = 1 << group;
let comp = node._renderComponent;
if (comp) {
@@ -275,7 +276,8 @@ RenderComponentWalker.prototype = {
// Update render data
datas = assembler.updateRenderData(comp, _batchData);
cullingMask = comp.node._inheritMask;
cullingMask = comp.node._cullingMask;
for (let id = 0; id < datas.length; id ++) {
data = datas[id];
+6
View File
@@ -13560,6 +13560,12 @@ module.exports = (function () {
this._reset();
const canvas = this._device._gl.canvas;
scene._cameras.sort((a, b) => {
if (a._depth > b._depth) return 1;
else if (a._depth < b._depth) return -1;
else return 0;
});
for (let i = 0; i < scene._cameras.length; ++i) {
let camera = scene._cameras.data[i];
+16
View File
@@ -471,6 +471,22 @@ if (CC_DEV) {
'isRunning',
]);
markAsRemoved(cc.Camera, [
'addTarget',
'removeTarget',
'getTargets'
]);
markAsRemoved(cc.PhysicsManager, [
'attachDebugDrawToCamera',
'detachDebugDrawFromCamera',
]);
markAsRemoved(cc.CollisionManager, [
'attachDebugDrawToCamera',
'detachDebugDrawFromCamera',
]);
markFunctionWarning(cc.Node.prototype, {
getNodeToParentTransform: 'getLocalMatrix',
getNodeToParentTransformAR: 'getLocalMatrix',
+7 -7
View File
@@ -40,7 +40,7 @@ test('simple spriteQuad trimmed', function () {
var isTrimmed = true;
var s9Sprite = new cc.Scale9Sprite(spriteFrame);
s9Sprite.setContentSize(contentSize);
s9Sprite.setColor(color);
s9Sprite.color = color;
s9Sprite.enableTrimmedContentSize(isTrimmed);
s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.SIMPLE);
s9Sprite._rebuildQuads();
@@ -73,7 +73,7 @@ test('simple spriteQuad no trimmed', function () {
var isTrimmed = false;
var s9Sprite = new cc.Scale9Sprite(spriteFrame);
s9Sprite.setContentSize(contentSize);
s9Sprite.setColor(color);
s9Sprite.color = color;
s9Sprite.enableTrimmedContentSize(isTrimmed);
s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.SIMPLE);
s9Sprite._rebuildQuads();
@@ -112,7 +112,7 @@ test('scale9 spriteQuad trimmed', function () {
s9Sprite.setInsetTop(8);
s9Sprite.setContentSize(contentSize);
s9Sprite.setColor(color);
s9Sprite.color = color;
s9Sprite.enableTrimmedContentSize(isTrimmed);
s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.SLICED);
s9Sprite._rebuildQuads();
@@ -151,7 +151,7 @@ test('tiled spriteQuad trimmed', function () {
var isTrimmed = true;
var s9Sprite = new cc.Scale9Sprite(spriteFrame);
s9Sprite.setContentSize(contentSize);
s9Sprite.setColor(color);
s9Sprite.color = color;
s9Sprite.enableTrimmedContentSize(isTrimmed);
s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.TILED);
s9Sprite._rebuildQuads();
@@ -191,7 +191,7 @@ test('filled-bar-horizontal spriteQuad trimmed', function () {
var isTrimmed = true;
var s9Sprite = new cc.Scale9Sprite(spriteFrame);
s9Sprite.setContentSize(contentSize);
s9Sprite.setColor(color);
s9Sprite.color = color;
s9Sprite.enableTrimmedContentSize(isTrimmed);
s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.FILLED);
s9Sprite.setFillType(cc.Scale9Sprite.FillType.HORIZONTAL);
@@ -241,7 +241,7 @@ test('filled-bar-vertical spriteQuad trimmed', function () {
var isTrimmed = true;
var s9Sprite = new cc.Scale9Sprite(spriteFrame);
s9Sprite.setContentSize(contentSize);
s9Sprite.setColor(color);
s9Sprite.color = color;
s9Sprite.enableTrimmedContentSize(isTrimmed);
s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.FILLED);
s9Sprite.setFillType(cc.Scale9Sprite.FillType.VERTICAL);
@@ -291,7 +291,7 @@ test('filled-bar-radial spriteQuad trimmed', function () {
var isTrimmed = true;
var s9Sprite = new cc.Scale9Sprite(spriteFrame);
s9Sprite.setContentSize(contentSize);
s9Sprite.setColor(color);
s9Sprite.color = color;
s9Sprite.enableTrimmedContentSize(isTrimmed);
s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.FILLED);
s9Sprite.setFillType(cc.Scale9Sprite.FillType.RADIAL);