mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
+19
-9
@@ -377,10 +377,12 @@ An Node can't be added as a child of itself.
|
||||
|
||||
### 1605
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
child already added. It can't be added again
|
||||
|
||||
### 1606
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
child must be non-null
|
||||
|
||||
### 1607
|
||||
@@ -510,6 +512,7 @@ Internal error, should not remove unknown node from parent.
|
||||
|
||||
### 1634
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
addChild: The child to add must be instance of cc.Node, not %s.
|
||||
|
||||
### 1635
|
||||
@@ -1152,6 +1155,10 @@ contentSize parameter is deprecated and ignored for cc.Texture2D initWithData fu
|
||||
|
||||
Lazy init texture with image element failed due to image loading failure: %s
|
||||
|
||||
### 3120
|
||||
|
||||
Loading texture with unsupported type: '%s'. Add '%s' into 'cc.macro.SUPPORT_TEXTURE_FORMATS' please.
|
||||
|
||||
### 3200
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
@@ -1455,12 +1462,16 @@ Please do not specifiy "default" attribute in decorator of "%s" property in "%s"
|
||||
Default value must be initialized at their declaration:
|
||||
```
|
||||
// Before:
|
||||
@property({ default: 0 }) // <--
|
||||
@integer
|
||||
value;
|
||||
@property({
|
||||
type: cc.SpriteFrame
|
||||
default: null // <--
|
||||
})
|
||||
myProp;
|
||||
// After:
|
||||
@integer
|
||||
value = 0; // <--
|
||||
@property({
|
||||
type: cc.SpriteFrame
|
||||
})
|
||||
myProp = null; // <--
|
||||
```
|
||||
|
||||
### 3654
|
||||
@@ -1469,10 +1480,10 @@ Please specifiy a default value for "%s.%s" property at its declaration:
|
||||
```
|
||||
// Before:
|
||||
@property(...)
|
||||
value;
|
||||
myProp;
|
||||
// After:
|
||||
@property(...)
|
||||
value = 0
|
||||
myProp = 0;
|
||||
```
|
||||
|
||||
### 3655
|
||||
@@ -2063,12 +2074,11 @@ Invalid type of %s.%s
|
||||
|
||||
### 5509
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
The 'type' attribute of '%s.%s' must be child class of cc.Asset, otherwise you should use 'url: %s' instead
|
||||
|
||||
### 5510
|
||||
|
||||
The 'type' attribute of '%s.%s' can not be 'Number', use 'Float' or 'Integer' instead please.
|
||||
The 'type' attribute of '%s.%s' can not be 'Number', use cc.Float or cc.Integer instead please.
|
||||
|
||||
### 5511
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -10,10 +10,7 @@ export type BezierControlPoints = [ number, number, number, number ];
|
||||
|
||||
export function bezier (C1: number, C2: number, C3: number, C4: number, t: number) {
|
||||
const t1 = 1 - t;
|
||||
return C1 * t1 * t1 * t1 +
|
||||
C2 * 3 * t1 * t1 * t +
|
||||
C3 * 3 * t1 * t * t +
|
||||
C4 * t * t * t;
|
||||
return t1 * (t1 * (C1 + (C2 * 3 - C1) * t) + C3 * 3 * t * t) + C4 * t * t * t;
|
||||
}
|
||||
legacyCC.bezier = bezier;
|
||||
|
||||
@@ -154,14 +151,9 @@ function cardano (curve: BezierControlPoints, x: number) {
|
||||
|
||||
export function bezierByTime (controlPoints: BezierControlPoints, x: number) {
|
||||
const percent = cardano(controlPoints, x); // t
|
||||
const p0y = 0; // a
|
||||
const p1y = controlPoints[1]; // b
|
||||
const p2y = controlPoints[3]; // c
|
||||
const p3y = 1; // d
|
||||
const t1 = 1 - percent;
|
||||
return p0y * t1 * t1 * t1 +
|
||||
p1y * 3 * percent * t1 * t1 +
|
||||
p2y * 3 * percent * percent * t1 +
|
||||
p3y * percent * percent * percent;
|
||||
// return bezier(0, p1y, p2y, 1, percent);
|
||||
return ((1 - percent) * (p1y + (p2y - p1y) * percent) * 3 + percent * percent) * percent;
|
||||
}
|
||||
legacyCC.bezierByTime = bezierByTime;
|
||||
|
||||
@@ -265,7 +265,7 @@ export class ImageAsset extends Asset {
|
||||
return { fmt: extensionIndices.join('_'), w: this.width, h: this.height };
|
||||
}
|
||||
|
||||
public _deserialize (data: any, handle: any) {
|
||||
public _deserialize (data: any) {
|
||||
let fmtStr = '';
|
||||
if (typeof data === 'string') {
|
||||
fmtStr = data;
|
||||
@@ -278,6 +278,7 @@ export class ImageAsset extends Asset {
|
||||
const device = _getGlobalDevice();
|
||||
const extensionIDs = fmtStr.split('_');
|
||||
|
||||
let defaultExt = '';
|
||||
let preferedExtensionIndex = Number.MAX_VALUE;
|
||||
let format = this._format;
|
||||
let ext = '';
|
||||
@@ -286,7 +287,7 @@ export class ImageAsset extends Asset {
|
||||
const extFormat = extensionID.split('@');
|
||||
|
||||
const i = parseInt(extFormat[0], undefined);
|
||||
const tmpExt = ImageAsset.extnames[i] || extFormat.join();
|
||||
const tmpExt = ImageAsset.extnames[i] || extFormat[0];
|
||||
|
||||
const index = SupportTextureFormats.indexOf(tmpExt);
|
||||
if (index !== -1 && index < preferedExtensionIndex) {
|
||||
@@ -309,19 +310,18 @@ export class ImageAsset extends Asset {
|
||||
ext = tmpExt;
|
||||
format = fmt;
|
||||
}
|
||||
else if (!defaultExt) {
|
||||
defaultExt = tmpExt;
|
||||
}
|
||||
}
|
||||
|
||||
if (ext) {
|
||||
this._setRawAsset(ext);
|
||||
this._format = format;
|
||||
}
|
||||
|
||||
// preset uuid to get correct nativeUrl
|
||||
const loadingItem = handle.customEnv;
|
||||
const uuid = loadingItem && loadingItem.uuid;
|
||||
if (uuid) {
|
||||
this._uuid = uuid;
|
||||
this._url = this.nativeUrl;
|
||||
else {
|
||||
this._setRawAsset(defaultExt);
|
||||
warnID(3120, defaultExt, defaultExt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ export class UIRenderable extends RenderableComponent {
|
||||
protected _uiMaterial: Material | null = null;
|
||||
protected _uiMaterialIns: MaterialInstance | null = null;
|
||||
|
||||
protected getUIRenderMaterial () {
|
||||
public getUIRenderMaterial () {
|
||||
return this._uiMaterialIns || this._uiMaterial;
|
||||
}
|
||||
|
||||
@@ -215,6 +215,31 @@ export class UIRenderable extends RenderableComponent {
|
||||
protected _uiMaterialDirty = false;
|
||||
protected _uiMatInsDirty = false;
|
||||
|
||||
// materialInstance only for Stencil // Will remove at v3.0
|
||||
protected _materialInstanceForStencil;
|
||||
public getMaterialInstanceForStencil () {
|
||||
if (!this._materialInstanceForStencil) {
|
||||
let patentMaterial;
|
||||
if (this.getRenderMaterial(0)) {
|
||||
patentMaterial = this.getMaterial(0);
|
||||
} else {
|
||||
patentMaterial = this._uiMaterial;
|
||||
}
|
||||
_matInsInfo.owner = this;
|
||||
_matInsInfo.parent = patentMaterial;
|
||||
this._materialInstanceForStencil = new MaterialInstance(_matInsInfo);
|
||||
}
|
||||
return this._materialInstanceForStencil;
|
||||
}
|
||||
|
||||
protected _onMaterialModified (idx: number, material: Material | null) {
|
||||
if (this._materialInstanceForStencil) {
|
||||
const inst = this._materialInstanceForStencil;
|
||||
inst.destroy();
|
||||
this._materialInstanceForStencil = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The user customized material, if not set, it will use builtin material resources, and will show nothing on inspector field.
|
||||
* @zh 用户自定义材质,如果没有设置过,那么将使用引擎内置的材质资源,在面板上也不会显示。
|
||||
@@ -480,6 +505,12 @@ export class UIRenderable extends RenderableComponent {
|
||||
}
|
||||
this._uiMaterialDirty = false;
|
||||
if(!init) {this._uiMatInsDirty = true;}
|
||||
// materialInstance only for Stencil // Will remove at v3.0
|
||||
if(this._materialInstanceForStencil) {
|
||||
const inst = this._materialInstanceForStencil;
|
||||
inst.destroy();
|
||||
this._materialInstanceForStencil = null;
|
||||
}
|
||||
return this._uiMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,9 +142,6 @@ function defineProp (cls, className, propName, val) {
|
||||
for (let i = 0; i < attrs.length; i++) {
|
||||
const attr: any = attrs[i];
|
||||
attributeUtils.attr(cls, propName, attr);
|
||||
if (attr.serializable === false) {
|
||||
pushUnique(cls.__values__, propName);
|
||||
}
|
||||
// register callback
|
||||
if (attr._onAfterProp) {
|
||||
onAfterProp.push(attr._onAfterProp);
|
||||
@@ -561,7 +558,7 @@ function parseAttributes (constructor: Function, attributes: IAcceptableAttribut
|
||||
if (primitiveType) {
|
||||
result.push({
|
||||
type,
|
||||
_onAfterProp: (EDITOR || TEST) && !attributes._short ?
|
||||
_onAfterProp: ((EDITOR && !window.Build) || TEST) && !attributes._short ?
|
||||
attributeUtils.getTypeChecker(primitiveType, 'cc.' + type) :
|
||||
undefined,
|
||||
});
|
||||
@@ -594,7 +591,7 @@ function parseAttributes (constructor: Function, attributes: IAcceptableAttribut
|
||||
}
|
||||
} else if (typeof type === 'function') {
|
||||
let typeChecker: OnAfterProp | undefined;
|
||||
if ((EDITOR || TEST) && !attributes._short) {
|
||||
if (((EDITOR && !window.Build) || TEST) && !attributes._short) {
|
||||
typeChecker = attributes.url ?
|
||||
attributeUtils.getTypeChecker('String', 'cc.String') :
|
||||
attributeUtils.getObjTypeChecker(type);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { IExposedAttributes } from '../utils/attribute-defines';
|
||||
import { LegacyPropertyDecorator, getSubDict, getClassCache } from './utils';
|
||||
import { warnID, errorID } from '../../platform/debug';
|
||||
import { js } from '../../utils/js';
|
||||
import { DEV } from 'internal:constants';
|
||||
import { DEV, EDITOR, TEST } from 'internal:constants';
|
||||
import { getFullFormOfProperty } from '../utils/preprocess-class';
|
||||
|
||||
export type SimplePropertyType = Function | string | typeof CCString | typeof CCInteger | typeof CCFloat | typeof CCBoolean;
|
||||
@@ -129,11 +129,11 @@ function genProperty (
|
||||
fullOptions = fullOptions || options;
|
||||
}
|
||||
const existsPropertyRecord = properties[propertyKey];
|
||||
const propertyRecord = js.mixin(existsPropertyRecord || {}, fullOptions || {});
|
||||
const propertyRecord = js.mixin(existsPropertyRecord || {}, fullOptions || options || {});
|
||||
|
||||
if (isGetset) {
|
||||
// typescript or babel
|
||||
if (DEV && options && ((fullOptions || options).get || (fullOptions || options).set)) {
|
||||
if (DEV && options && (fullOptions.get || fullOptions.set)) {
|
||||
const errorProps = getSubDict(cache, 'errorProps');
|
||||
if (!errorProps[propertyKey]) {
|
||||
errorProps[propertyKey] = true;
|
||||
@@ -173,8 +173,8 @@ function genProperty (
|
||||
}
|
||||
}
|
||||
|
||||
if (DEV) {
|
||||
if (options && options.hasOwnProperty('default')) {
|
||||
if ((EDITOR && !window.Build) || TEST) {
|
||||
if (!fullOptions && options && options.hasOwnProperty('default')) {
|
||||
warnID(3653, propertyKey, js.getClassName(ctor));
|
||||
} else if (!isDefaultValueSpecified) {
|
||||
warnID(3654, js.getClassName(ctor), propertyKey);
|
||||
@@ -185,4 +185,4 @@ function genProperty (
|
||||
}
|
||||
|
||||
properties[propertyKey] = propertyRecord;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,6 +362,32 @@ class Parser {
|
||||
return codeArray;
|
||||
}
|
||||
|
||||
public instantiateTypedArray (value) {
|
||||
let type = value.constructor.name;
|
||||
if (value.length === 0) {
|
||||
return 'new ' + type;
|
||||
}
|
||||
|
||||
const arrayVar = LOCAL_ARRAY + (++this.localVariableId);
|
||||
const declaration = new Declaration(arrayVar, 'new ' + type + '(' + value.length + ')');
|
||||
const codeArray = [declaration];
|
||||
|
||||
// assign a _iN$t flag to indicate that this object has been parsed.
|
||||
value._iN$t = {
|
||||
globalVar: '', // the name of declared global variable used to access this object
|
||||
source: codeArray, // the source code array for this object
|
||||
};
|
||||
this.objsToClear_iN$t.push(value);
|
||||
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
if (value[i] !== 0) {
|
||||
const statement = arrayVar + '[' + i + ']=';
|
||||
writeAssignment(codeArray, statement, value[i]);
|
||||
}
|
||||
}
|
||||
return codeArray;
|
||||
}
|
||||
|
||||
public enumerateField (obj, key, value) {
|
||||
if (typeof value === 'object' && value) {
|
||||
const _iN$t = value._iN$t;
|
||||
@@ -383,6 +409,9 @@ class Parser {
|
||||
}
|
||||
return globalVar;
|
||||
}
|
||||
else if (ArrayBuffer.isView(value)) {
|
||||
return this.instantiateTypedArray(value);
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
return this.instantiateArray(value);
|
||||
}
|
||||
|
||||
@@ -243,11 +243,23 @@ function instantiateObj (obj, parent) {
|
||||
return obj;
|
||||
}
|
||||
let clone;
|
||||
if (ArrayBuffer.isView(obj)) {
|
||||
let len = (obj as any).length;
|
||||
clone = new ((obj as any).constructor)(len);
|
||||
// @ts-ignore
|
||||
obj._iN$t = clone;
|
||||
objsToClearTmpVar.push(obj);
|
||||
for (let i = 0; i < len; ++i) {
|
||||
clone[i] = obj[i];
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
if (Array.isArray(obj)) {
|
||||
const len = obj.length;
|
||||
clone = new Array(len);
|
||||
// @ts-ignore
|
||||
obj._iN$t = clone;
|
||||
objsToClearTmpVar.push(obj);
|
||||
for (let i = 0; i < len; ++i) {
|
||||
const value = obj[i];
|
||||
if (typeof value === 'object' && value) {
|
||||
@@ -257,7 +269,6 @@ function instantiateObj (obj, parent) {
|
||||
clone[i] = value;
|
||||
}
|
||||
}
|
||||
objsToClearTmpVar.push(obj);
|
||||
return clone;
|
||||
}
|
||||
else if (obj._objFlags & Destroyed) {
|
||||
|
||||
@@ -454,7 +454,7 @@ declare namespace CCObject {
|
||||
|
||||
/**
|
||||
* @en Dont destroy automatically when loading a new scene.
|
||||
* @zh 加载一个新场景时,不自动删除该对象
|
||||
* @zh 加载一个新场景时,不自动删除该对象。
|
||||
* @private
|
||||
*/
|
||||
DontDestroy,
|
||||
@@ -474,7 +474,7 @@ declare namespace CCObject {
|
||||
|
||||
/**
|
||||
* @en The lock node, when the node is locked, cannot be clicked in the scene.
|
||||
* @zh 锁定节点,锁定后场景内不能点击
|
||||
* @zh 锁定节点,锁定后场景内不能点击。
|
||||
* @private
|
||||
*/
|
||||
LockedInEditor,
|
||||
@@ -492,8 +492,8 @@ declare namespace CCObject {
|
||||
// FLAGS FOR EDITOR
|
||||
|
||||
/// **
|
||||
// * @en This flag is readonly, it can only be used as an argument of scene.addEntity() or Entity.createWithFlags().
|
||||
// * @zh 该标记只读,它只能被用作 scene.addEntity()的一个参数。
|
||||
// * @en Hide the object in editor.
|
||||
// * @zh 在编辑器中隐藏该对象。
|
||||
// */
|
||||
HideInHierarchy,
|
||||
|
||||
@@ -507,9 +507,6 @@ declare namespace CCObject {
|
||||
// */
|
||||
// Hide: Hide,
|
||||
|
||||
//// UUID Registered in editor
|
||||
// RegisteredInEditor: RegisteredInEditor,
|
||||
|
||||
// FLAGS FOR COMPONENT
|
||||
|
||||
IsPreloadStarted,
|
||||
|
||||
@@ -269,6 +269,7 @@ Callbacks: {
|
||||
}
|
||||
*/
|
||||
|
||||
// Ensures the type matches its default value
|
||||
export function getTypeChecker (type: string, attributeName: string) {
|
||||
return function (constructor: Function, mainPropertyName: string) {
|
||||
const propInfo = '"' + getClassName(constructor) + '.' + mainPropertyName + '"';
|
||||
@@ -278,7 +279,7 @@ export function getTypeChecker (type: string, attributeName: string) {
|
||||
if (mainPropAttrsType === CCInteger || mainPropAttrsType === CCFloat) {
|
||||
mainPropAttrsType = 'Number';
|
||||
} else if (mainPropAttrsType === CCString || mainPropAttrsType === CCBoolean) {
|
||||
mainPropAttrsType = mainPropAttrsType.toString();
|
||||
mainPropAttrsType = '' + mainPropAttrsType;
|
||||
}
|
||||
if (mainPropAttrsType !== type) {
|
||||
warnID(3604, propInfo);
|
||||
@@ -326,6 +327,7 @@ export function getTypeChecker (type: string, attributeName: string) {
|
||||
};
|
||||
}
|
||||
|
||||
// Ensures the type matches its default value
|
||||
export function getObjTypeChecker (typeCtor) {
|
||||
return function (classCtor, mainPropName) {
|
||||
getTypeChecker('Object', 'type')(classCtor, mainPropName);
|
||||
|
||||
@@ -141,8 +141,10 @@ function checkUrl (val, className, propName, url) {
|
||||
* 解析类型
|
||||
*/
|
||||
function parseType (val, type, className, propName) {
|
||||
const STATIC_CHECK = (EDITOR && DEV) || TEST;
|
||||
|
||||
if (Array.isArray(type)) {
|
||||
if ((EDITOR || TEST) && 'default' in val) {
|
||||
if (STATIC_CHECK && 'default' in val) {
|
||||
if (!legacyCC.Class.isArray(val.default)) {
|
||||
warnID(5507, className, propName);
|
||||
}
|
||||
@@ -159,41 +161,43 @@ function parseType (val, type, className, propName) {
|
||||
return errorID(5508, className, propName);
|
||||
}
|
||||
}
|
||||
if (EDITOR || TEST) {
|
||||
if (typeof type === 'function') {
|
||||
if (legacyCC.RawAsset.isRawAssetType(type)) {
|
||||
warnID(5509, className, propName, js.getClassName(type));
|
||||
} else if (type === String) {
|
||||
val.type = legacyCC.String;
|
||||
if (typeof type === 'function') {
|
||||
if (type === String) {
|
||||
val.type = legacyCC.String;
|
||||
if (STATIC_CHECK) {
|
||||
warnID(3608, `"${className}.${propName}"`);
|
||||
} else if (type === Boolean) {
|
||||
val.type = legacyCC.Boolean;
|
||||
}
|
||||
} else if (type === Boolean) {
|
||||
val.type = legacyCC.Boolean;
|
||||
if (STATIC_CHECK) {
|
||||
warnID(3609, `"${className}.${propName}"`);
|
||||
} else if (type === Number) {
|
||||
val.type = legacyCC.Float;
|
||||
}
|
||||
} else if (type === Number) {
|
||||
val.type = legacyCC.Float;
|
||||
if (STATIC_CHECK) {
|
||||
warnID(3610, `"${className}.${propName}"`);
|
||||
}
|
||||
} else {
|
||||
switch (type) {
|
||||
case 'Number':
|
||||
warnID(5510, className, propName);
|
||||
break;
|
||||
case 'String':
|
||||
warn(`The type of "${className}.${propName}" must be CCString, not "String".`);
|
||||
break;
|
||||
case 'Boolean':
|
||||
warn(`The type of "${className}.${propName}" must be CCBoolean, not "Boolean".`);
|
||||
break;
|
||||
case 'Float':
|
||||
warn(`The type of "${className}.${propName}" must be CCFloat, not "Float".`);
|
||||
break;
|
||||
case 'Integer':
|
||||
warn(`The type of "${className}.${propName}" must be CCInteger, not "Integer".`);
|
||||
break;
|
||||
case null:
|
||||
warnID(5511, className, propName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STATIC_CHECK) {
|
||||
switch (type) {
|
||||
case 'Number':
|
||||
warnID(5510, className, propName);
|
||||
break;
|
||||
case 'String':
|
||||
warn(`The type of "${className}.${propName}" must be CCString, not "String".`);
|
||||
break;
|
||||
case 'Boolean':
|
||||
warn(`The type of "${className}.${propName}" must be CCBoolean, not "Boolean".`);
|
||||
break;
|
||||
case 'Float':
|
||||
warn(`The type of "${className}.${propName}" must be CCFloat, not "Float".`);
|
||||
break;
|
||||
case 'Integer':
|
||||
warn(`The type of "${className}.${propName}" must be CCInteger, not "Integer".`);
|
||||
break;
|
||||
case null:
|
||||
warnID(5511, className, propName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { Mat3, Mat4, Quat, Vec3 } from '../../core/math';
|
||||
import enums from './enums';
|
||||
import { IVec3Like } from '../math/type-define';
|
||||
import sphere from './sphere';
|
||||
|
||||
const _v3_tmp = new Vec3();
|
||||
const _v3_tmp2 = new Vec3();
|
||||
@@ -134,6 +135,33 @@ export default class aabb {
|
||||
return aabb.fromPoints(out, _v3_tmp3, _v3_tmp4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* aabb to sphere
|
||||
* @zh
|
||||
* 包围盒转包围球
|
||||
* @param out 接受操作的 sphere。
|
||||
* @param a 输入的 aabb。
|
||||
*/
|
||||
public static toBoundingSphere (out: sphere, a: aabb) {
|
||||
a.getBoundary(_v3_tmp, _v3_tmp2);
|
||||
|
||||
// Initialize sphere
|
||||
out.center.set(_v3_tmp);
|
||||
out.radius = 0.0;
|
||||
|
||||
// Calculate sphere
|
||||
Vec3.subtract(_v3_tmp3, _v3_tmp2, out.center);
|
||||
const dist = _v3_tmp3.length();
|
||||
|
||||
const half = dist * 0.5;
|
||||
out.radius += half;
|
||||
Vec3.multiplyScalar(_v3_tmp3, _v3_tmp3, half / dist);
|
||||
Vec3.add(out.center, out.center, _v3_tmp3);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Transform this aabb.
|
||||
|
||||
@@ -60,12 +60,12 @@ export function pt_point_aabb (out: Vec3, point: Vec3, aabb_: aabb): Vec3 {
|
||||
Vec3.add(max, aabb_.center, aabb_.halfExtents);
|
||||
|
||||
out.x = (out.x < min.x) ? min.x : out.x;
|
||||
out.y = (out.y < min.x) ? min.y : out.y;
|
||||
out.z = (out.z < min.x) ? min.z : out.z;
|
||||
out.y = (out.y < min.y) ? min.y : out.y;
|
||||
out.z = (out.z < min.z) ? min.z : out.z;
|
||||
|
||||
out.x = (out.x > max.x) ? max.x : out.x;
|
||||
out.y = (out.y > max.x) ? max.y : out.y;
|
||||
out.z = (out.z > max.x) ? max.z : out.z;
|
||||
out.y = (out.y > max.y) ? max.y : out.y;
|
||||
out.z = (out.z > max.z) ? max.z : out.z;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -109,8 +109,11 @@ export default class sphere {
|
||||
* 球跟点合并
|
||||
*/
|
||||
public static mergePoint (out: sphere, s: sphere, point: Vec3) {
|
||||
// if sphere.radius Less than 0,
|
||||
// Set this point as anchor,
|
||||
// And set radius to 0.
|
||||
if (s.radius < 0.0) {
|
||||
out.center = point;
|
||||
out.center.set(point);
|
||||
out.radius = 0.0;
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ import { EDITOR, DEBUG, JSB } from 'internal:constants';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { Details } from '../data/deserialize';
|
||||
|
||||
const MissingClass = EDITOR && EditorExtends.MissingReporter.classInstance; // 合并有冲突就丢弃此改动
|
||||
|
||||
export function isSceneObj (json) {
|
||||
let SCENE_ID = 'cc.Scene';
|
||||
let PREFAB_ID = 'cc.Prefab';
|
||||
@@ -224,13 +226,7 @@ function canDeferredLoad (asset, item, isScene) {
|
||||
return res;
|
||||
}
|
||||
|
||||
let MissingClass;
|
||||
|
||||
export function loadUuid (item, callback) {
|
||||
if (EDITOR) {
|
||||
MissingClass = MissingClass || EditorExtends.MissingReporter.classInstance;
|
||||
}
|
||||
|
||||
let json;
|
||||
if (typeof item.content === 'string') {
|
||||
try {
|
||||
@@ -256,19 +252,19 @@ export function loadUuid (item, callback) {
|
||||
return new Error(getError(4923, item.id));
|
||||
}
|
||||
|
||||
let classFinder;
|
||||
let classFinder, missingClass; // 合并有冲突就丢弃此改动
|
||||
let isScene = isSceneObj(json);
|
||||
if (isScene) {
|
||||
if (EDITOR) {
|
||||
MissingClass.hasMissingClass = false;
|
||||
missingClass = MissingClass; // 合并有冲突就丢弃此改动
|
||||
classFinder = function (type, data, owner, propName) {
|
||||
let res = MissingClass.classFinder(type, data, owner, propName);
|
||||
let res = missingClass.classFinder(type, data, owner, propName); // 合并有冲突就丢弃此改动
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
return legacyCC._MissingScript.getMissingWrapper(type, data);
|
||||
};
|
||||
classFinder.onDereferenced = MissingClass.classFinder.onDereferenced;
|
||||
classFinder.onDereferenced = missingClass.classFinder.onDereferenced; // 合并有冲突就丢弃此改动
|
||||
}
|
||||
else {
|
||||
classFinder = legacyCC._MissingScript.safeFindClass;
|
||||
@@ -304,8 +300,10 @@ export function loadUuid (item, callback) {
|
||||
|
||||
asset._uuid = item.uuid;
|
||||
|
||||
if (EDITOR && isScene && MissingClass.hasMissingClass) {
|
||||
MissingClass.reportMissingClass(asset);
|
||||
// 合并有冲突就丢弃此改动
|
||||
if (EDITOR && missingClass) {
|
||||
missingClass.reportMissingClass(asset);
|
||||
missingClass.reset();
|
||||
}
|
||||
|
||||
let deferredLoad = canDeferredLoad(asset, item, isScene);
|
||||
|
||||
@@ -287,7 +287,7 @@ export class Color extends ValueType {
|
||||
|
||||
set a (alpha) {
|
||||
alpha = ~~clamp(alpha, 0, 255);
|
||||
this._val = ((this._val & 0x00ffffff) | ((alpha << 24) >>> 0)) >>> 0;
|
||||
this._val = ((this._val & 0x00ffffff) | (alpha << 24)) >>> 0;
|
||||
}
|
||||
|
||||
// compatibility with vector interfaces
|
||||
@@ -668,7 +668,7 @@ export class Color extends ValueType {
|
||||
}
|
||||
|
||||
public _set_a_unsafe (alpha) {
|
||||
this._val = ((this._val & 0x00ffffff) | ((alpha << 24) >>> 0)) >>> 0;
|
||||
this._val = ((this._val & 0x00ffffff) | (alpha << 24)) >>> 0;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,14 +183,35 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
|
||||
if (mainLight && shadowInfo.type === ShadowType.ShadowMap) {
|
||||
// light view
|
||||
const shadowCameraView = getShadowWorldMatrix(this, mainLight.node!.worldRotation, mainLight.direction);
|
||||
Mat4.invert(matShadowView, shadowCameraView);
|
||||
let shadowCameraView: Mat4;
|
||||
|
||||
// light proj
|
||||
const x: number = shadowInfo.orthoSize * shadowInfo.aspect;
|
||||
const y: number = shadowInfo.orthoSize;
|
||||
let x: number = 0;
|
||||
let y: number = 0;
|
||||
let far: number = 0;
|
||||
if (shadowInfo.autoAdapt) {
|
||||
shadowCameraView = getShadowWorldMatrix(this, mainLight.node?.getWorldRotation()!, mainLight.direction);
|
||||
// if orthoSize is the smallest, auto calculate orthoSize.
|
||||
const radius = shadowInfo.sphere.radius;
|
||||
x = radius * shadowInfo.aspect;
|
||||
y = radius;
|
||||
|
||||
far = Math.min(shadowInfo.receiveSphere.radius * 2.0 * Math.sqrt(2.0), 2000.0);
|
||||
if(radius >= 500) { shadowInfo.size.set(2048, 2048); }
|
||||
else if (radius < 500 && radius >= 100) { shadowInfo.size.set(1024, 1024); }
|
||||
} else {
|
||||
shadowCameraView = mainLight.node!.getWorldMatrix();
|
||||
|
||||
x = shadowInfo.orthoSize * shadowInfo.aspect;
|
||||
y = shadowInfo.orthoSize;
|
||||
|
||||
far = shadowInfo.far;
|
||||
}
|
||||
|
||||
Mat4.invert(matShadowView, shadowCameraView!);
|
||||
|
||||
const projectionSignY = device.screenSpaceSignY * device.UVSpaceSignY; // always offscreen
|
||||
Mat4.ortho(matShadowViewProj, -x, x, -y, y, shadowInfo.near, shadowInfo.far,
|
||||
Mat4.ortho(matShadowViewProj, -x, x, -y, y, shadowInfo.near, far,
|
||||
device.clipSpaceMinZ, projectionSignY);
|
||||
Mat4.multiply(matShadowViewProj, matShadowViewProj, matShadowView);
|
||||
Mat4.toArray(this._shadowUBO, matShadowViewProj, UBOShadow.MAT_LIGHT_VIEW_PROJ_OFFSET);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @hidden
|
||||
*/
|
||||
|
||||
import { intersect, sphere } from '../../geometry';
|
||||
import { aabb, intersect, frustum } from '../../geometry';
|
||||
import { Model } from '../../renderer/scene/model';
|
||||
import { Camera, SKYBOX_FLAG } from '../../renderer/scene/camera';
|
||||
import { Layers } from '../../scene-graph/layers';
|
||||
@@ -12,13 +12,17 @@ import { ForwardPipeline } from './forward-pipeline';
|
||||
import { RenderView } from '../';
|
||||
import { Pool } from '../../memop';
|
||||
import { IRenderObject, UBOShadow } from '../define';
|
||||
import { ShadowType } from '../../renderer/scene/shadows';
|
||||
import { SphereLight, DirectionalLight} from '../../renderer/scene';
|
||||
import { ShadowType, Shadows } from '../../renderer/scene/shadows';
|
||||
import { SphereLight, DirectionalLight, RenderScene} from '../../renderer/scene';
|
||||
|
||||
const _tempVec3 = new Vec3();
|
||||
const _dir_negate = new Vec3();
|
||||
const _vec3_p = new Vec3();
|
||||
const _mat4_trans = new Mat4();
|
||||
const _castWorldBounds = new aabb();
|
||||
const _receiveWorldBounds = new aabb();
|
||||
let _castBoundsInited = false;
|
||||
let _receiveBoundsInited = false;
|
||||
|
||||
const roPool = new Pool<IRenderObject>(() => ({ model: null!, depth: 0 }), 128);
|
||||
const shadowPool = new Pool<IRenderObject>(() => ({ model: null!, depth: 0 }), 128);
|
||||
@@ -120,16 +124,18 @@ function updateDirLight (pipeline: ForwardPipeline, light: DirectionalLight) {
|
||||
export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
const camera = view.camera;
|
||||
const scene = camera.scene!;
|
||||
const mainLight = scene.mainLight;
|
||||
const shadows = pipeline.shadows;
|
||||
|
||||
const renderObjects = pipeline.renderObjects;
|
||||
roPool.freeArray(renderObjects); renderObjects.length = 0;
|
||||
const shadowObjects = pipeline.shadowObjects;
|
||||
shadowPool.freeArray(shadowObjects); shadowObjects.length = 0;
|
||||
|
||||
const mainLight = scene.mainLight;
|
||||
const shadows = pipeline.shadows;
|
||||
const shadowSphere = shadows.sphere;
|
||||
shadowSphere.center.set(0.0, 0.0, 0.0);
|
||||
shadowSphere.radius = 0.01;
|
||||
// Each time the calculation,
|
||||
// reset the flag.
|
||||
_castBoundsInited = false;
|
||||
_receiveBoundsInited = false;
|
||||
|
||||
if (shadows.enabled) {
|
||||
Color.toArray(pipeline.shadowUBO, shadows.shadowColor, UBOShadow.SHADOW_COLOR_OFFSET);
|
||||
@@ -163,11 +169,25 @@ export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
(view.visibility & model.visFlags)) {
|
||||
|
||||
// shadow render Object
|
||||
if (model.castShadow) {
|
||||
sphere.mergeAABB(shadowSphere, shadowSphere, model.worldBounds!);
|
||||
if (model.castShadow && model.worldBounds) {
|
||||
if (!_castBoundsInited) {
|
||||
_castWorldBounds.copy(model.worldBounds);
|
||||
_castBoundsInited = true;
|
||||
}
|
||||
aabb.merge(_castWorldBounds, _castWorldBounds, model.worldBounds);
|
||||
shadowObjects.push(getCastShadowRenderObject(model, camera));
|
||||
}
|
||||
|
||||
// Even if the obstruction is not in the field of view,
|
||||
// the shadow is still visible.
|
||||
if (model.receiveShadow && model.worldBounds) {
|
||||
if(!_receiveBoundsInited) {
|
||||
_receiveWorldBounds.copy(model.worldBounds);
|
||||
_receiveBoundsInited = true;
|
||||
}
|
||||
aabb.merge(_receiveWorldBounds, _receiveWorldBounds, model.worldBounds);
|
||||
}
|
||||
|
||||
// frustum culling
|
||||
if (model.worldBounds && !intersect.aabb_frustum(model.worldBounds, camera.frustum)) {
|
||||
continue;
|
||||
@@ -178,4 +198,8 @@ export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_castWorldBounds) { aabb.toBoundingSphere(shadows.sphere, _castWorldBounds); }
|
||||
|
||||
if (_receiveWorldBounds) { aabb.toBoundingSphere(shadows.receiveSphere, _receiveWorldBounds); }
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ const ERROR_MAP_URL = 'https://github.com/cocos-creator/engine/blob/3d/EngineErr
|
||||
// The html element displays log in web page (DebugMode.INFO_FOR_WEB_PAGE)
|
||||
let logList: HTMLTextAreaElement | null = null;
|
||||
|
||||
let ccLog = console.log;
|
||||
let ccLog = console.log.bind(console);
|
||||
|
||||
let ccWarn = console.log;
|
||||
let ccWarn = ccLog;
|
||||
|
||||
let ccError = console.log;
|
||||
let ccError = ccLog;
|
||||
|
||||
let ccAssert = (condition: any, message?: any, ...optionalParams: any[]) => {
|
||||
if (!condition) {
|
||||
@@ -352,7 +352,7 @@ export enum DebugMode {
|
||||
* @en Gets error message with the error id and possible parameters.
|
||||
* @zh 通过 error id 和必要的参数来获取错误信息。
|
||||
*/
|
||||
export function getError (errorId: any, ...param: any[]): string {
|
||||
export function getError (errorId: number, ...param: any[]): string {
|
||||
return errorFormatter(errorId, ...param);
|
||||
}
|
||||
|
||||
|
||||
+21
-51
@@ -401,6 +401,13 @@ export const sys: { [x: string]: any; } = {
|
||||
* @default 119
|
||||
*/
|
||||
LINKSURE: 119,
|
||||
/**
|
||||
* @en Platform - Xiaomi Game
|
||||
* @zh Platform - 小米小游戏
|
||||
* @default 111
|
||||
*/
|
||||
XIAOMI_GAME: 111,
|
||||
|
||||
/**
|
||||
* @en Browser Type - WeChat inner browser
|
||||
* @zh 浏览器类型 - 微信内置浏览器
|
||||
@@ -419,18 +426,24 @@ export const sys: { [x: string]: any; } = {
|
||||
* @default "huaweiquickgame"
|
||||
*/
|
||||
BROWSER_TYPE_HUAWEI_GAME: 'huaweiquickgame',
|
||||
/**
|
||||
/**
|
||||
* @en Browser Type - OPPO mini Game
|
||||
* @zh 浏览器类型 - OPPO小游戏
|
||||
* @default "oppogame"
|
||||
*/
|
||||
BROWSER_TYPE_OPPO_GAME: 'oppogame',
|
||||
/**
|
||||
* @en Browser Type - vivo mini Game
|
||||
* @zh 浏览器类型 - vivo小游戏
|
||||
* @default "vivogame"
|
||||
*/
|
||||
BROWSER_TYPE_VIVO_GAME: 'vivogame',
|
||||
* @en Browser Type - vivo mini Game
|
||||
* @zh 浏览器类型 - vivo小游戏
|
||||
* @default "vivogame"
|
||||
*/
|
||||
BROWSER_TYPE_VIVO_GAME: 'vivogame',
|
||||
/**
|
||||
* @en Browser Type - Xiaomi Game
|
||||
* @zh 浏览器类型 - 小米小游戏
|
||||
* @default "xiaomigame"
|
||||
*/
|
||||
BROWSER_TYPE_XIAOMI_GAME: "xiaomigame",
|
||||
/**
|
||||
* @en Browser Type - Android Browser
|
||||
* @zh 浏览器类型 - 安卓浏览器
|
||||
@@ -1022,7 +1035,7 @@ else {
|
||||
sys.browserVersion = '';
|
||||
/* Determine the browser version number */
|
||||
(function () {
|
||||
const versionReg1 = /(mqqbrowser|micromessenger|qqbrowser|sogou|qzone|liebao|maxthon|uc|ucbs|360 aphone|360|baiduboxapp|baidu|maxthon|mxbrowser|miui)(mobile)?(browser)?\/?([\d.]+)/i;
|
||||
const versionReg1 = /(mqqbrowser|micromessenger|qqbrowser|sogou|qzone|liebao|maxthon|uc|ucbs|360 aphone|360|baiduboxapp|baidu|maxthon|mxbrowser|miui(?:.hybrid)?)(mobile)?(browser)?\/?([\d.]+)/i;
|
||||
const versionReg2 = /(qq|chrome|safari|firefox|trident|opera|opr\/|oupeng)(mobile)?(browser)?\/?([\d.]+)/i;
|
||||
let tmp = ua.match(versionReg1);
|
||||
if (!tmp) { tmp = ua.match(versionReg2); }
|
||||
@@ -1081,50 +1094,7 @@ else {
|
||||
_supportWebGL = false;
|
||||
}
|
||||
else if (win.WebGLRenderingContext) {
|
||||
// @ts-ignore
|
||||
if (create3DContext(document.createElement('CANVAS'))) {
|
||||
_supportWebGL = true;
|
||||
}
|
||||
if (_supportWebGL && sys.os === sys.OS_ANDROID) {
|
||||
const browserVer = parseFloat(sys.browserVersion);
|
||||
switch (sys.browserType) {
|
||||
case sys.BROWSER_TYPE_MOBILE_QQ:
|
||||
case sys.BROWSER_TYPE_BAIDU:
|
||||
case sys.BROWSER_TYPE_BAIDU_APP:
|
||||
// QQ & Baidu Brwoser 6.2+ (using blink kernel)
|
||||
if (browserVer >= 6.2) {
|
||||
_supportWebGL = true;
|
||||
}
|
||||
else {
|
||||
_supportWebGL = false;
|
||||
}
|
||||
break;
|
||||
case sys.BROWSER_TYPE_ANDROID:
|
||||
// Android 5+ default browser
|
||||
if (sys.osMainVersion && sys.osMainVersion >= 5) {
|
||||
_supportWebGL = true;
|
||||
}
|
||||
break;
|
||||
case sys.BROWSER_TYPE_CHROME:
|
||||
// Chrome on android supports WebGL from v. 30
|
||||
if (browserVer >= 30.0) {
|
||||
_supportWebGL = true;
|
||||
} else {
|
||||
_supportWebGL = false;
|
||||
}
|
||||
break;
|
||||
case sys.BROWSER_TYPE_UC:
|
||||
if (browserVer > 11.0) {
|
||||
_supportWebGL = true;
|
||||
} else {
|
||||
_supportWebGL = false;
|
||||
}
|
||||
break;
|
||||
case sys.BROWSER_TYPE_360:
|
||||
_supportWebGL = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_supportWebGL = true;
|
||||
}
|
||||
|
||||
const capabilities = sys.capabilities = {
|
||||
|
||||
@@ -123,7 +123,6 @@ export class Shadows {
|
||||
get type (): number {
|
||||
return ShadowsPool.get(this._handle, ShadowsView.TYPE);
|
||||
}
|
||||
|
||||
set type (val: number) {
|
||||
ShadowsPool.set(this._handle, ShadowsView.TYPE, val);
|
||||
this._updatePipeline();
|
||||
@@ -213,8 +212,8 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 场景包围球
|
||||
* @en The bounding sphere of the shadow map
|
||||
* @zh 用于计算阴影 Shadow map 的场景包围球
|
||||
*/
|
||||
public get sphere (): sphere {
|
||||
return this._sphere;
|
||||
@@ -228,6 +227,22 @@ export class Shadows {
|
||||
return this._instancingMaterial!;
|
||||
}
|
||||
|
||||
public get handle () : ShadowsHandle {
|
||||
return this._handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow generation range
|
||||
* @zh 获取或设置阴影生成范围
|
||||
*/
|
||||
public receiveSphere: sphere = new sphere();
|
||||
|
||||
/**
|
||||
* @en get or set shadow auto control
|
||||
* @zh 获取或者设置阴影是否自动控制
|
||||
*/
|
||||
public autoAdapt: boolean = true;
|
||||
|
||||
protected _normal = new Vec3(0, 1, 0);
|
||||
protected _shadowColor = new Color(0, 0, 0, 76);
|
||||
protected _matLight = new Mat4();
|
||||
@@ -237,10 +252,6 @@ export class Shadows {
|
||||
protected _handle: ShadowsHandle = NULL_HANDLE;
|
||||
protected _sphere: sphere = new sphere(0.0, 0.0, 0.0, 0.01);
|
||||
|
||||
get handle () : ShadowsHandle {
|
||||
return this._handle;
|
||||
}
|
||||
|
||||
constructor () {
|
||||
this._handle = ShadowsPool.alloc();
|
||||
}
|
||||
|
||||
@@ -407,6 +407,7 @@ export class UI {
|
||||
mat = renderComp._updateBlendFunc();
|
||||
}
|
||||
|
||||
// use material judgment merge is increasingly impossible, change to hash is more possible
|
||||
if (this._currMaterial !== mat ||
|
||||
this._currTexture !== texture || this._currSampler !== samp
|
||||
) {
|
||||
@@ -525,7 +526,7 @@ export class UI {
|
||||
}
|
||||
|
||||
if (renderComp && StencilManager.sharedManager!.handleMaterial(mat)) {
|
||||
this._currMaterial = mat = renderComp.getUIMaterialInstance();
|
||||
this._currMaterial = mat = renderComp.getMaterialInstanceForStencil();
|
||||
const state = StencilManager.sharedManager!.pattern;
|
||||
mat.overridePipelineStates({
|
||||
depthStencilState: {
|
||||
|
||||
@@ -33,7 +33,7 @@ import { property } from '../data/decorators/property';
|
||||
import { ccclass, editable, serializable } from 'cc.decorator';
|
||||
import { CCObject } from '../data/object';
|
||||
import { Event } from '../event';
|
||||
import { errorID, warnID, error, log, assertID, getError } from '../platform/debug';
|
||||
import { errorID, warnID, error, log, getError } from '../platform/debug';
|
||||
import { SystemEventType } from '../platform/event-manager/event-enum';
|
||||
import { ISchedulable } from '../scheduler';
|
||||
import IdGenerator from '../utils/id-generator';
|
||||
@@ -525,19 +525,13 @@ export class BaseNode extends CCObject implements ISchedulable {
|
||||
}
|
||||
return lastNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Add a child to the current node, it will be pushed to the end of [[children]] array.
|
||||
* @zh 添加一个子节点,它会被添加到 [[children]] 数组的末尾。
|
||||
* @en Add a child to the current node.
|
||||
* @zh 添加一个子节点。
|
||||
* @param child - the child node to be added
|
||||
*/
|
||||
public addChild (child: this | Node): void {
|
||||
if (DEV && !(child instanceof legacyCC._BaseNode)) {
|
||||
return errorID(1634, legacyCC.js.getClassName(child));
|
||||
}
|
||||
assertID(child, 1606);
|
||||
assertID((child as this)._parent === null, 1605);
|
||||
|
||||
// invokes the parent setter
|
||||
(child as this).setParent(this);
|
||||
}
|
||||
|
||||
@@ -1181,11 +1175,7 @@ export class BaseNode extends CCObject implements ISchedulable {
|
||||
|
||||
public destroy () {
|
||||
if (super.destroy()) {
|
||||
// disable hierarchy
|
||||
if (this._activeInHierarchy) {
|
||||
this._disableChildComps();
|
||||
}
|
||||
|
||||
this.active = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1380,25 +1370,6 @@ export class BaseNode extends CCObject implements ISchedulable {
|
||||
return destroyByParent;
|
||||
}
|
||||
|
||||
protected _disableChildComps () {
|
||||
// leave this._activeInHierarchy unmodified
|
||||
const comps = this._components;
|
||||
for (let i = 0; i < comps.length; ++i) {
|
||||
const component = comps[i];
|
||||
if (component._enabled) {
|
||||
legacyCC.director._compScheduler.disableComp(component);
|
||||
}
|
||||
}
|
||||
// deactivate recursively
|
||||
const children = this._children;
|
||||
for (let i = 0; i < children.length; ++i) {
|
||||
const node = children[i];
|
||||
if (node._active) {
|
||||
node._disableChildComps();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected _onSiblingIndexChanged? (siblingIndex: number): void;
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* @module scene-graph
|
||||
*/
|
||||
|
||||
import { CCObject } from '../data/object';
|
||||
import { CCObject, isValid } from '../data/object';
|
||||
import { array, Pool } from '../utils/js';
|
||||
import { tryCatchFunctor_EDITOR } from '../utils/misc';
|
||||
import { invokeOnEnable, createInvokeImpl, createInvokeImplJit, OneOffInvoker, LifeCycleInvoker } from './component-scheduler';
|
||||
@@ -226,6 +226,10 @@ export default class NodeActivator {
|
||||
* @param onEnableInvoker The invoker for `onEnable` method, normally from [[ComponentScheduler]]
|
||||
*/
|
||||
public activateComp (comp, preloadInvoker?, onLoadInvoker?, onEnableInvoker?) {
|
||||
if (!isValid(comp, true)) {
|
||||
// destroyed before activating
|
||||
return;
|
||||
}
|
||||
if (!(comp._objFlags & IsPreloadStarted)) {
|
||||
comp._objFlags |= IsPreloadStarted;
|
||||
if (comp.__preload) {
|
||||
@@ -359,6 +363,10 @@ export default class NodeActivator {
|
||||
|
||||
if (EDITOR) {
|
||||
NodeActivator.prototype.activateComp = (comp, preloadInvoker, onLoadInvoker, onEnableInvoker) => {
|
||||
if (!isValid(comp, true)) {
|
||||
// destroyed before activating
|
||||
return;
|
||||
}
|
||||
if (legacyCC.GAME_VIEW || comp.constructor._executeInEditMode) {
|
||||
if (!(comp._objFlags & IsPreloadStarted)) {
|
||||
comp._objFlags |= IsPreloadStarted;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
* @module scene-graph
|
||||
*/
|
||||
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { ccclass } from 'cc.decorator';
|
||||
import { CCObject } from '../data/object';
|
||||
import { Node } from './node';
|
||||
@@ -101,7 +102,9 @@ export class PrivateNode extends Node {
|
||||
constructor (name: string) {
|
||||
super(name);
|
||||
// this._originPos = cc.v2();
|
||||
this._objFlags |= HideInHierarchy;
|
||||
if (EDITOR) {
|
||||
this._objFlags |= HideInHierarchy;
|
||||
}
|
||||
}
|
||||
|
||||
// _posDirty (sendEvent) {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
import { TextureCube } from '../assets/texture-cube';
|
||||
import { ccclass, visible, type, displayOrder, slide, range, rangeStep, editable, serializable, rangeMin } from 'cc.decorator';
|
||||
import { CCFloat } from '../data/utils/attribute';
|
||||
import { CCFloat, CCBoolean } from '../data/utils/attribute';
|
||||
import { Color, Quat, Vec3, Vec2 } from '../math';
|
||||
import { Ambient } from '../renderer/scene/ambient';
|
||||
import { Shadows, ShadowType, PCFType } from '../renderer/scene/shadows';
|
||||
@@ -393,6 +393,8 @@ export class ShadowsInfo {
|
||||
@serializable
|
||||
protected _shadowColor = new Color(0, 0, 0, 76);
|
||||
@serializable
|
||||
protected _autoAdapt = true;
|
||||
@serializable
|
||||
protected _pcf = PCFType.HARD;
|
||||
@serializable
|
||||
protected _bias = 0.0035;
|
||||
@@ -485,18 +487,18 @@ export class ShadowsInfo {
|
||||
get pcf () {
|
||||
return this._pcf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow bias
|
||||
* @zh 获取或者设置阴影偏移量
|
||||
* @en get or set shadow Map sampler auto adapt
|
||||
* @zh 阴影纹理生成是否自适应
|
||||
*/
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap; })
|
||||
set bias (val: number) {
|
||||
this._bias = val;
|
||||
if (this._resource) {this._resource.bias = val; }
|
||||
@type (CCBoolean)
|
||||
@visible(function (this: ShadowsInfo) {return this._type === ShadowType.ShadowMap; })
|
||||
set autoAdapt (val) {
|
||||
this._autoAdapt = val;
|
||||
if (this._resource) { this._resource.autoAdapt = val; }
|
||||
}
|
||||
get bias () {
|
||||
return this._bias;
|
||||
get autoAdapt (){
|
||||
return this._autoAdapt;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -504,7 +506,7 @@ export class ShadowsInfo {
|
||||
* @zh 获取或者设置阴影相机近裁剪面
|
||||
*/
|
||||
@type(CCFloat)
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap; })
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap && this._autoAdapt === false; })
|
||||
set near (val: number) {
|
||||
this._near = val;
|
||||
if (this._resource) { this._resource.near = val; }
|
||||
@@ -518,7 +520,7 @@ export class ShadowsInfo {
|
||||
* @zh 获取或者设置阴影相机远裁剪面
|
||||
*/
|
||||
@type(CCFloat)
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap; })
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap && this._autoAdapt === false; })
|
||||
set far (val: number) {
|
||||
this._far = val;
|
||||
if (this._resource) { this._resource.far = val; }
|
||||
@@ -532,7 +534,7 @@ export class ShadowsInfo {
|
||||
* @zh 获取或者设置阴影相机正交大小
|
||||
*/
|
||||
@type(CCFloat)
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap; })
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap && this._autoAdapt === false; })
|
||||
set orthoSize (val: number) {
|
||||
this._orthoSize = val;
|
||||
if (this._resource) { this._resource.orthoSize = val; }
|
||||
@@ -545,7 +547,7 @@ export class ShadowsInfo {
|
||||
* @en get or set shadow camera orthoSize
|
||||
* @zh 获取或者设置阴影纹理大小
|
||||
*/
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap; })
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap && this._autoAdapt === false; })
|
||||
set shadowMapSize (val: Vec2) {
|
||||
this._size.set(val);
|
||||
if (this._resource) { this._resource.size = val; }
|
||||
@@ -559,7 +561,7 @@ export class ShadowsInfo {
|
||||
* @zh 获取或者设置阴影纹理大小
|
||||
*/
|
||||
@type(CCFloat)
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap; })
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap && this._autoAdapt === false; })
|
||||
set aspect (val: number) {
|
||||
this._aspect = val;
|
||||
if (this._resource) { this._resource.aspect = val; }
|
||||
@@ -568,6 +570,20 @@ export class ShadowsInfo {
|
||||
return this._aspect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow map sampler offset
|
||||
* @zh 获取或者设置阴影纹理偏移值
|
||||
*/
|
||||
@type(CCFloat)
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap && this._autoAdapt === false; })
|
||||
set bias (val: number) {
|
||||
this._bias = val;
|
||||
if (this._resource) { this._resource.bias = val; }
|
||||
}
|
||||
get bias () {
|
||||
return this._bias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Set plane which receives shadow with the given node's world transformation
|
||||
* @zh 根据指定节点的世界变换设置阴影接收平面的信息
|
||||
@@ -583,6 +599,7 @@ export class ShadowsInfo {
|
||||
public activate (resource: Shadows) {
|
||||
this._resource = resource;
|
||||
this._resource.type = this._type;
|
||||
this._resource.autoAdapt = this._autoAdapt;
|
||||
this._resource.near = this._near;
|
||||
this._resource.far = this._far;
|
||||
this._resource.aspect = this._aspect;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
*/
|
||||
|
||||
import { ccclass, serializable, editable } from 'cc.decorator';
|
||||
import { CCObject } from '../data/object';
|
||||
import { Mat4, Quat, Vec3 } from '../math';
|
||||
import { assert, getError } from '../platform/debug';
|
||||
import { RenderScene } from '../renderer/scene/render-scene';
|
||||
@@ -103,8 +104,15 @@ export class Scene extends BaseNode {
|
||||
* @zh 销毁当前场景中的所有节点,这个操作不会销毁资源
|
||||
*/
|
||||
public destroy () {
|
||||
const success = super.destroy();
|
||||
const success = CCObject.prototype.destroy.call(this);
|
||||
if (success) {
|
||||
let children = this._children;
|
||||
for (let i = 0; i < children.length; ++i) {
|
||||
children[i].active = false;
|
||||
}
|
||||
}
|
||||
legacyCC.director.root.destroyScene(this._renderScene);
|
||||
this._active = false;
|
||||
this._activeInHierarchy = false;
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ export class HtmlTextParser {
|
||||
|
||||
tagValue = (nextSpace > -1) ? remainingArgument.substr(0, nextSpace) : remainingArgument;
|
||||
tagName = tagName.replace(/[^a-zA-Z]/g, '').trim();
|
||||
tagName = tagName.toLocaleLowerCase();
|
||||
tagName = tagName.toLowerCase();
|
||||
|
||||
attribute = remainingArgument.substring(nextSpace).trim();
|
||||
if ( tagValue.endsWith( '\/' ) ) tagValue = tagValue.slice( 0, -1 );
|
||||
@@ -212,7 +212,7 @@ export class HtmlTextParser {
|
||||
tagValue = tagValue.slice(1, -1);
|
||||
break;
|
||||
}
|
||||
obj.imageAlign = tagValue.toLocaleLowerCase();
|
||||
obj.imageAlign = tagValue.toLowerCase();
|
||||
}
|
||||
else if (tagName === "offset") {
|
||||
obj.imageOffset = tagValue;
|
||||
@@ -257,7 +257,7 @@ export class HtmlTextParser {
|
||||
tagValue = remainingArgument;
|
||||
}
|
||||
tagName = tagName.replace(/[^a-zA-Z]/g, '').trim();
|
||||
tagName = tagName.toLocaleLowerCase();
|
||||
tagName = tagName.toLowerCase();
|
||||
|
||||
attribute = remainingArgument.substring(nextSpace).trim();
|
||||
if (tagName === 'click') {
|
||||
|
||||
@@ -135,7 +135,7 @@ export const set = (() => {
|
||||
* This causes V8 to put the object in "dictionary mode" and disables creation of hidden classes
|
||||
* which are very expensive for objects that are constantly changing shape.
|
||||
*/
|
||||
export function createMap (forceDictMode?: boolean) {
|
||||
export function createMap (forceDictMode?: boolean): any {
|
||||
const map = Object.create(null);
|
||||
if (forceDictMode) {
|
||||
const INVALID_IDENTIFIER_1 = '.';
|
||||
@@ -434,9 +434,38 @@ function isTempClassId (id) {
|
||||
return typeof id !== 'string' || id.startsWith(tempCIDGenerator.prefix);
|
||||
}
|
||||
|
||||
// id 注册
|
||||
export const _idToClass = {};
|
||||
export const _nameToClass = {};
|
||||
// id registration
|
||||
export const _idToClass: Record<string, Constructor> = createMap(true);
|
||||
export const _nameToClass: Record<string, Constructor> = createMap(true);
|
||||
|
||||
function setup (tag: string, table: object) {
|
||||
return function (id: string, constructor: Constructor) {
|
||||
// deregister old
|
||||
if (constructor.prototype.hasOwnProperty(tag)) {
|
||||
delete table[constructor.prototype[tag]];
|
||||
}
|
||||
value(constructor.prototype, tag, id);
|
||||
// register class
|
||||
if (id) {
|
||||
const registered = table[id];
|
||||
if (registered && registered !== constructor) {
|
||||
let err = 'A Class already exists with the same ' + tag + ' : "' + id + '".';
|
||||
if (TEST) {
|
||||
err += ' (This may be caused by error of unit test.) \
|
||||
If you dont need serialization, you can set class id to "". You can also call \
|
||||
js.unregisterClass to remove the id of unused class';
|
||||
}
|
||||
error(err);
|
||||
}
|
||||
else {
|
||||
table[id] = constructor;
|
||||
}
|
||||
// if (id === "") {
|
||||
// console.trace("", table === _nameToClass);
|
||||
// }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the class by specified id, if its classname is not defined, the class name will also be set.
|
||||
@@ -445,61 +474,9 @@ export const _nameToClass = {};
|
||||
* @param constructor
|
||||
* @private
|
||||
*/
|
||||
export function _setClassId (id, constructor) {
|
||||
const table = _idToClass;
|
||||
// deregister old
|
||||
if (constructor.prototype.hasOwnProperty(classIdTag)) {
|
||||
delete table[constructor.prototype[classIdTag]];
|
||||
}
|
||||
value(constructor.prototype, classIdTag, id);
|
||||
// register class
|
||||
if (id) {
|
||||
const registered = table[id];
|
||||
if (registered && registered !== constructor) {
|
||||
let err = 'A Class already exists with the same ' + classIdTag + ' : "' + id + '".';
|
||||
if (TEST) {
|
||||
err += ' (This may be caused by error of unit test.) \
|
||||
If you dont need serialization, you can set class id to "". You can also call \
|
||||
js.unregisterClass to remove the id of unused class';
|
||||
}
|
||||
error(err);
|
||||
}
|
||||
else {
|
||||
table[id] = constructor;
|
||||
}
|
||||
// if (id === "") {
|
||||
// console.trace("", table === _nameToClass);
|
||||
// }
|
||||
}
|
||||
}
|
||||
export const _setClassId = setup('__cid__', _idToClass);
|
||||
|
||||
function doSetClassName (id, constructor) {
|
||||
const table = _nameToClass;
|
||||
// deregister old
|
||||
if (constructor.prototype.hasOwnProperty(classNameTag)) {
|
||||
delete table[constructor.prototype[classNameTag]];
|
||||
}
|
||||
value(constructor.prototype, classNameTag, id);
|
||||
// register class
|
||||
if (id) {
|
||||
const registered = table[id];
|
||||
if (registered && registered !== constructor) {
|
||||
let err = 'A Class already exists with the same ' + classNameTag + ' : "' + id + '".';
|
||||
if (TEST) {
|
||||
err += ' (This may be caused by error of unit test.) \
|
||||
If you dont need serialization, you can set class id to "". You can also call \
|
||||
js.unregisterClass to remove the id of unused class';
|
||||
}
|
||||
error(err);
|
||||
}
|
||||
else {
|
||||
table[id] = constructor;
|
||||
}
|
||||
// if (id === "") {
|
||||
// console.trace("", table === _nameToClass);
|
||||
// }
|
||||
}
|
||||
}
|
||||
const doSetClassName = setup('__classname__', _nameToClass);
|
||||
|
||||
/**
|
||||
* Register the class by specified name manually
|
||||
@@ -507,7 +484,7 @@ js.unregisterClass to remove the id of unused class';
|
||||
* @param className
|
||||
* @param constructor
|
||||
*/
|
||||
export function setClassName (className, constructor) {
|
||||
export function setClassName (className: string, constructor: Constructor) {
|
||||
doSetClassName(className, constructor);
|
||||
// auto set class id
|
||||
if (!constructor.prototype.hasOwnProperty(classIdTag)) {
|
||||
@@ -531,7 +508,7 @@ export function setClassName (className, constructor) {
|
||||
* @param target Constructor of target class.
|
||||
* @param alias Alias to set. The name shall not have been set as class name or alias of another class.
|
||||
*/
|
||||
export function setClassAlias (target: Function, alias: string) {
|
||||
export function setClassAlias (target: Constructor, alias: string) {
|
||||
const nameRegistry = _nameToClass[alias];
|
||||
const idRegistry = _idToClass[alias];
|
||||
let ok = true;
|
||||
|
||||
+50
-49
@@ -28,6 +28,8 @@
|
||||
import * as jsarray from './array';
|
||||
import IDGenerator from './id-generator';
|
||||
import {
|
||||
_idToClass,
|
||||
_nameToClass,
|
||||
_getClassById,
|
||||
_getClassId,
|
||||
_setClassId,
|
||||
@@ -57,11 +59,6 @@ import {
|
||||
} from './js-typed';
|
||||
import Pool from './pool';
|
||||
|
||||
import {
|
||||
_idToClass,
|
||||
_nameToClass,
|
||||
} from './js-typed';
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { legacyCC } from '../global-exports';
|
||||
|
||||
export * from './js-typed';
|
||||
@@ -91,6 +88,54 @@ export const js = {
|
||||
setClassName,
|
||||
setClassAlias,
|
||||
getClassByName,
|
||||
/**
|
||||
* @en All classes registered in the engine, indexed by name.
|
||||
* @zh 引擎中已注册的所有类型,通过名称进行索引。
|
||||
* @private
|
||||
* @example
|
||||
* ```
|
||||
* import { js } from 'cc';
|
||||
* // save all registered classes before loading scripts
|
||||
* let builtinClassIds = js._registeredClassIds;
|
||||
* let builtinClassNames = js._registeredClassNames;
|
||||
* // load some scripts that contain CCClass
|
||||
* ...
|
||||
* // clear all loaded classes
|
||||
* js._registeredClassIds = builtinClassIds;
|
||||
* js._registeredClassNames = builtinClassNames;
|
||||
* ```
|
||||
*/
|
||||
get _registeredClassNames (): typeof _nameToClass {
|
||||
return Object.assign({}, _nameToClass);
|
||||
},
|
||||
set _registeredClassNames (value: typeof _nameToClass) {
|
||||
clear(_nameToClass);
|
||||
Object.assign(_nameToClass, value);
|
||||
},
|
||||
/**
|
||||
* @en All classes registered in the engine, indexed by ID.
|
||||
* @zh 引擎中已注册的所有类型,通过 ID 进行索引。
|
||||
* @private
|
||||
* @example
|
||||
* ```
|
||||
* import { js } from 'cc';
|
||||
* // save all registered classes before loading scripts
|
||||
* let builtinClassIds = js._registeredClassIds;
|
||||
* let builtinClassNames = js._registeredClassNames;
|
||||
* // load some scripts that contain CCClass
|
||||
* ...
|
||||
* // clear all loaded classes
|
||||
* js._registeredClassIds = builtinClassIds;
|
||||
* js._registeredClassNames = builtinClassNames;
|
||||
* ```
|
||||
*/
|
||||
get _registeredClassIds (): typeof _idToClass {
|
||||
return Object.assign({}, _idToClass);
|
||||
},
|
||||
set _registeredClassIds (value: typeof _idToClass) {
|
||||
clear(_idToClass);
|
||||
Object.assign(_idToClass, value);
|
||||
},
|
||||
_getClassId,
|
||||
_setClassId,
|
||||
_getClassById,
|
||||
@@ -106,47 +151,3 @@ export const js = {
|
||||
* @zh 这个模块封装了 JavaScript 相关的一些实用函数,你可以通过 `import { js } from 'cc'` 来访问这个模块。
|
||||
*/
|
||||
legacyCC.js = js;
|
||||
|
||||
if (EDITOR) {
|
||||
legacyCC.js.getset(legacyCC.js, '_registeredClassIds', () => {
|
||||
const dump = {};
|
||||
for (const id in _idToClass) {
|
||||
if (!(id in _idToClass)) {
|
||||
continue;
|
||||
}
|
||||
dump[id] = _idToClass[id];
|
||||
}
|
||||
return dump;
|
||||
},
|
||||
(item) => {
|
||||
clear(_idToClass);
|
||||
for (const id in item) {
|
||||
if (!(id in item)) {
|
||||
continue;
|
||||
}
|
||||
_idToClass[id] = item[id];
|
||||
}
|
||||
},
|
||||
);
|
||||
legacyCC.js.getset(legacyCC.js, '_registeredClassNames',
|
||||
() => {
|
||||
const dump = {};
|
||||
for (const id in _nameToClass) {
|
||||
if (!(id in _nameToClass)) {
|
||||
continue;
|
||||
}
|
||||
dump[id] = _nameToClass[id];
|
||||
}
|
||||
return dump;
|
||||
},
|
||||
(item) => {
|
||||
clear(_nameToClass);
|
||||
for (const id in item) {
|
||||
if (!(id in item)) {
|
||||
continue;
|
||||
}
|
||||
_nameToClass[id] = item[id];
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -293,13 +293,20 @@ export class AmmoSharedBody {
|
||||
cocos2AmmoVec3(wt.getOrigin(), this.node.worldPosition)
|
||||
cocos2AmmoQuat(this.bodyStruct.worldQuat, this.node.worldRotation);
|
||||
wt.setRotation(this.bodyStruct.worldQuat);
|
||||
if (this.isBodySleeping()) this.body.activate();
|
||||
|
||||
if (this.node.hasChangedFlags & TransformBit.SCALE) {
|
||||
for (let i = 0; i < this.bodyStruct.wrappedShapes.length; i++) {
|
||||
this.bodyStruct.wrappedShapes[i].setScale();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.body.isKinematicObject()) {
|
||||
// Kinematic objects must be updated using motion state
|
||||
var ms = this.body.getMotionState();
|
||||
if (ms) ms.setWorldTransform(wt);
|
||||
} else {
|
||||
if (this.isBodySleeping()) this.body.activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ export function cocos2AmmoTriMesh (out: Ammo.btTriangleMesh, mesh: Mesh): Ammo.b
|
||||
const i0 = ib[j - rev] * 3;
|
||||
const i1 = ib[j + rev + 1] * 3;
|
||||
const i2 = ib[j + 2] * 3;
|
||||
rev = ~rev;
|
||||
const v0 = new Ammo.btVector3(vb[i0], vb[i0 + 1], vb[i0 + 2]);
|
||||
const v1 = new Ammo.btVector3(vb[i1], vb[i1 + 1], vb[i1 + 2]);
|
||||
const v2 = new Ammo.btVector3(vb[i2], vb[i2 + 1], vb[i2 + 2]);
|
||||
|
||||
@@ -108,10 +108,10 @@ export class Collider extends Eventify(Component) {
|
||||
* @en
|
||||
* Gets or sets the collider is trigger, this will be always trigger if using builtin.
|
||||
* @zh
|
||||
* 获取或设置碰撞器是否为触发器,若使用 builtin ,属性值无论真假 ,此碰撞器都为触发器。
|
||||
* 获取或设置碰撞器是否为触发器。(builtin中无论真假都为触发器)
|
||||
*/
|
||||
@displayOrder(0)
|
||||
@tooltip('是否与其它碰撞器产生碰撞,并产生物理行为')
|
||||
@tooltip('是否为触发器,触发器不会产生物理反馈')
|
||||
public get isTrigger () {
|
||||
return this._isTrigger;
|
||||
}
|
||||
|
||||
+58
-50
@@ -25,6 +25,10 @@ import { TerrainAsset, TerrainLayerInfo, TERRAIN_HEIGHT_BASE, TERRAIN_HEIGHT_FAC
|
||||
TERRAIN_BLOCK_TILE_COMPLEXITY, TERRAIN_BLOCK_VERTEX_SIZE, TERRAIN_BLOCK_VERTEX_COMPLEXITY,
|
||||
TERRAIN_MAX_LAYER_COUNT, TERRAIN_HEIGHT_FMIN, TERRAIN_HEIGHT_FMAX, } from './terrain-asset';
|
||||
|
||||
|
||||
const bbMin = new Vec3();
|
||||
const bbMax = new Vec3();
|
||||
|
||||
/**
|
||||
* @en Terrain info
|
||||
* @zh 地形信息
|
||||
@@ -185,6 +189,7 @@ class TerrainRenderable extends RenderableComponent {
|
||||
this.setMaterial(this._currentMaterial, 0);
|
||||
this._currentMaterialLayers = nLayers;
|
||||
this._model.enabled = true;
|
||||
this._model.receiveShadow = block.getTerrain().receiveShadow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,6 +289,8 @@ export class TerrainBlock {
|
||||
// vertex buffer
|
||||
const vertexData = new Float32Array(TERRAIN_BLOCK_VERTEX_SIZE * TERRAIN_BLOCK_VERTEX_COMPLEXITY * TERRAIN_BLOCK_VERTEX_COMPLEXITY);
|
||||
let index = 0;
|
||||
bbMin.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
||||
bbMax.set(Number.MIN_VALUE, Number.MIN_VALUE, Number.MIN_VALUE);
|
||||
for (let j = 0; j < TERRAIN_BLOCK_VERTEX_COMPLEXITY; ++j) {
|
||||
for (let i = 0; i < TERRAIN_BLOCK_VERTEX_COMPLEXITY; ++i) {
|
||||
const x = this._index[0] * TERRAIN_BLOCK_TILE_COMPLEXITY + i;
|
||||
@@ -299,6 +306,9 @@ export class TerrainBlock {
|
||||
vertexData[index++] = normal.z;
|
||||
vertexData[index++] = uv.x;
|
||||
vertexData[index++] = uv.y;
|
||||
|
||||
Vec3.min(bbMin, bbMin, position);
|
||||
Vec3.max(bbMax, bbMax, position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,6 +332,7 @@ export class TerrainBlock {
|
||||
|
||||
const model = this._renderable._model = (legacyCC.director.root as Root).createModel(scene.Model);
|
||||
model.node = model.transform = this._node;
|
||||
model.createBoundingShape(bbMin, bbMax);
|
||||
this._renderable._getRenderScene().addModel(model);
|
||||
|
||||
// reset weightmap
|
||||
@@ -549,36 +560,11 @@ export class TerrainBlock {
|
||||
}
|
||||
|
||||
public _getMaterialDefines (nlayers: number): MacroRecord {
|
||||
if (this.lightmap != null) {
|
||||
if (nlayers === 0) {
|
||||
return { LAYERS: 1, LIGHT_MAP: 1 };
|
||||
}
|
||||
else if (nlayers === 1) {
|
||||
return { LAYERS: 2, LIGHT_MAP: 1 };
|
||||
}
|
||||
else if (nlayers === 2) {
|
||||
return { LAYERS: 3, LIGHT_MAP: 1 };
|
||||
}
|
||||
else if (nlayers === 3) {
|
||||
return { LAYERS: 4, LIGHT_MAP: 1 };
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (nlayers === 0) {
|
||||
return { LAYERS: 1 };
|
||||
}
|
||||
else if (nlayers === 1) {
|
||||
return { LAYERS: 2 };
|
||||
}
|
||||
else if (nlayers === 2) {
|
||||
return { LAYERS: 3 };
|
||||
}
|
||||
else if (nlayers === 3) {
|
||||
return { LAYERS: 4 };
|
||||
}
|
||||
}
|
||||
|
||||
return { LAYERS: 0 };
|
||||
return {
|
||||
LAYERS: nlayers + 1,
|
||||
USE_LIGHTMAP: this.lightmap !== null ? 1 : 0,
|
||||
// CC_RECEIVE_SHADOW: this._terrain.receiveShadow ? 1 : 0,
|
||||
};
|
||||
}
|
||||
|
||||
public _invalidMaterial () {
|
||||
@@ -597,6 +583,8 @@ export class TerrainBlock {
|
||||
const vertexData = new Float32Array(TERRAIN_BLOCK_VERTEX_SIZE * TERRAIN_BLOCK_VERTEX_COMPLEXITY * TERRAIN_BLOCK_VERTEX_COMPLEXITY);
|
||||
|
||||
let index = 0;
|
||||
bbMin.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
||||
bbMax.set(Number.MIN_VALUE, Number.MIN_VALUE, Number.MIN_VALUE);
|
||||
for (let j = 0; j < TERRAIN_BLOCK_VERTEX_COMPLEXITY; ++j) {
|
||||
for (let i = 0; i < TERRAIN_BLOCK_VERTEX_COMPLEXITY; ++i) {
|
||||
const x = this._index[0] * TERRAIN_BLOCK_TILE_COMPLEXITY + i;
|
||||
@@ -614,10 +602,14 @@ export class TerrainBlock {
|
||||
vertexData[index++] = normal.z;
|
||||
vertexData[index++] = uv.x;
|
||||
vertexData[index++] = uv.y;
|
||||
|
||||
Vec3.min(bbMin, bbMin, position);
|
||||
Vec3.max(bbMax, bbMax, position);
|
||||
}
|
||||
}
|
||||
|
||||
this._renderable._meshData.vertexBuffers[0].update(vertexData);
|
||||
this._renderable._model!.createBoundingShape(bbMin, bbMax);
|
||||
}
|
||||
|
||||
public _updateWeightMap () {
|
||||
@@ -698,6 +690,10 @@ export class Terrain extends Component {
|
||||
@disallowAnimation
|
||||
protected _lightmapInfos: TerrainBlockLightmapInfo[] = [];
|
||||
|
||||
@serializable
|
||||
@disallowAnimation
|
||||
protected _receiveShadow: boolean = false;
|
||||
|
||||
protected _tileSize: number = 1;
|
||||
protected _blockCount: number[] = [1, 1];
|
||||
protected _weightMapSize: number = 128;
|
||||
@@ -759,6 +755,22 @@ export class Terrain extends Component {
|
||||
return this._effectAsset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Receive shadow
|
||||
* @zh 是否接受阴影
|
||||
*/
|
||||
@editable
|
||||
get receiveShadow () {
|
||||
return this._receiveShadow;
|
||||
}
|
||||
|
||||
set receiveShadow (val) {
|
||||
this._receiveShadow = val;
|
||||
for (let i = 0; i < this._blocks.length; i++) {
|
||||
this._blocks[i]._invalidMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get terrain size
|
||||
* @zh 获得地形大小
|
||||
@@ -1545,32 +1557,28 @@ export class Terrain extends Component {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!restore && this.__asset != null) {
|
||||
this._tileSize = this.__asset.tileSize;
|
||||
this._blockCount = this.__asset.blockCount;
|
||||
this._weightMapSize = this.__asset.weightMapSize;
|
||||
this._lightMapSize = this.__asset.lightMapSize;
|
||||
this._heights = this.__asset.heights;
|
||||
this._weights = this.__asset.weights;
|
||||
const terrainAsset = this.__asset;
|
||||
if (!restore && terrainAsset !== null) {
|
||||
this._tileSize = terrainAsset.tileSize;
|
||||
this._blockCount = terrainAsset.blockCount;
|
||||
this._weightMapSize = terrainAsset.weightMapSize;
|
||||
this._lightMapSize = terrainAsset.lightMapSize;
|
||||
this._heights = terrainAsset.heights;
|
||||
this._weights = terrainAsset.weights;
|
||||
|
||||
// build layers
|
||||
let initial = true;
|
||||
for (let i = 0; i < this._layers.length; ++i) {
|
||||
if (this._layers[i] != null) {
|
||||
initial = false;
|
||||
}
|
||||
this._layers[i] = null;
|
||||
}
|
||||
|
||||
if (initial && this._asset != null) {
|
||||
for (const i of this._asset.layerInfos) {
|
||||
const layer = new TerrainLayer();
|
||||
layer.tileSize = i.tileSize;
|
||||
legacyCC.loader.loadRes(i.detailMap, Texture2D, (err, asset) => {
|
||||
layer.detailMap = asset;
|
||||
});
|
||||
for (const i of terrainAsset.layerInfos) {
|
||||
const layer = new TerrainLayer();
|
||||
layer.tileSize = i.tileSize;
|
||||
legacyCC.AssetLibrary.loadAsset(i.detailMap, (err, asset) => {
|
||||
layer.detailMap = asset;
|
||||
});
|
||||
|
||||
this._layers[i.slot] = layer;
|
||||
}
|
||||
this._layers[i.slot] = layer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class FontLetterDefinition {
|
||||
public xAdvance = 0;
|
||||
}
|
||||
|
||||
const _backgroundStyle = 'rgba(255, 255, 255, 0.005)';
|
||||
const _backgroundStyle = `rgba(255, 255, 255, ${(1 / 255).toFixed(3)})`;
|
||||
|
||||
class LetterTexture {
|
||||
public image: ImageAsset | null = null;
|
||||
|
||||
@@ -332,7 +332,6 @@ export const ttfUtils = {
|
||||
},
|
||||
|
||||
_calculateTextBaseline () {
|
||||
// let node = this._node;
|
||||
let hAlign;
|
||||
let vAlign;
|
||||
|
||||
|
||||
@@ -472,6 +472,7 @@ export class Mask extends UIRenderable {
|
||||
protected _removeGraphics () {
|
||||
if (this._graphics) {
|
||||
this._graphics.destroy();
|
||||
this._graphics._destroyImmediate(); // FIX: cocos-creator/2d-tasks#2511. TODO: cocos-creator/2d-tasks#2516
|
||||
}
|
||||
|
||||
if (this._clearGraphics) {
|
||||
|
||||
@@ -81,15 +81,15 @@ float CCGetShadowFactorX25 () {
|
||||
return shadow /= 25.0;
|
||||
}
|
||||
|
||||
#define CC_SHADOW_FACTOR(finalColor, atten) \
|
||||
{ \
|
||||
float pcf = cc_shadowInfo.z + 0.001; \
|
||||
float shadowAttenuation = 0.0; \
|
||||
if (pcf > 3.0) shadowAttenuation = CCGetShadowFactorX25(); \
|
||||
else if (3.0 > pcf && pcf > 2.0) shadowAttenuation = CCGetShadowFactorX9(); \
|
||||
else if (2.0 > pcf && pcf > 1.0) shadowAttenuation = CCGetShadowFactorX5(); \
|
||||
else shadowAttenuation = CCGetShadowFactorX1(); \
|
||||
vec3 shadowColor = cc_shadowColor.rgb * cc_shadowColor.a + finalColor * (1.0 - cc_shadowColor.a); \
|
||||
finalColor = shadowColor.rgb * shadowAttenuation * atten + finalColor.rgb * (1.0 - shadowAttenuation * atten); \
|
||||
} \
|
||||
#define CC_SHADOW_FACTOR(finalColor, atten) \
|
||||
{ \
|
||||
float pcf = cc_shadowInfo.z + 0.001; \
|
||||
float shadowAttenuation = 0.0; \
|
||||
if (pcf > 3.0) shadowAttenuation = CCGetShadowFactorX25(); \
|
||||
else if (3.0 > pcf && pcf > 2.0) shadowAttenuation = CCGetShadowFactorX9(); \
|
||||
else if (2.0 > pcf && pcf > 1.0) shadowAttenuation = CCGetShadowFactorX5(); \
|
||||
else shadowAttenuation = CCGetShadowFactorX1(); \
|
||||
vec3 shadowColor = cc_shadowColor.rgb * cc_shadowColor.a + finalColor.rgb * (1.0 - cc_shadowColor.a); \
|
||||
finalColor.rgb = shadowColor.rgb * shadowAttenuation * atten + finalColor.rgb * (1.0 - shadowAttenuation * atten); \
|
||||
} \
|
||||
#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
#include <texture-lod>
|
||||
#endif
|
||||
|
||||
#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD
|
||||
#include <lightingmap-fs>
|
||||
#endif
|
||||
|
||||
#include <common>
|
||||
#include <gamma>
|
||||
|
||||
@@ -48,6 +44,8 @@ struct StandardSurface {
|
||||
vec3 normal;
|
||||
// emissive
|
||||
vec3 emissive;
|
||||
// light map
|
||||
vec4 lightmap;
|
||||
// PBR params
|
||||
float roughness;
|
||||
float metallic;
|
||||
@@ -122,8 +120,7 @@ struct StandardSurface {
|
||||
vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;
|
||||
|
||||
#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD
|
||||
vec4 lightmap = texture(cc_lightingMap, v_luv);
|
||||
finalColor = lightmap.a * lightmap.rgb + (1.0 - lightmap.a) * finalColor;
|
||||
finalColor = s.lightmap.a * s.lightmap.rgb + (1.0 - s.lightmap.a) * finalColor;
|
||||
#endif
|
||||
|
||||
vec3 diffuseContrib = diffuse / PI;
|
||||
|
||||
@@ -154,6 +154,9 @@ CCProgram standard-fs %{
|
||||
#include <gamma>
|
||||
#include <shared-ubos>
|
||||
#include <cc-fog>
|
||||
#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD
|
||||
#include <lightingmap-fs>
|
||||
#endif
|
||||
|
||||
in vec3 v_position;
|
||||
in vec2 v_uv;
|
||||
@@ -215,6 +218,10 @@ CCProgram standard-fs %{
|
||||
if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;
|
||||
#endif
|
||||
|
||||
#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD
|
||||
s.lightmap = texture(cc_lightingMap, v_luv);
|
||||
#endif
|
||||
|
||||
s.normal = v_normal;
|
||||
#if USE_NORMAL_MAP
|
||||
vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);
|
||||
|
||||
@@ -5,7 +5,7 @@ CCEffect %{
|
||||
passes:
|
||||
- vert: terrain-vs:vert
|
||||
frag: terrain-fs:frag
|
||||
properties:
|
||||
properties: &props
|
||||
UVScale: { value: [1, 1, 1, 1] }
|
||||
lightMapUVParam: { value: [0, 0, 0, 0] }
|
||||
weightMap: { value: black }
|
||||
@@ -14,6 +14,29 @@ CCEffect %{
|
||||
detailMap2: { value: grey }
|
||||
detailMap3: { value: grey }
|
||||
lightMap: { value: grey }
|
||||
- vert: terrain-vs:vert
|
||||
frag: terrain-fs:frag
|
||||
phase: forward-add
|
||||
propertyIndex: 0
|
||||
embeddedMacros: { CC_FORWARD_ADD: true }
|
||||
depthStencilState:
|
||||
depthFunc: equal
|
||||
depthTest: true
|
||||
depthWrite: false
|
||||
blendState:
|
||||
targets:
|
||||
- blend: true
|
||||
blendSrc: one
|
||||
blendDst: one
|
||||
blendSrcAlpha: zero
|
||||
blendDstAlpha: one
|
||||
properties: *props
|
||||
- vert: shadow-caster-vs:vert
|
||||
frag: shadow-caster-fs:frag
|
||||
phase: shadow-add
|
||||
propertyIndex: 0
|
||||
rasterizerState:
|
||||
cullMode: back
|
||||
}%
|
||||
|
||||
CCProgram terrain-vs %{
|
||||
@@ -21,11 +44,14 @@ CCProgram terrain-vs %{
|
||||
#include <cc-global>
|
||||
#include <cc-local>
|
||||
#include <cc-fog>
|
||||
#include <cc-shadow-map-vs>
|
||||
|
||||
in vec3 a_position;
|
||||
in vec3 a_normal;
|
||||
in vec2 a_texCoord;
|
||||
|
||||
out vec3 v_position;
|
||||
out vec3 v_normal;
|
||||
out vec2 uvw;
|
||||
out vec2 uv0;
|
||||
out vec2 uv1;
|
||||
@@ -33,7 +59,8 @@ CCProgram terrain-vs %{
|
||||
out vec2 uv3;
|
||||
out vec2 luv;
|
||||
out vec3 diffuse;
|
||||
out float factor_fog;
|
||||
out float v_fog_factor;
|
||||
|
||||
uniform TexCoords {
|
||||
vec4 UVScale;
|
||||
vec4 lightMapUVParam;
|
||||
@@ -45,7 +72,7 @@ CCProgram terrain-vs %{
|
||||
worldPos.y = cc_matWorld[3][1] + a_position.y;
|
||||
worldPos.z = cc_matWorld[3][2] + a_position.z;
|
||||
|
||||
vec4 pos = vec4(worldPos, 1);
|
||||
vec4 pos = vec4(worldPos, 1.0);
|
||||
pos = cc_matViewProj * pos;
|
||||
|
||||
uvw = a_texCoord;
|
||||
@@ -53,79 +80,132 @@ CCProgram terrain-vs %{
|
||||
uv1 = a_position.xz * UVScale.y;
|
||||
uv2 = a_position.xz * UVScale.z;
|
||||
uv3 = a_position.xz * UVScale.w;
|
||||
|
||||
float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;
|
||||
vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;
|
||||
|
||||
#if LIGHT_MAP == 0
|
||||
vec3 L = normalize(-cc_mainLitDir.xyz);
|
||||
vec3 N = a_normal;
|
||||
|
||||
diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;
|
||||
#else
|
||||
diffuse = ambDiff;
|
||||
#if USE_LIGHTMAP
|
||||
luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;
|
||||
#endif
|
||||
factor_fog = CC_TRANSFER_FOG(vec4(worldPos, 1));
|
||||
|
||||
v_position = worldPos;
|
||||
v_normal = a_normal;
|
||||
v_fog_factor = CC_TRANSFER_FOG(vec4(worldPos, 1.0));
|
||||
|
||||
CCPassShadowParams(vec4(worldPos, 1.0));
|
||||
|
||||
return pos;
|
||||
}
|
||||
}%
|
||||
|
||||
CCProgram terrain-fs %{
|
||||
precision mediump float;
|
||||
#include <output>
|
||||
precision highp float;
|
||||
#include <cc-global>
|
||||
#include <shading-standard>
|
||||
#include <output-standard>
|
||||
#include <gamma>
|
||||
#include <cc-fog>
|
||||
#pragma define LAYERS range([0, 4])
|
||||
|
||||
in vec2 uvw;
|
||||
in vec2 uv0;
|
||||
in vec2 uv1;
|
||||
in vec2 uv2;
|
||||
in vec2 uv3;
|
||||
in vec3 diffuse;
|
||||
in vec2 luv;
|
||||
in vec3 v_position;
|
||||
in vec3 v_normal;
|
||||
in vec2 uvw;
|
||||
in vec2 uv0;
|
||||
in vec2 uv1;
|
||||
in vec2 uv2;
|
||||
in vec2 uv3;
|
||||
in vec3 diffuse;
|
||||
in vec2 luv;
|
||||
in float v_fog_factor;
|
||||
|
||||
uniform sampler2D weightMap;
|
||||
uniform sampler2D detailMap0;
|
||||
uniform sampler2D detailMap1;
|
||||
uniform sampler2D detailMap2;
|
||||
uniform sampler2D detailMap3;
|
||||
uniform sampler2D lightMap;
|
||||
in float factor_fog;
|
||||
vec4 frag () {
|
||||
vec4 color = vec4(0, 0, 0, 0);
|
||||
uniform sampler2D weightMap;
|
||||
uniform sampler2D detailMap0;
|
||||
uniform sampler2D detailMap1;
|
||||
uniform sampler2D detailMap2;
|
||||
uniform sampler2D detailMap3;
|
||||
uniform sampler2D lightMap;
|
||||
|
||||
void surf (out StandardSurface s) {
|
||||
vec4 baseColor = vec4(0, 0, 0, 0);
|
||||
|
||||
#if LAYERS == 1
|
||||
color = texture(detailMap0, uv0);
|
||||
baseColor = texture(detailMap0, uv0);
|
||||
#elif LAYERS == 2
|
||||
vec4 w = texture(weightMap, uvw);
|
||||
|
||||
color += texture(detailMap0, uv0) * w.r;
|
||||
color += texture(detailMap1, uv1) * w.g;
|
||||
baseColor += texture(detailMap0, uv0) * w.r;
|
||||
baseColor += texture(detailMap1, uv1) * w.g;
|
||||
#elif LAYERS == 3
|
||||
vec4 w = texture(weightMap, uvw);
|
||||
|
||||
color += texture(detailMap0, uv0) * w.r;
|
||||
color += texture(detailMap1, uv1) * w.g;
|
||||
color += texture(detailMap2, uv2) * w.b;
|
||||
baseColor += texture(detailMap0, uv0) * w.r;
|
||||
baseColor += texture(detailMap1, uv1) * w.g;
|
||||
baseColor += texture(detailMap2, uv2) * w.b;
|
||||
#elif LAYERS == 4
|
||||
vec4 w = texture(weightMap, uvw);
|
||||
|
||||
color += texture(detailMap0, uv0) * w.r;
|
||||
color += texture(detailMap1, uv1) * w.g;
|
||||
color += texture(detailMap2, uv2) * w.b;
|
||||
color += texture(detailMap3, uv3) * w.a;
|
||||
baseColor += texture(detailMap0, uv0) * w.r;
|
||||
baseColor += texture(detailMap1, uv1) * w.g;
|
||||
baseColor += texture(detailMap2, uv2) * w.b;
|
||||
baseColor += texture(detailMap3, uv3) * w.a;
|
||||
#else
|
||||
color = texture(detailMap0, uv0);
|
||||
baseColor = texture(detailMap0, uv0);
|
||||
#endif
|
||||
|
||||
vec3 lighting = diffuse;
|
||||
#if LIGHT_MAP == 1
|
||||
lighting += texture(lightMap, luv).rgb;
|
||||
#endif
|
||||
s.position = v_position;
|
||||
s.normal = v_normal;
|
||||
|
||||
color.rgb *= lighting;
|
||||
color = CC_APPLY_FOG(color, factor_fog);
|
||||
s.albedo = vec4(SRGBToLinear(baseColor.rgb), 1.0);
|
||||
s.occlusion = 1.0;
|
||||
s.roughness = 1.0;
|
||||
s.metallic = 0.0;
|
||||
s.emissive = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD
|
||||
s.lightmap = texture(lightMap, luv);
|
||||
#else
|
||||
s.lightmap = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
vec4 frag () {
|
||||
StandardSurface s; surf(s);
|
||||
vec4 color = CCStandardShading(s);
|
||||
color = CC_APPLY_FOG(color, v_fog_factor);
|
||||
return CCFragOutput(color);
|
||||
}
|
||||
}%
|
||||
|
||||
CCProgram shadow-caster-vs %{
|
||||
precision highp float;
|
||||
#include <cc-global>
|
||||
#include <cc-local>
|
||||
#include <cc-shadow>
|
||||
|
||||
in vec3 a_position;
|
||||
in vec3 a_normal;
|
||||
in vec2 a_texCoord;
|
||||
|
||||
out vec2 v_clip_depth;
|
||||
|
||||
vec4 vert () {
|
||||
vec4 worldPos;
|
||||
worldPos.x = cc_matWorld[3][0] + a_position.x;
|
||||
worldPos.y = cc_matWorld[3][1] + a_position.y;
|
||||
worldPos.z = cc_matWorld[3][2] + a_position.z;
|
||||
worldPos.w = 1.0;
|
||||
|
||||
vec4 clipPos = cc_matLightViewProj * worldPos;
|
||||
|
||||
v_clip_depth = clipPos.zw;
|
||||
|
||||
return clipPos;
|
||||
}
|
||||
}%
|
||||
|
||||
CCProgram shadow-caster-fs %{
|
||||
precision highp float;
|
||||
#include <packing>
|
||||
|
||||
in vec2 v_clip_depth;
|
||||
|
||||
vec4 frag () {
|
||||
return packDepthToRGBA(v_clip_depth.x / v_clip_depth.y * 0.5 + 0.5);
|
||||
}
|
||||
}%
|
||||
|
||||
@@ -476,7 +476,7 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
block_input_events: {
|
||||
brief_help: 'This component will block all input events, preventing the input from penetrating into the underlying node, typically for the background of the top UI.',
|
||||
brief_help: 'This component will block all input events, preventing the input from penetrating to other nodes below the screen, typically for the background of the top-level UI of the screen.',
|
||||
},
|
||||
tiledtile: {
|
||||
row: 'Specify the TiledTile horizontal coordinate,use map tile as the unit.',
|
||||
|
||||
@@ -482,7 +482,7 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
block_input_events: {
|
||||
brief_help: '该组件将拦截所有输入事件,防止输入穿透到下层节点,一般用于上层 UI 的背景。',
|
||||
brief_help: '该组件将拦截所有输入事件,防止输入穿透到屏幕下方的其它节点,一般用于屏幕上层 UI 的背景。',
|
||||
},
|
||||
tiledtile: {
|
||||
row: '指定 TiledTile 的横向坐标,以地图块为单位',
|
||||
|
||||
@@ -153,7 +153,7 @@ let TileFlag = cc.Enum({
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
FLIPPED_MASK: (~((0x80000000 | 0x40000000 | 0x20000000) >>> 0)) >>> 0
|
||||
FLIPPED_MASK: (~(0x80000000 | 0x40000000 | 0x20000000)) >>> 0
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
@@ -544,6 +544,18 @@ test('set sibling index during onDisable', function () {
|
||||
compOfChild.onEnable.once('child component should be re-enabled');
|
||||
});
|
||||
|
||||
test('component might be destroyed when destroy() called before node activating', function () {
|
||||
var node = new cc.Node();
|
||||
var comp = createDisabledComp(node, 'destroyed');
|
||||
comp.onDestroy = new Callback().disable('onDestroy should not be called');
|
||||
comp.destroy();
|
||||
|
||||
cc.director.getScene().addChild(node);
|
||||
|
||||
cc.game.step();
|
||||
strictEqual(comp.isValid, false, 'component should be destroyed');
|
||||
});
|
||||
|
||||
// test('could deactivate parent in onLoad', function () {
|
||||
// strictEqual(StillInvokeRestCompsOnSameNode, false, 'test cases not implemented if "StillInvokeRestCompsOnSameNode"');
|
||||
// strictEqual(StillInvokeOnEnableOnSameComp, false, 'test cases not implemented if "StillInvokeOnEnableOnSameComp"');
|
||||
|
||||
@@ -50,3 +50,17 @@ test('call "once" twice', function () {
|
||||
.disable('should only invoke once');
|
||||
target.emit('fire');
|
||||
});
|
||||
|
||||
test('call "off" without handler twice during invoking', function () {
|
||||
var target = new cc.EventTarget();
|
||||
var ctx = {};
|
||||
|
||||
function handler () {
|
||||
target.off('fire');
|
||||
target.off('fire', handler, ctx);
|
||||
}
|
||||
target.on('fire', handler, ctx, true);
|
||||
target.emit('fire');
|
||||
|
||||
expect(0);
|
||||
});
|
||||
|
||||
@@ -123,6 +123,31 @@ test('activeInHierarchy', function () {
|
||||
strictEqual(child.activeInHierarchy, false, 'child should not activeInHierarchy after remove from scene');
|
||||
});
|
||||
|
||||
test('activeInHierarchy should be false after destroy', function () {
|
||||
var parent = new cc.Node();
|
||||
var child = new cc.Node();
|
||||
child.parent = parent;
|
||||
|
||||
cc.director.getScene().addChild(parent);
|
||||
|
||||
parent.destroy();
|
||||
cc.game.step();
|
||||
|
||||
strictEqual(parent.activeInHierarchy, false, 'parent should not activeInHierarchy after destroy');
|
||||
strictEqual(child.activeInHierarchy, false, 'child should not activeInHierarchy after destroy');
|
||||
});
|
||||
|
||||
test('nodes should be destroyed with the scene', function () {
|
||||
var child = new cc.Node();
|
||||
var scene = cc.director.getScene();
|
||||
child.parent = scene;
|
||||
|
||||
cc.director.runSceneImmediate(new cc.Scene());
|
||||
|
||||
strictEqual(child.activeInHierarchy, false, 'nodes should not activeInHierarchy after destroy');
|
||||
strictEqual(child.isValid, false, 'nodes should be destroyed with the scene');
|
||||
});
|
||||
|
||||
test('activation logic for component', function () {
|
||||
// 这里主要测试node,不是测试component
|
||||
|
||||
|
||||
Reference in New Issue
Block a user