Merge branch '3d-stable' of https://github.com/cocos-creator/engine into 3d

This commit is contained in:
jerrywwl
2019-03-18 11:16:05 +08:00
44 changed files with 585 additions and 569 deletions
+4 -3
View File
@@ -2,10 +2,11 @@
"version": "0.2.0",
"configurations": [
{
"type": "node",
"type": "chrome",
"request": "launch",
"name": "Generate declaration",
"program": "${workspaceFolder}\\scripts\\generate-declaration-cli.js"
"name": "Launch Chrome",
"url": "http://localhost:8002/playground/simple.html",
"webRoot": "${workspaceFolder}"
}
]
}
+12 -2
View File
@@ -37,14 +37,24 @@ declare const CC_QQPLAY: boolean;
declare const CC_RUNTIME: boolean;
declare const CC_SUPPORT_JIT: boolean;
declare const cc: any;
declare const cc : {
// polyfills: {
// destroyObject? (object: any): void;
// };
[x: string]: any;
};
type RecursivePartial<T> = {
declare type RecursivePartial<T> = {
[P in keyof T]?:
T[P] extends Array<infer U> ? Array<RecursivePartial<U>> :
T[P] extends ReadonlyArray<infer V> ? ReadonlyArray<RecursivePartial<V>> : RecursivePartial<T[P]>;
};
declare interface IWritableArrayLike<T> {
readonly length: number;
[index: number]: T;
}
declare module "webgl-debug" {
export function makeDebugContext(
webGLRenderingContext: WebGLRenderingContext,
View File
+11 -7
View File
File diff suppressed because one or more lines are too long
@@ -34,7 +34,7 @@ import { LightComponent } from './light-component';
export class DirectionalLightComponent extends LightComponent {
@property
protected _intensity = 10000;
protected _illuminance = 65000;
protected _type = LightType.DIRECTIONAL;
protected _light: DirectionalLight | null = null;
@@ -45,12 +45,12 @@ export class DirectionalLightComponent extends LightComponent {
* !#ch 光源强度
*/
@property
get intensity () {
return this._intensity;
get illuminance () {
return this._illuminance;
}
set intensity (val) {
this._intensity = val;
if (this._light) { this._light.illuminance = this._intensity; }
set illuminance (val) {
this._illuminance = val;
if (this._light) { this._light.illuminance = this._illuminance; }
}
protected _createLight (scene?: RenderScene) {
@@ -61,7 +61,7 @@ export class DirectionalLightComponent extends LightComponent {
return;
}
this._light = scene.mainLight;
this.intensity = this._intensity;
this.illuminance = this._illuminance;
super._createLight(scene);
}
@@ -238,10 +238,10 @@ export class ParticleSystemComponent extends Component {
this.renderer = null;
}
private onLoad () {
protected onLoad () {
// HACK, TODO
this.renderer = this.getComponent(ParticleSystemRenderer);
this.renderer.onInit();
this.renderer!.onInit();
this.shapeModule.onInit(this);
this.textureAnimationModule.onInit(this);
@@ -251,17 +251,17 @@ export class ParticleSystemComponent extends Component {
// this._system.add(this);
}
private onDestroy () {
protected onDestroy () {
// this._system.remove(this);
}
private onEnable () {
protected onEnable () {
if (this.playOnAwake) {
this.play();
}
}
private onDisable () {
protected onDisable () {
}
@@ -434,7 +434,7 @@ export class ParticleSystemComponent extends Component {
}
}
private update (dt) {
protected update (dt) {
const scaledDeltaTime = dt * this.simulationSpeed;
if (this._isPlaying) {
this._time += scaledDeltaTime;
+2 -2
View File
@@ -1,5 +1,5 @@
import { Vec3 } from '../../core/value-types';
import { BoxShapeBase, ICreateBodyOptions, PhysicsWorldBase, RigidBodyBase } from './api';
import { BoxShapeBase, ICreateBodyOptions, PhysicsWorldBase, RigidBodyBase, SphereShapeBase } from './api';
import { BoxShape, PhysicsWorld, RigidBody, SphereShape } from './impl-selector';
import { RaycastResult } from './raycast-result';
@@ -15,7 +15,7 @@ export function createBoxShape (size: Vec3): BoxShapeBase {
return new BoxShape(size);
}
export function createSphereShape (radius: number): SphereShape {
export function createSphereShape (radius: number): SphereShapeBase {
return new SphereShape(radius);
}
-43
View File
@@ -1,43 +0,0 @@
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
import { RawAsset } from "./raw-asset";
export class Asset extends RawAsset {
protected _native: string;
public loaded: boolean;
public _nativeAsset: any;
public nativeUrl: string;
static preventDeferredLoadDependents: boolean;
static preventPreloadNativeObject: boolean;
static deserialize(data: string): object;
public createNode: (err: string, node: object) => void | null;
public toString(): string;
public serialize(): string;
protected _setRawAsset(filename: string, inLibrary: boolean): void;
}
+63 -62
View File
@@ -25,6 +25,7 @@
****************************************************************************/
import { ccclass, property } from '../core/data/class-decorator';
import { Node } from '../scene-graph';
import { RawAsset } from './raw-asset';
/**
@@ -50,20 +51,6 @@ import { RawAsset } from './raw-asset';
*/
@ccclass('cc.Asset')
export class Asset extends RawAsset {
constructor () {
super();
/**
* !#en
* Whether the asset is loaded or not
* !#zh
* 该资源是否已经成功加载
*
* @property loaded
* @type {Boolean}
*/
this.loaded = true;
}
/**
* !#en
* Returns the url of this asset's native object, if none it will returns an empty string.
@@ -74,18 +61,18 @@ export class Asset extends RawAsset {
* @readOnly
*/
@property({
visible: false
visible: false,
})
get nativeUrl () {
if (this._native) {
var name = this._native;
const name = this._native;
if (name.charCodeAt(0) === 47) { // '/'
// remove library tag
// not imported in library, just created on-the-fly
return name.slice(1);
}
if (cc.AssetLibrary) {
var base = cc.AssetLibrary.getLibUrlNoExt(this._uuid, true);
const base = cc.AssetLibrary.getLibUrlNoExt(this._uuid, true);
if (name.charCodeAt(0) === 46) { // '.'
// imported in dir where json exist
return base + name;
@@ -102,15 +89,6 @@ export class Asset extends RawAsset {
return '';
}
/**
* Serializable url for native asset.
* @property {String} _native
* @default ""
* @private
*/
@property
_native = ""
/**
* The underlying native asset of this asset if one is available.
* This property can be used to access additional details or functionality releated to the asset.
@@ -121,24 +99,12 @@ export class Asset extends RawAsset {
* @type {any}
*/
@property
get _nativeAsset () {
get _nativeAsset (): any {
return null;
}
set _nativeAsset (obj) {
}
/**
* 应 AssetDB 要求提供这个方法
*
* @method deserialize
* @param {String} data
* @return {Asset}
* @static
* @private
*/
static deserialize (data) {
return cc.deserialize(data);
}
/**
* !#en Indicates whether its dependent raw assets can support deferred load if the owner scene (or prefab) is marked as `asyncLoadAssets`.
* !#zh 当场景或 Prefab 被标记为 `asyncLoadAssets`,禁止延迟加载该资源所依赖的其它 RawAsset。
@@ -147,7 +113,7 @@ export class Asset extends RawAsset {
* @default false
* @static
*/
static preventDeferredLoadDependents = false;
public static preventDeferredLoadDependents = false;
/**
* !#en Indicates whether its native object should be preloaded from native url.
@@ -157,13 +123,45 @@ export class Asset extends RawAsset {
* @default false
* @static
*/
static preventPreloadNativeObject = false;
public static preventPreloadNativeObject = false;
/**
* 应 AssetDB 要求提供这个方法
*
* @method deserialize
* @param {String} data
* @return {Asset}
* @static
* @private
*/
public static deserialize (data) {
return cc.deserialize(data);
}
/**
* !#en
* Whether the asset is loaded or not
* !#zh
* 该资源是否已经成功加载
*/
public loaded = true;
/**
* Serializable url for native asset. For internal usage.
* @default ""
*/
@property
public _native: string | undefined = '';
constructor () {
super();
}
/**
* Returns the string representation of the object.
*
* The `Asset` object overrides the `toString()` method of the `Object` object.
* JavaScript calls the toString() method automatically when an asset is to be represented as a text value or when a texture is referred to in a string concatenation.
* JavaScript calls the toString() method automatically when an asset is to
* be represented as a text value or when a texture is referred to in a string concatenation.
*
* For assets of the native type, it will return `this.nativeUrl`.
* Otherwise, an empty string is returned.
@@ -172,7 +170,7 @@ export class Asset extends RawAsset {
* @method toString
* @return {String}
*/
toString () {
public toString () {
return this.nativeUrl;
}
@@ -183,20 +181,19 @@ export class Asset extends RawAsset {
* @return {String}
* @private
*/
serialize () {
return Editor.serialize(this);
}
// public serialize () {
// return Editor.serialize(this);
// }
/**
* Set native file name for this asset.
* @seealso nativeUrl
*
* @method _setRawAsset
* @param {String} filename
* @param {Boolean} [inLibrary=true]
* @param filename
* @param [inLibrary=true]
* @private
*/
_setRawAsset (filename, inLibrary) {
public _setRawAsset (filename: string, inLibrary?: boolean) {
if (inLibrary !== false) {
this._native = filename || undefined;
}
@@ -204,21 +201,25 @@ export class Asset extends RawAsset {
this._native = '/' + filename; // simply use '/' to tag location where is not in the library
}
}
/**
* !#en
* Create a new node using this asset in the scene.<br/>
* If this type of asset dont have its corresponding node type, this method should be null.
* !#zh
* 使用该资源在场景中创建一个新节点。<br/>
* 如果这类资源没有相应的节点类型,该方法应该是空的。
*/
public createNode? (callback: CreateNodeCallback): void;
}
/**
* !#en
* Create a new node using this asset in the scene.<br/>
* If this type of asset dont have its corresponding node type, this method should be null.
* !#zh
* 使用该资源在场景中创建一个新节点。<br/>
* 如果这类资源没有相应的节点类型,该方法应该是空的。
*
* @method createNode
* @param {Function} callback
* @param {String} callback.error - null or the error info
* @param {Object} callback.node - the created node or null
* @param error - null or the error info
* @param node - the created node or null
*/
type CreateNodeCallback = (error: Error | null, node: Node) => void;
// @ts-ignore
Asset.prototype.createNode = null;
cc.Asset = Asset;
-33
View File
@@ -1,33 +0,0 @@
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
import { CCObject } from '../core/data/object';
export class RawAsset extends CCObject {
_uuid: string;
public constructor();
static isRawAssetType(ctor: Function): boolean;
}
@@ -24,9 +24,9 @@
THE SOFTWARE.
****************************************************************************/
import { isChildClassOf } from '../core/utils/js';
import { CCObject } from '../core/data/object';
import { ccclass } from '../core/data/class-decorator';
import { CCObject } from '../core/data/object';
import { isChildClassOf } from '../core/utils/js';
/**
* !#en
@@ -39,30 +39,28 @@ import { ccclass } from '../core/data/class-decorator';
*/
@ccclass('cc.RawAsset')
export class RawAsset extends CCObject {
/**
* For internal usage.
*/
public static isRawAssetType (ctor: Function) {
return isChildClassOf(ctor, cc.RawAsset) && !isChildClassOf(ctor, cc.Asset);
}
/**
* For internal usage.
*/
// @ts-ignore
public _uuid: string;
constructor () {
super();
/**
* @property _uuid
* @type {String}
* @private
*/
Object.defineProperty(this, '_uuid', {
value: '',
writable: true,
// enumerable is false by default, to avoid uuid being assigned to empty string during destroy
});
}
/**
* @method isRawAssetType
* @param {Function} ctor
* @returns {Boolean}
* @static
* @private
*/
static isRawAssetType (ctor) {
return isChildClassOf(ctor, cc.RawAsset) && !isChildClassOf(ctor, cc.Asset);
}
}
cc.RawAsset = RawAsset;
+14 -13
View File
@@ -201,13 +201,13 @@ export class TextureBase extends EventTargetFactory(Asset) {
protected _mipFilter: number = Filter.LINEAR;
@property
protected _wrapU: number = WrapMode.REPEAT;
protected _wrapS: number = WrapMode.REPEAT;
@property
protected _wrapV: number = WrapMode.REPEAT;
protected _wrapT: number = WrapMode.REPEAT;
@property
protected _wrapW: number = WrapMode.REPEAT;
protected _wrapR: number = WrapMode.REPEAT;
@property
protected _anisotropy = 16;
@@ -308,14 +308,15 @@ export class TextureBase extends EventTargetFactory(Asset) {
* If the texture size is NPOT (non power of 2), then in can only use gl.CLAMP_TO_EDGE in gl.TEXTURE_WRAP_{S,T}.
* !#zh 设置纹理包装模式。
* 若纹理贴图尺寸是 NPOT(non power of 2),则只能使用 Texture2D.WrapMode.CLAMP_TO_EDGE。
* @param wrapU
* @param wrapV
* @param wrapS
* @param wrapT
* @param wrapR
*/
public setWrapMode (wrapU: WrapMode, wrapV: WrapMode, wrapW?: WrapMode) {
if (wrapU !== this._wrapU) { this._wrapU = wrapU; this._samplerInfo[3] = wrapU; }
if (wrapV !== this._wrapV) { this._wrapV = wrapV; this._samplerInfo[4] = wrapV; }
if (wrapW === undefined) { return; }
if (wrapW !== this._wrapW) { this._wrapW = wrapW; this._samplerInfo[5] = wrapW; }
public setWrapMode (wrapS: WrapMode, wrapT: WrapMode, wrapR?: WrapMode) {
if (wrapS !== this._wrapS) { this._wrapS = wrapS; this._samplerInfo[3] = wrapS; }
if (wrapT !== this._wrapT) { this._wrapT = wrapT; this._samplerInfo[4] = wrapT; }
if (wrapR === undefined) { return; }
if (wrapR !== this._wrapR) { this._wrapR = wrapR; this._samplerInfo[5] = wrapR; }
}
/**
@@ -406,7 +407,7 @@ export class TextureBase extends EventTargetFactory(Asset) {
*/
public _serialize (): any {
return this._minFilter + ',' + this._magFilter + ',' +
this._wrapU + ',' + this._wrapV + ',' +
this._wrapS + ',' + this._wrapT + ',' +
(this._premultiplyAlpha ? 1 : 0) + ',' +
this._mipFilter + ',' + this._anisotropy + ',' +
(this._flipY ? 1 : 0) + ',' +
@@ -527,9 +528,9 @@ export class TextureBase extends EventTargetFactory(Asset) {
};
if (source instanceof HTMLElement) {
gfxDevice.copyImageSourceToTexture([source], this._texture, [region]);
gfxDevice.copyTexImagesToTexture([source], this._texture, [region]);
} else {
gfxDevice.copyBufferToTexture(source, this._texture, [region]);
gfxDevice.copyBuffersToTexture([source], this._texture, [region]);
}
}
-1
View File
@@ -1,4 +1,3 @@
import { IWritableArrayLike } from './fwd-decls';
import { EPSILON } from './utils';
/**
-1
View File
@@ -1,4 +1,3 @@
import { IWritableArrayLike } from './fwd-decls';
import { EPSILON } from './utils';
// tslint:disable: one-variable-per-declaration
-4
View File
@@ -1,4 +0,0 @@
export interface IWritableArrayLike<T> {
readonly length: number;
[index: number]: T;
}
-1
View File
@@ -1,4 +1,3 @@
import { IWritableArrayLike } from './fwd-decls';
import { EPSILON } from './utils';
import vec2 from './vec2';
-1
View File
@@ -1,4 +1,3 @@
import { IWritableArrayLike } from './fwd-decls';
import { EPSILON } from './utils';
import vec2 from './vec2';
-1
View File
@@ -1,4 +1,3 @@
import { IWritableArrayLike } from './fwd-decls';
import mat3 from './mat3';
import { toDegree } from './utils';
import vec3 from './vec3';
-1
View File
@@ -1,4 +1,3 @@
import { IWritableArrayLike } from './fwd-decls';
import mat2 from './mat2';
import mat23 from './mat23';
import mat3 from './mat3';
-1
View File
@@ -1,4 +1,3 @@
import { IWritableArrayLike } from './fwd-decls';
import mat3 from './mat3';
import mat4 from './mat4';
import quat from './quat';
-1
View File
@@ -1,4 +1,3 @@
import { IWritableArrayLike } from './fwd-decls';
import mat4 from './mat4';
import quat from './quat';
import { EPSILON, random } from './utils';
+2 -2
View File
@@ -191,8 +191,8 @@ export abstract class GFXDevice {
public abstract createWindow (info: IGFXWindowInfo): GFXWindow;
public abstract present ();
public abstract copyBufferToTexture (buffer: ArrayBuffer, texture: GFXTexture, regions: GFXBufferTextureCopy[]);
public abstract copyImageSourceToTexture (source: CanvasImageSource[], texture: GFXTexture, regions: GFXBufferTextureCopy[]);
public abstract copyBuffersToTexture (buffers: ArrayBuffer[], texture: GFXTexture, regions: GFXBufferTextureCopy[]);
public abstract copyTexImagesToTexture (texImages: TexImageSource[], texture: GFXTexture, regions: GFXBufferTextureCopy[]);
public abstract copyFramebufferToBuffer (srcFramebuffer: GFXFramebuffer, dstBuffer: ArrayBuffer, regions: GFXBufferTextureCopy[]);
public hasFeature (feature: GFXFeature): boolean {
+1
View File
@@ -78,6 +78,7 @@ export abstract class GFXTexture extends GFXObject {
protected _arrayLayer: number = 1;
protected _mipLevel: number = 1;
protected _flags: GFXTextureFlags = GFXTextureFlagBit.NONE;
protected _isPowerOf2: boolean = false;
protected _size: number = 0;
protected _buffer: ArrayBuffer | null = null;
+145 -119
View File
@@ -793,14 +793,20 @@ export function WebGLCmdFuncCreateTexture (device: WebGLGFXDevice, gpuTexture: W
}
}
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_S, WebGLRenderingContext.CLAMP_TO_EDGE);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_T, WebGLRenderingContext.CLAMP_TO_EDGE);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_MIN_FILTER, WebGLRenderingContext.LINEAR);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_MAG_FILTER, WebGLRenderingContext.LINEAR);
gpuTexture.glWrapS = WebGLRenderingContext.CLAMP_TO_EDGE;
gpuTexture.glWrapT = WebGLRenderingContext.CLAMP_TO_EDGE;
if (gpuTexture.isPowerOf2) {
gpuTexture.glWrapS = WebGLRenderingContext.REPEAT;
gpuTexture.glWrapT = WebGLRenderingContext.REPEAT;
} else {
gpuTexture.glWrapS = WebGLRenderingContext.CLAMP_TO_EDGE;
gpuTexture.glWrapT = WebGLRenderingContext.CLAMP_TO_EDGE;
}
gpuTexture.glMinFilter = WebGLRenderingContext.LINEAR;
gpuTexture.glMagFilter = WebGLRenderingContext.LINEAR;
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_S, gpuTexture.glWrapS);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_T, gpuTexture.glWrapT);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_MIN_FILTER, gpuTexture.glMinFilter);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_MAG_FILTER, gpuTexture.glMagFilter);
}
break;
@@ -844,14 +850,20 @@ export function WebGLCmdFuncCreateTexture (device: WebGLGFXDevice, gpuTexture: W
}
}
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_S, WebGLRenderingContext.CLAMP_TO_EDGE);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_T, WebGLRenderingContext.CLAMP_TO_EDGE);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_MIN_FILTER, WebGLRenderingContext.LINEAR);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_MAG_FILTER, WebGLRenderingContext.LINEAR);
gpuTexture.glWrapS = WebGLRenderingContext.CLAMP_TO_EDGE;
gpuTexture.glWrapT = WebGLRenderingContext.CLAMP_TO_EDGE;
if (gpuTexture.isPowerOf2) {
gpuTexture.glWrapS = WebGLRenderingContext.REPEAT;
gpuTexture.glWrapT = WebGLRenderingContext.REPEAT;
} else {
gpuTexture.glWrapS = WebGLRenderingContext.CLAMP_TO_EDGE;
gpuTexture.glWrapT = WebGLRenderingContext.CLAMP_TO_EDGE;
}
gpuTexture.glMinFilter = WebGLRenderingContext.LINEAR;
gpuTexture.glMagFilter = WebGLRenderingContext.LINEAR;
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_S, gpuTexture.glWrapS);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_T, gpuTexture.glWrapT);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_MIN_FILTER, gpuTexture.glMinFilter);
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_MAG_FILTER, gpuTexture.glMagFilter);
}
break;
@@ -1283,6 +1295,8 @@ export function WebGLCmdFuncExecuteCmds (device: WebGLGFXDevice, cmdPackage: Web
let gpuShader: WebGLGPUShader | null = null;
let gpuInputAssembler: IWebGLGPUInputAssembler | null = null;
let glPrimitive = WebGLRenderingContext.TRIANGLES;
let glWrapS;
let glWrapT;
for (let i = 0; i < cmdPackage.cmds.length; ++i) {
const cmd = cmdPackage.cmds.array[i];
@@ -1935,15 +1949,22 @@ export function WebGLCmdFuncExecuteCmds (device: WebGLGFXDevice, cmdPackage: Web
if (glTexUnit) {
const gpuSampler = gpuBinding.gpuSampler;
if (gpuTexture.glWrapS !== gpuSampler.glWrapS) {
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_S, gpuSampler.glWrapS);
gpuTexture.glWrapS = gpuSampler.glWrapS;
if (gpuTexture.isPowerOf2) {
glWrapS = gpuSampler.glWrapS;
glWrapT = gpuSampler.glWrapT;
} else {
glWrapS = WebGLRenderingContext.CLAMP_TO_EDGE;
glWrapT = WebGLRenderingContext.CLAMP_TO_EDGE;
}
if (gpuTexture.glWrapT !== gpuSampler.glWrapT) {
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_T, gpuSampler.glWrapT);
gpuTexture.glWrapT = gpuSampler.glWrapT;
if (gpuTexture.glWrapS !== glWrapS) {
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_S, glWrapS);
gpuTexture.glWrapS = glWrapS;
}
if (gpuTexture.glWrapT !== glWrapT) {
gl.texParameteri(gpuTexture.glTarget, WebGLRenderingContext.TEXTURE_WRAP_T, glWrapT);
gpuTexture.glWrapT = glWrapT;
}
if (gpuTexture.glMinFilter !== gpuSampler.glMinFilter) {
@@ -2287,9 +2308,9 @@ export function WebGLCmdFuncExecuteCmds (device: WebGLGFXDevice, cmdPackage: Web
}
case WebGLCmd.COPY_BUFFER_TO_TEXTURE: {
const cmd5 = cmdPackage.copyBufferToTextureCmds.array[cmdId];
WebGLCmdFuncCopyBufferToTexture(
WebGLCmdFuncCopyBuffersToTexture(
device,
(cmd5.gpuBuffer as WebGLGPUBuffer).buffer as GFXBufferSource,
[(cmd5.gpuBuffer as WebGLGPUBuffer).buffer!],
cmd5.gpuTexture as WebGLGPUTexture,
cmd5.regions);
@@ -2299,22 +2320,16 @@ export function WebGLCmdFuncExecuteCmds (device: WebGLGFXDevice, cmdPackage: Web
} // for
}
export function WebGLCmdFuncCopyBufferToTexture (
export function WebGLCmdFuncCopyTexImagesToTexture (
device: WebGLGFXDevice,
buffer: GFXBufferSource,
texImages: TexImageSource[],
gpuTexture: WebGLGPUTexture,
regions: GFXBufferTextureCopy[]) {
const gl = device.gl;
const buff = buffer as ArrayBuffer;
const fmtInfo: IGFXFormatInfo = GFXFormatInfos[gpuTexture.format];
let m = 0;
let w = 1;
let h = 1;
let n = 0;
let f = 0;
let buffOffset = 0;
switch (gpuTexture.glTarget) {
case WebGLRenderingContext.TEXTURE_2D: {
const glTexUnit = device.stateCache.glTex2DUnits[device.stateCache.texUnit];
@@ -2323,48 +2338,12 @@ export function WebGLCmdFuncCopyBufferToTexture (
glTexUnit.glTexture = gpuTexture.glTexture;
}
const isCompressed = GFXFormatInfos[gpuTexture.format].isCompressed;
if (!isCompressed) {
for (const region of regions) {
buffOffset = region.buffOffset + region.buffTexHeight * region.buffStride;
w = region.texExtent.width;
h = region.texExtent.height;
for (m = region.texSubres.baseMipLevel; m < region.texSubres.levelCount; ++m) {
const memSize = GFXFormatSize(gpuTexture.format, w, h, 1);
const data = buff.slice(buffOffset, buffOffset + memSize);
const pixels = !fmtInfo.isFloating ? new Uint8Array(data) : new Float32Array(data);
gl.texSubImage2D(WebGLRenderingContext.TEXTURE_2D, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, gpuTexture.glType, pixels);
buffOffset += memSize;
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
}
} else {
for (const region of regions) {
buffOffset = region.buffOffset + region.buffTexHeight * region.buffStride;
w = region.texExtent.width;
h = region.texExtent.height;
for (m = region.texSubres.baseMipLevel; m < region.texSubres.levelCount; ++m) {
const memSize = GFXFormatSize(gpuTexture.format, w, h, 1);
const data = buff.slice(buffOffset, buffOffset + memSize);
const pixels = !fmtInfo.isFloating ? new Uint8Array(data) : new Float32Array(data);
gl.compressedTexSubImage2D(WebGLRenderingContext.TEXTURE_2D, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, pixels);
buffOffset += memSize;
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
for (const region of regions) {
n = 0;
for (m = region.texSubres.baseMipLevel; m < region.texSubres.levelCount; ++m) {
gl.texSubImage2D(WebGLRenderingContext.TEXTURE_2D, m,
region.texOffset.x, region.texOffset.y,
gpuTexture.glFormat, gpuTexture.glType, texImages[n++]);
}
}
break;
@@ -2376,53 +2355,100 @@ export function WebGLCmdFuncCopyBufferToTexture (
glTexUnit.glTexture = gpuTexture.glTexture;
}
const isCompressed = GFXFormatInfos[gpuTexture.format].isCompressed;
if (!isCompressed) {
for (const region of regions) {
buffOffset = region.buffOffset + region.buffTexHeight * region.buffStride;
const fcount = region.texSubres.baseArrayLayer + region.texSubres.layerCount;
for (f = region.texSubres.baseArrayLayer; f < fcount; ++f) {
w = region.texExtent.width;
h = region.texExtent.height;
const mcount = region.texSubres.baseMipLevel + region.texSubres.levelCount;
for (m = region.texSubres.baseMipLevel; m < mcount; ++m) {
const memSize = GFXFormatSize(gpuTexture.format, w, h, 1);
const data = buff.slice(buffOffset, buffOffset + memSize);
const pixels = !fmtInfo.isFloating ? new Uint8Array(data) : new Float32Array(data);
gl.texSubImage2D(WebGLRenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, gpuTexture.glType, pixels);
buffOffset += memSize;
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
}
}
} else {
for (const region of regions) {
buffOffset = region.buffOffset + region.buffTexHeight * region.buffStride;
const fcount = region.texSubres.baseArrayLayer + region.texSubres.layerCount;
for (f = region.texSubres.baseArrayLayer; f < fcount; ++f) {
w = region.texExtent.width;
h = region.texExtent.height;
const mcount = region.texSubres.baseMipLevel + region.texSubres.levelCount;
for (m = region.texSubres.baseMipLevel; m < mcount; ++m) {
const memSize = GFXFormatSize(gpuTexture.format, w, h, 1);
const data = buff.slice(buffOffset, buffOffset + memSize);
const pixels = !fmtInfo.isFloating ? new Uint8Array(data) : new Float32Array(data);
gl.compressedTexSubImage2D(WebGLRenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, pixels);
buffOffset += memSize;
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
for (const region of regions) {
n = 0;
const fcount = region.texSubres.baseArrayLayer + region.texSubres.layerCount;
for (f = region.texSubres.baseArrayLayer; f < fcount; ++f) {
const mcount = region.texSubres.baseMipLevel + region.texSubres.levelCount;
for (m = region.texSubres.baseMipLevel; m < mcount; ++m) {
gl.texSubImage2D(WebGLRenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, m,
region.texOffset.x, region.texOffset.y,
gpuTexture.glFormat, gpuTexture.glType, texImages[n++]);
}
}
}
break;
}
default: {
console.error('Unsupported GL texture type, copy buffer to texture failed.');
}
}
if (gpuTexture.flags & GFXTextureFlagBit.GEN_MIPMAP) {
gl.generateMipmap(gpuTexture.glTarget);
}
}
export function WebGLCmdFuncCopyBuffersToTexture (
device: WebGLGFXDevice,
buffers: ArrayBuffer[],
gpuTexture: WebGLGPUTexture,
regions: GFXBufferTextureCopy[]) {
const gl = device.gl;
let m = 0;
let n = 0;
let w = 1;
let h = 1;
let f = 0;
const fmtInfo: IGFXFormatInfo = GFXFormatInfos[gpuTexture.format];
const isCompressed = fmtInfo.isCompressed;
switch (gpuTexture.glTarget) {
case WebGLRenderingContext.TEXTURE_2D: {
const glTexUnit = device.stateCache.glTex2DUnits[device.stateCache.texUnit];
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
gl.bindTexture(WebGLRenderingContext.TEXTURE_2D, gpuTexture.glTexture);
glTexUnit.glTexture = gpuTexture.glTexture;
}
for (const region of regions) {
n = 0;
w = region.texExtent.width;
h = region.texExtent.height;
for (m = region.texSubres.baseMipLevel; m < region.texSubres.levelCount; ++m) {
const pixels = !fmtInfo.isFloating ? new Uint8Array(buffers[n++]) : new Float32Array(buffers[n++]);
if (!isCompressed) {
gl.texSubImage2D(WebGLRenderingContext.TEXTURE_2D, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, gpuTexture.glType, pixels);
} else {
gl.compressedTexSubImage2D(WebGLRenderingContext.TEXTURE_2D, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, pixels);
}
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
}
break;
}
case WebGLRenderingContext.TEXTURE_CUBE_MAP: {
const glTexUnit = device.stateCache.glTexCubeUnits[device.stateCache.texUnit];
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
gl.bindTexture(WebGLRenderingContext.TEXTURE_CUBE_MAP, gpuTexture.glTexture);
glTexUnit.glTexture = gpuTexture.glTexture;
}
for (const region of regions) {
n = 0;
const fcount = region.texSubres.baseArrayLayer + region.texSubres.layerCount;
for (f = region.texSubres.baseArrayLayer; f < fcount; ++f) {
w = region.texExtent.width;
h = region.texExtent.height;
const mcount = region.texSubres.baseMipLevel + region.texSubres.levelCount;
for (m = region.texSubres.baseMipLevel; m < mcount; ++m) {
const pixels = !fmtInfo.isFloating ? new Uint8Array(buffers[n++]) : new Float32Array(buffers[n++]);
gl.texSubImage2D(WebGLRenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, gpuTexture.glType, pixels);
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
}
}
+8 -37
View File
@@ -25,9 +25,7 @@ import { WebGLGFXBindingLayout } from './webgl-binding-layout';
import { WebGLGFXBuffer } from './webgl-buffer';
import { WebGLGFXCommandAllocator } from './webgl-command-allocator';
import { WebGLGFXCommandBuffer } from './webgl-command-buffer';
import {
WebGLCmdFuncCopyBufferToTexture,
} from './webgl-commands';
import { WebGLCmdFuncCopyBuffersToTexture, WebGLCmdFuncCopyTexImagesToTexture } from './webgl-commands';
import { WebGLGFXFramebuffer } from './webgl-framebuffer';
import { WebGLGFXInputAssembler } from './webgl-input-assembler';
import { WebGLGFXPipelineLayout } from './webgl-pipeline-layout';
@@ -463,49 +461,22 @@ export class WebGLGFXDevice extends GFXDevice {
(this._cmdAllocator as WebGLGFXCommandAllocator).releaseCmds();
}
public copyBufferToTexture (buffer: ArrayBuffer, texture: GFXTexture, regions: GFXBufferTextureCopy[]) {
WebGLCmdFuncCopyBufferToTexture(
public copyBuffersToTexture (buffers: ArrayBuffer[], texture: GFXTexture, regions: GFXBufferTextureCopy[]) {
WebGLCmdFuncCopyBuffersToTexture(
this,
buffer,
buffers,
(texture as WebGLGFXTexture).gpuTexture,
regions);
}
public copyImageSourceToTexture (
source: CanvasImageSource[],
public copyTexImagesToTexture (
texImages: TexImageSource[],
texture: GFXTexture,
regions: GFXBufferTextureCopy[]) {
if (!this._canvas2D) { return; }
const context = this._canvas2D.getContext('2d');
if (!context) { return; }
const data: Uint8ClampedArray[] = [];
const faces = source.length / regions.length;
let imgSrc: CanvasImageSource;
for (let j = 0; j < regions.length; j++) {
for (let i = 0; i < faces; i++) {
const level = regions[j].texSubres.baseMipLevel;
this._canvas2D.width = texture.width >> level;
this._canvas2D.height = texture.height >> level;
imgSrc = source[j * faces + i];
if (imgSrc.width <= 0 || imgSrc.height <= 0) {
return ;
}
context.drawImage(imgSrc, 0, 0);
data.push(context.getImageData(0, 0, this._canvas2D.width, this._canvas2D.height).data);
}
}
const buffer = new Uint8ClampedArray(data.reduce((acc, cur) => acc + cur.length, 0));
data.reduce((acc, cur) => { buffer.set(cur, acc); return acc + cur.length; }, 0);
WebGLCmdFuncCopyBufferToTexture(
WebGLCmdFuncCopyTexImagesToTexture(
this,
buffer,
texImages,
(texture as WebGLGFXTexture).gpuTexture,
regions);
}
+1
View File
@@ -54,6 +54,7 @@ export class WebGLGPUTexture {
public arrayLayer: number = 1;
public mipLevel: number = 1;
public flags: GFXTextureFlags = GFXTextureFlagBit.NONE;
public isPowerOf2: boolean = false;
public glTarget: GLenum = 0;
public glInternelFmt: GLenum = 0;
+6 -6
View File
@@ -81,9 +81,9 @@ export class WebGLGFXSampler extends GFXSampler {
let glMinFilter = WebGLRenderingContext.NONE;
let glMagFilter = WebGLRenderingContext.NONE;
const minFilter = (info.minFilter !== undefined ? info.minFilter : GFXFilter.LINEAR);
const magFilter = (info.magFilter !== undefined ? info.magFilter : GFXFilter.LINEAR);
const mipFilter = (info.mipFilter !== undefined ? info.mipFilter : GFXFilter.NONE);
const minFilter = this._state.minFilter;
const magFilter = this._state.magFilter;
const mipFilter = this._state.mipFilter;
if (minFilter === GFXFilter.LINEAR || minFilter === GFXFilter.ANISOTROPIC) {
if (mipFilter === GFXFilter.LINEAR || mipFilter === GFXFilter.ANISOTROPIC) {
@@ -109,9 +109,9 @@ export class WebGLGFXSampler extends GFXSampler {
glMagFilter = WebGLRenderingContext.NEAREST;
}
const glWrapS = (info.addressU !== undefined ? WebGLWraps[info.addressU] : WebGLRenderingContext.CLAMP_TO_EDGE);
const glWrapT = (info.addressV !== undefined ? WebGLWraps[info.addressV] : WebGLRenderingContext.CLAMP_TO_EDGE);
const glWrapR = (info.addressW !== undefined ? WebGLWraps[info.addressW] : WebGLRenderingContext.CLAMP_TO_EDGE);
const glWrapS = WebGLWraps[this._state.addressU];
const glWrapT = WebGLWraps[this._state.addressV];
const glWrapR = WebGLWraps[this._state.addressW];
this._gpuSampler = {
glMinFilter,
+7
View File
@@ -5,6 +5,10 @@ import { WebGLCmdFuncCreateTexture, WebGLCmdFuncDestroyTexture } from './webgl-c
import { WebGLGFXDevice } from './webgl-device';
import { WebGLGPUTexture } from './webgl-gpu-objects';
function IsPowerOf2 (x: number): boolean{
return x > 0 && (x & (x - 1)) === 0;
}
export class WebGLGFXTexture extends GFXTexture {
public get gpuTexture (): WebGLGPUTexture {
@@ -41,6 +45,8 @@ export class WebGLGFXTexture extends GFXTexture {
this._flags = info.flags;
}
this._isPowerOf2 = IsPowerOf2(this._width) && IsPowerOf2(this._height);
this._size = GFXFormatSurfaceSize(this._format, this.width, this.height,
this.depth, this.mipLevel) * this._arrayLayer;
@@ -101,6 +107,7 @@ export class WebGLGFXTexture extends GFXTexture {
arrayLayer: Math.max(info.arrayLayer || 1, 1),
mipLevel: Math.max(info.mipLevel || 1, 1),
flags: info.flags || GFXTextureFlagBit.NONE,
isPowerOf2: this._isPowerOf2,
glTarget: 0,
glInternelFmt: 0,
+1 -1
View File
@@ -749,7 +749,7 @@ interface WebGL2RenderingContextBase {
compressedTexImage3D(target: GLenum, level: GLint, internalformat: GLenum, width: GLsizei, height: GLsizei, depth: GLsizei, border: GLint, imageSize: GLsizei, offset: GLintptr);
compressedTexImage3D(target: GLenum, level: GLint, internalformat: GLenum, width: GLsizei, height: GLsizei, depth: GLsizei, border: GLint, srcData: ArrayBufferView, srcOffset?: GLuint, srcLengthOverride?: GLuint);
ompressedTexSubImage2D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, imageSize: GLsizei, offset: GLintptr);
compressedTexSubImage2D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, imageSize: GLsizei, offset: GLintptr);
compressedTexSubImage2D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, srcData: ArrayBufferView, srcOffset?: GLuint, srcLengthOverride?: GLuint);
compressedTexSubImage3D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, zoffset: GLint, width: GLsizei, height: GLsizei, depth: GLsizei, format: GLenum, imageSize: GLsizei, offset: GLintptr);
compressedTexSubImage3D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, zoffset: GLint, width: GLsizei, height: GLsizei, depth: GLsizei, format: GLenum, srcData: ArrayBufferView, srcOffset?: GLuint, srcLengthOverride?: GLuint);
+156 -100
View File
@@ -956,6 +956,23 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2GFXDevice, gpuTexture:
h = Math.max(1, h >> 1);
}
}
/*
if (gpuTexture.isPowerOf2) {
gpuTexture.glWrapS = WebGL2RenderingContext.REPEAT;
gpuTexture.glWrapT = WebGL2RenderingContext.REPEAT;
} else {
gpuTexture.glWrapS = WebGL2RenderingContext.CLAMP_TO_EDGE;
gpuTexture.glWrapT = WebGL2RenderingContext.CLAMP_TO_EDGE;
}
gpuTexture.glMinFilter = WebGL2RenderingContext.LINEAR;
gpuTexture.glMagFilter = WebGL2RenderingContext.LINEAR;
gl.texParameteri(gpuTexture.glTarget, WebGL2RenderingContext.TEXTURE_WRAP_S, gpuTexture.glWrapS);
gl.texParameteri(gpuTexture.glTarget, WebGL2RenderingContext.TEXTURE_WRAP_T, gpuTexture.glWrapT);
gl.texParameteri(gpuTexture.glTarget, WebGL2RenderingContext.TEXTURE_MIN_FILTER, gpuTexture.glMinFilter);
gl.texParameteri(gpuTexture.glTarget, WebGL2RenderingContext.TEXTURE_MAG_FILTER, gpuTexture.glMagFilter);
*/
}
break;
}
@@ -996,6 +1013,23 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2GFXDevice, gpuTexture:
}
}
}
/*
if (gpuTexture.isPowerOf2) {
gpuTexture.glWrapS = WebGL2RenderingContext.REPEAT;
gpuTexture.glWrapT = WebGL2RenderingContext.REPEAT;
} else {
gpuTexture.glWrapS = WebGL2RenderingContext.CLAMP_TO_EDGE;
gpuTexture.glWrapT = WebGL2RenderingContext.CLAMP_TO_EDGE;
}
gpuTexture.glMinFilter = WebGL2RenderingContext.LINEAR;
gpuTexture.glMagFilter = WebGL2RenderingContext.LINEAR;
gl.texParameteri(gpuTexture.glTarget, WebGL2RenderingContext.TEXTURE_WRAP_S, gpuTexture.glWrapS);
gl.texParameteri(gpuTexture.glTarget, WebGL2RenderingContext.TEXTURE_WRAP_T, gpuTexture.glWrapT);
gl.texParameteri(gpuTexture.glTarget, WebGL2RenderingContext.TEXTURE_MIN_FILTER, gpuTexture.glMinFilter);
gl.texParameteri(gpuTexture.glTarget, WebGL2RenderingContext.TEXTURE_MAG_FILTER, gpuTexture.glMagFilter);
*/
}
break;
}
@@ -1482,6 +1516,8 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2GFXDevice, cmdPackage: W
let gpuShader: WebGL2GPUShader | null = null;
let gpuInputAssembler: IWebGL2GPUInputAssembler | null = null;
let glPrimitive = WebGL2RenderingContext.TRIANGLES;
let glWrapS;
let glWrapT;
for (let i = 0; i < cmdPackage.cmds.length; ++i) {
const cmd = cmdPackage.cmds.array[i];
@@ -1979,6 +2015,15 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2GFXDevice, cmdPackage: W
}
}
const gpuSampler = gpuBinding.gpuSampler;
if (gpuTexture.isPowerOf2) {
glWrapS = gpuSampler.glWrapS;
glWrapT = gpuSampler.glWrapT;
} else {
glWrapS = WebGLRenderingContext.CLAMP_TO_EDGE;
glWrapT = WebGLRenderingContext.CLAMP_TO_EDGE;
}
if (cache.glSamplerUnits[texUnit] !== gpuBinding.gpuSampler.glSampler) {
gl.bindSampler(texUnit, gpuBinding.gpuSampler.glSampler);
cache.glSamplerUnits[texUnit] = gpuBinding.gpuSampler.glSampler;
@@ -2313,9 +2358,9 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2GFXDevice, cmdPackage: W
}
case WebGL2Cmd.COPY_BUFFER_TO_TEXTURE: {
const cmd5 = cmdPackage.copyBufferToTextureCmds.array[cmdId];
WebGL2CmdFuncCopyBufferToTexture(
WebGL2CmdFuncCopyBuffersToTexture(
device,
(cmd5.gpuBuffer as WebGL2GPUBuffer).buffer as GFXBufferSource,
[(cmd5.gpuBuffer as WebGL2GPUBuffer).buffer!],
cmd5.gpuTexture as WebGL2GPUTexture,
cmd5.regions);
@@ -2325,22 +2370,16 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2GFXDevice, cmdPackage: W
} // for
}
export function WebGL2CmdFuncCopyBufferToTexture (
export function WebGL2CmdFuncCopyTexImagesToTexture (
device: WebGL2GFXDevice,
buffer: GFXBufferSource,
texImages: TexImageSource[],
gpuTexture: WebGL2GPUTexture,
regions: GFXBufferTextureCopy[]) {
const gl = device.gl;
const buff = buffer as ArrayBuffer;
const fmtInfo: IGFXFormatInfo = GFXFormatInfos[gpuTexture.format];
let m = 0;
let w = 1;
let h = 1;
let n = 0;
let f = 0;
let buffOffset = 0;
switch (gpuTexture.glTarget) {
case WebGL2RenderingContext.TEXTURE_2D: {
const glTexUnit = device.stateCache.glTex2DUnits[device.stateCache.texUnit];
@@ -2349,48 +2388,12 @@ export function WebGL2CmdFuncCopyBufferToTexture (
glTexUnit.glTexture = gpuTexture.glTexture;
}
const isCompressed = GFXFormatInfos[gpuTexture.format].isCompressed;
if (!isCompressed) {
for (const region of regions) {
buffOffset = region.buffOffset + region.buffTexHeight * region.buffStride;
w = region.texExtent.width;
h = region.texExtent.height;
for (m = region.texSubres.baseMipLevel; m < region.texSubres.levelCount; ++m) {
const memSize = GFXFormatSize(gpuTexture.format, w, h, 1);
const data = buff.slice(buffOffset, buffOffset + memSize);
const pixels = !fmtInfo.isFloating ? new Uint8Array(data) : new Float32Array(data);
gl.texSubImage2D(WebGL2RenderingContext.TEXTURE_2D, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, gpuTexture.glType, pixels);
buffOffset += memSize;
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
}
} else {
for (const region of regions) {
buffOffset = region.buffOffset + region.buffTexHeight * region.buffStride;
w = region.texExtent.width;
h = region.texExtent.height;
for (m = region.texSubres.baseMipLevel; m < region.texSubres.levelCount; ++m) {
const memSize = GFXFormatSize(gpuTexture.format, w, h, 1);
const data = buff.slice(buffOffset, buffOffset + memSize);
const pixels = !fmtInfo.isFloating ? new Uint8Array(data) : new Float32Array(data);
gl.compressedTexSubImage2D(WebGL2RenderingContext.TEXTURE_2D, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, pixels);
buffOffset += memSize;
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
for (const region of regions) {
n = 0;
for (m = region.texSubres.baseMipLevel; m < region.texSubres.levelCount; ++m) {
gl.texSubImage2D(WebGL2RenderingContext.TEXTURE_2D, m,
region.texOffset.x, region.texOffset.y,
gpuTexture.glFormat, gpuTexture.glType, texImages[n++]);
}
}
break;
@@ -2402,53 +2405,106 @@ export function WebGL2CmdFuncCopyBufferToTexture (
glTexUnit.glTexture = gpuTexture.glTexture;
}
const isCompressed = GFXFormatInfos[gpuTexture.format].isCompressed;
if (!isCompressed) {
for (const region of regions) {
buffOffset = region.buffOffset + region.buffTexHeight * region.buffStride;
const fcount = region.texSubres.baseArrayLayer + region.texSubres.layerCount;
for (f = region.texSubres.baseArrayLayer; f < fcount; ++f) {
w = region.texExtent.width;
h = region.texExtent.height;
const mcount = region.texSubres.baseMipLevel + region.texSubres.levelCount;
for (m = region.texSubres.baseMipLevel; m < mcount; ++m) {
const memSize = GFXFormatSize(gpuTexture.format, w, h, 1);
const data = buff.slice(buffOffset, buffOffset + memSize);
const pixels = !fmtInfo.isFloating ? new Uint8Array(data) : new Float32Array(data);
gl.texSubImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, gpuTexture.glType, pixels);
buffOffset += memSize;
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
}
}
} else {
for (const region of regions) {
buffOffset = region.buffOffset + region.buffTexHeight * region.buffStride;
const fcount = region.texSubres.baseArrayLayer + region.texSubres.layerCount;
for (f = region.texSubres.baseArrayLayer; f < fcount; ++f) {
w = region.texExtent.width;
h = region.texExtent.height;
const mcount = region.texSubres.baseMipLevel + region.texSubres.levelCount;
for (m = region.texSubres.baseMipLevel; m < mcount; ++m) {
const memSize = GFXFormatSize(gpuTexture.format, w, h, 1);
const data = buff.slice(buffOffset, buffOffset + memSize);
const pixels = !fmtInfo.isFloating ? new Uint8Array(data) : new Float32Array(data);
gl.compressedTexSubImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, pixels);
buffOffset += memSize;
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
for (const region of regions) {
n = 0;
const fcount = region.texSubres.baseArrayLayer + region.texSubres.layerCount;
for (f = region.texSubres.baseArrayLayer; f < fcount; ++f) {
const mcount = region.texSubres.baseMipLevel + region.texSubres.levelCount;
for (m = region.texSubres.baseMipLevel; m < mcount; ++m) {
gl.texSubImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, m,
region.texOffset.x, region.texOffset.y,
gpuTexture.glFormat, gpuTexture.glType, texImages[n++]);
}
}
}
break;
}
default: {
console.error('Unsupported GL texture type, copy buffer to texture failed.');
}
}
if (gpuTexture.flags & GFXTextureFlagBit.GEN_MIPMAP) {
gl.generateMipmap(gpuTexture.glTarget);
}
}
export function WebGL2CmdFuncCopyBuffersToTexture (
device: WebGL2GFXDevice,
buffers: ArrayBuffer[],
gpuTexture: WebGL2GPUTexture,
regions: GFXBufferTextureCopy[]) {
const gl = device.gl;
let m = 0;
let n = 0;
let w = 1;
let h = 1;
let f = 0;
const fmtInfo: IGFXFormatInfo = GFXFormatInfos[gpuTexture.format];
const isCompressed = fmtInfo.isCompressed;
switch (gpuTexture.glTarget) {
case WebGL2RenderingContext.TEXTURE_2D: {
const glTexUnit = device.stateCache.glTex2DUnits[device.stateCache.texUnit];
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
gl.bindTexture(WebGL2RenderingContext.TEXTURE_2D, gpuTexture.glTexture);
glTexUnit.glTexture = gpuTexture.glTexture;
}
for (const region of regions) {
n = 0;
w = region.texExtent.width;
h = region.texExtent.height;
for (m = region.texSubres.baseMipLevel; m < region.texSubres.levelCount; ++m) {
const pixels = !fmtInfo.isFloating ? new Uint8Array(buffers[n++]) : new Float32Array(buffers[n++]);
if (!isCompressed) {
gl.texSubImage2D(WebGL2RenderingContext.TEXTURE_2D, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, gpuTexture.glType, pixels);
} else {
gl.compressedTexSubImage2D(WebGL2RenderingContext.TEXTURE_2D, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, pixels);
}
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
}
break;
}
case WebGL2RenderingContext.TEXTURE_CUBE_MAP: {
const glTexUnit = device.stateCache.glTexCubeUnits[device.stateCache.texUnit];
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
gl.bindTexture(WebGL2RenderingContext.TEXTURE_CUBE_MAP, gpuTexture.glTexture);
glTexUnit.glTexture = gpuTexture.glTexture;
}
for (const region of regions) {
n = 0;
const fcount = region.texSubres.baseArrayLayer + region.texSubres.layerCount;
for (f = region.texSubres.baseArrayLayer; f < fcount; ++f) {
w = region.texExtent.width;
h = region.texExtent.height;
const mcount = region.texSubres.baseMipLevel + region.texSubres.levelCount;
for (m = region.texSubres.baseMipLevel; m < mcount; ++m) {
const pixels = !fmtInfo.isFloating ? new Uint8Array(buffers[n++]) : new Float32Array(buffers[n++]);
if (!isCompressed) {
gl.texSubImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, gpuTexture.glType, pixels);
} else {
gl.compressedTexSubImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, m,
region.texOffset.x, region.texOffset.y, w, h,
gpuTexture.glFormat, pixels);
}
w = Math.max(1, w >> 1);
h = Math.max(1, w >> 1);
}
}
}
+8 -35
View File
@@ -20,7 +20,7 @@ import { WebGL2GFXBindingLayout } from './webgl2-binding-layout';
import { WebGL2GFXBuffer } from './webgl2-buffer';
import { WebGL2GFXCommandAllocator } from './webgl2-command-allocator';
import { WebGL2GFXCommandBuffer } from './webgl2-command-buffer';
import { WebGL2CmdFuncCopyBufferToTexture } from './webgl2-commands';
import { WebGL2CmdFuncCopyTexImagesToTexture, WebGL2CmdFuncCopyBuffersToTexture } from './webgl2-commands';
import { WebGL2GFXFramebuffer } from './webgl2-framebuffer';
import { WebGL2GFXInputAssembler } from './webgl2-input-assembler';
import { WebGL2GFXPipelineLayout } from './webgl2-pipeline-layout';
@@ -382,49 +382,22 @@ export class WebGL2GFXDevice extends GFXDevice {
(this._cmdAllocator as WebGL2GFXCommandAllocator).releaseCmds();
}
public copyBufferToTexture (buffer: ArrayBuffer, texture: GFXTexture, regions: GFXBufferTextureCopy[]) {
WebGL2CmdFuncCopyBufferToTexture(
public copyBuffersToTexture (buffers: ArrayBuffer[], texture: GFXTexture, regions: GFXBufferTextureCopy[]) {
WebGL2CmdFuncCopyBuffersToTexture(
this,
buffer,
buffers,
(texture as WebGL2GFXTexture).gpuTexture,
regions);
}
public copyImageSourceToTexture (
source: CanvasImageSource[],
public copyTexImagesToTexture (
texImages: TexImageSource[],
texture: GFXTexture,
regions: GFXBufferTextureCopy[]) {
if (!this._canvas2D) { return; }
const context = this._canvas2D.getContext('2d');
if (!context) { return; }
const data: Uint8ClampedArray[] = [];
const faces = source.length / regions.length;
let imgSrc: CanvasImageSource;
for (let j = 0; j < regions.length; j++) {
for (let i = 0; i < faces; i++) {
const level = regions[j].texSubres.baseMipLevel;
this._canvas2D.width = texture.width >> level;
this._canvas2D.height = texture.height >> level;
imgSrc = source[j * faces + i];
if (imgSrc.width <= 0 || imgSrc.height <= 0) {
return ;
}
context.drawImage(imgSrc, 0, 0);
data.push(context.getImageData(0, 0, this._canvas2D.width, this._canvas2D.height).data);
}
}
const buffer = new Uint8ClampedArray(data.reduce((acc, cur) => acc + cur.length, 0));
data.reduce((acc, cur) => { buffer.set(cur, acc); return acc + cur.length; }, 0);
WebGL2CmdFuncCopyBufferToTexture(
WebGL2CmdFuncCopyTexImagesToTexture(
this,
buffer,
texImages,
(texture as WebGL2GFXTexture).gpuTexture,
regions);
}
+1
View File
@@ -56,6 +56,7 @@ export class WebGL2GPUTexture {
public arrayLayer: number = 1;
public mipLevel: number = 1;
public flags: GFXTextureFlags = GFXTextureFlagBit.NONE;
public isPowerOf2: boolean = false;
public glTarget: GLenum = 0;
public glInternelFmt: GLenum = 0;
+7
View File
@@ -5,6 +5,10 @@ import { WebGL2CmdFuncCreateTexture, WebGL2CmdFuncDestroyTexture } from './webgl
import { WebGL2GFXDevice } from './webgl2-device';
import { WebGL2GPUTexture } from './webgl2-gpu-objects';
function IsPowerOf2 (x: number): boolean{
return x > 0 && (x & (x - 1)) === 0;
}
export class WebGL2GFXTexture extends GFXTexture {
public get gpuTexture (): WebGL2GPUTexture {
@@ -41,6 +45,8 @@ export class WebGL2GFXTexture extends GFXTexture {
this._flags = info.flags;
}
this._isPowerOf2 = IsPowerOf2(this._width) && IsPowerOf2(this._height);
this._size = GFXFormatSurfaceSize(this._format, this.width, this.height,
this.depth, this.mipLevel) * this._arrayLayer;
@@ -101,6 +107,7 @@ export class WebGL2GFXTexture extends GFXTexture {
arrayLayer: Math.max(info.arrayLayer || 1, 1),
mipLevel: Math.max(info.mipLevel || 1, 1),
flags: info.flags || GFXTextureFlagBit.NONE,
isPowerOf2: this._isPowerOf2,
glTarget: 0,
glInternelFmt: 0,
+2 -2
View File
@@ -181,7 +181,7 @@ export class ForwardPipeline extends RenderPipeline {
_vec4Array[1] *= tempRGB.y;
_vec4Array[2] *= tempRGB.z;
}
_vec4Array[3] = (light as SphereLight).luminance;
_vec4Array[3] = (light as SphereLight).luminance * 10000.0;
this._uboLights.view.set(_vec4Array, UBOForwardLight.SPHERE_LIGHT_COLOR_OFFSET + sphereNum * 4);
sphereNum++;
break;
@@ -204,7 +204,7 @@ export class ForwardPipeline extends RenderPipeline {
_vec4Array[1] *= tempRGB.y;
_vec4Array[2] *= tempRGB.z;
}
_vec4Array[3] = (light as SpotLight).luminance;
_vec4Array[3] = (light as SpotLight).luminance * 10000.0;
this._uboLights.view.set(_vec4Array, UBOForwardLight.SPOT_LIGHT_COLOR_OFFSET + spotNum * 4);
spotNum++;
break;
+3 -2
View File
@@ -8,10 +8,11 @@ import { GFXBuffer } from '../../gfx/buffer';
import { GFXBufferUsageBit, GFXMemoryUsageBit } from '../../gfx/define';
import { GFXFeature } from '../../gfx/device';
import { GFXPipelineState } from '../../gfx/pipeline-state';
import { UBOSkinning, UNIFORM_JOINTS_TEXTURE } from '../../pipeline/define';
import { Node } from '../../scene-graph/node';
import { samplerLib } from '../core/sampler-lib';
import { Model } from '../scene/model';
import { RenderScene } from '../scene/render-scene';
import { UBOSkinning, UNIFORM_JOINTS_TEXTURE } from '../../pipeline/define';
const textureSizeBuffer = new Float32Array(4);
@@ -94,7 +95,7 @@ export class SkinningModel extends Model {
if (this._jointStorage && isTextureStorage(this._jointStorage)) {
const jointTexture = this._jointStorage.texture;
const view = jointTexture.getGFXTextureView();
const sampler = jointTexture.getGFXSampler();
const sampler = samplerLib.getSampler(this._device, jointTexture.getGFXSamplerInfo());
if (view && sampler) {
pso.pipelineLayout.layouts[0].bindTextureView(UNIFORM_JOINTS_TEXTURE.binding, view);
pso.pipelineLayout.layouts[0].bindSampler(UNIFORM_JOINTS_TEXTURE.binding, sampler);
+4 -4
View File
@@ -29,7 +29,7 @@ export class SphereLight extends Light {
set luminance (lum: number) {
this._luminance = lum;
this._luminousPower = this._luminance * 4.0 * Math.PI;
this._luminousPower = this._luminance * (4.0 * this._size * this._size * Math.PI * Math.PI);
}
get luminance (): number {
@@ -38,7 +38,7 @@ export class SphereLight extends Light {
set luminousPower (lm: number) {
this._luminousPower = lm;
this._luminance = this._luminousPower / 4.0 / Math.PI;
this._luminance = this._luminousPower / (4.0 * this._size * this._size * Math.PI * Math.PI);
}
get luminousPower (): number {
@@ -51,7 +51,7 @@ export class SphereLight extends Light {
protected _size: number = 0.15;
protected _range: number = 1.0;
protected _luminance: number = 10000.0;
protected _luminance: number = 0.0;
protected _luminousPower: number = 0.0;
protected _pos: Vec3;
protected _aabb: aabb;
@@ -59,7 +59,7 @@ export class SphereLight extends Light {
constructor (scene: RenderScene, name: string, node: Node) {
super(scene, name, node);
this._type = LightType.SPHERE;
this._luminousPower = this._luminance * 4.0 * Math.PI;
this.luminousPower = 1700.0;
this._aabb = aabb.create();
this._pos = v3();
}
+3 -3
View File
@@ -48,7 +48,7 @@ export class SpotLight extends Light {
set luminance (lum: number) {
this._luminance = lum;
this._luminousPower = this._luminance * 4.0 * Math.PI;
this._luminousPower = this._luminance * (4.0 * this._size * this._size * Math.PI * Math.PI);
}
get luminance (): number {
@@ -57,7 +57,7 @@ export class SpotLight extends Light {
set luminousPower (lm: number) {
this._luminousPower = lm;
this._luminance = this._luminousPower / 4.0 / Math.PI;
this._luminance = this._luminousPower / (4.0 * this._size * this._size * Math.PI * Math.PI);
}
get luminousPower (): number {
@@ -88,7 +88,7 @@ export class SpotLight extends Light {
constructor (scene: RenderScene, name: string, node: Node) {
super(scene, name, node);
this._type = LightType.SPOT;
this._luminousPower = this._luminance * 4.0 * Math.PI;
this.luminousPower = 1700.0;
this._aabb = aabb.create();
this._frustum = frustum.create();
this._pos = v3();
+34 -30
View File
@@ -31,6 +31,7 @@ import { EventType } from '../core/platform/event-manager/event-enum';
import IdGenerator from '../core/utils/id-generator';
import * as js from '../core/utils/js';
import { baseNodePolyfill } from './base-node-dev';
import { Scene } from './scene';
type Constructor<T = {}> = new (...args: any[]) => T;
@@ -46,6 +47,8 @@ const Deactivating = CCObject.Flags.Deactivating;
const idGenerator = new IdGenerator('Node');
const NullScene = null as unknown as Scene;
function getConstructor (typeOrClassName: string | Function): Function | null {
if (!typeOrClassName) {
cc.errorID(3804);
@@ -219,9 +222,13 @@ export class BaseNode extends CCObject {
this.setParent(value);
}
get scene () {
return this._scene;
}
public static _setScene (node: BaseNode) {
if (node instanceof cc.Scene) {
node._scene = node;
node._scene = node as Scene;
} else {
if (node._parent == null) {
cc.error('Node %s(%s) has not attached to a scene.', node.name, node.uuid);
@@ -330,7 +337,7 @@ export class BaseNode extends CCObject {
* !#zh 此节点属于哪个场景。
* @type {cc.Scene}}
*/
protected _scene: any = null;
protected _scene: Scene = NullScene;
protected _activeInHierarchy = false;
@@ -345,10 +352,6 @@ export class BaseNode extends CCObject {
*/
protected __eventTargets: any[] = [];
get scene () {
return this._scene;
}
/**
* @method constructor
* @param {String} [name]
@@ -378,7 +381,7 @@ export class BaseNode extends CCObject {
* @example
* node.setParent(newNode);
*/
public setParent (value: this | null) {
public setParent (value: this | null, keepWorldTransform: boolean) {
if (this._parent === value) {
return;
}
@@ -386,9 +389,10 @@ export class BaseNode extends CCObject {
if (CC_DEBUG && oldParent && (oldParent._objFlags & Deactivating)) {
cc.errorID(3821);
}
this._parent = value || null;
this._onSetParent(oldParent);
this._parent = value;
this._onSetParent(oldParent, keepWorldTransform);
if (value) {
if (CC_DEBUG && (value._objFlags & Deactivating)) {
@@ -1067,7 +1071,27 @@ export class BaseNode extends CCObject {
public emit? (type: string, ...args: any[]): void;
protected _onSetParent (oldParent: this | null) {
// Do remove component, only used internally.
public _removeComponent (component: Component) {
if (!component) {
cc.errorID(3814);
return;
}
if (!(this._objFlags & Destroying)) {
const i = this._components.indexOf(component);
if (i !== -1) {
this._components.splice(i, 1);
if ((CC_EDITOR || CC_TEST) && cc.engine) {
delete cc.engine.attachedObjsForEditor[component._id];
}
} else if ((component.node as BaseNode) !== this) {
cc.errorID(3815);
}
}
}
protected _onSetParent (oldParent: this | null, keepWorldTransform: boolean) {
if (this._parent) {
if ((oldParent == null || oldParent._scene !== this._parent._scene) && this._parent._scene != null) {
this.walk((node) => {
@@ -1230,26 +1254,6 @@ export class BaseNode extends CCObject {
return destroyByParent;
}
// do remove component, only used internally
protected _removeComponent (component: Component) {
if (!component) {
cc.errorID(3814);
return;
}
if (!(this._objFlags & Destroying)) {
const i = this._components.indexOf(component);
if (i !== -1) {
this._components.splice(i, 1);
if ((CC_EDITOR || CC_TEST) && cc.engine) {
delete cc.engine.attachedObjsForEditor[component._id];
}
} else if ((component.node as BaseNode) !== this) {
cc.errorID(3815);
}
}
}
protected _disableChildComps () {
// leave this._activeInHierarchy unmodified
for (const component of this._components) {
+30 -3
View File
@@ -141,10 +141,37 @@ class Node extends BaseNode {
// ===============================
/**
* invalidate all children after relevant events
* hierarchical events
*/
public _onSetParent (oldParent: this) {
super._onSetParent(oldParent);
public setParent (value: this | null, keepWorldTransform: boolean = false) {
if (keepWorldTransform) { this.updateWorldTransform(); }
super.setParent(value, keepWorldTransform);
}
public _onSetParent (oldParent: this | null, keepWorldTransform: boolean) {
super._onSetParent(oldParent, keepWorldTransform);
if (keepWorldTransform) {
const parent = this._parent;
const local = this._lpos;
if (parent) {
parent.updateWorldTransform();
vec3.sub(local, this._pos, parent._pos);
vec3.transformQuat(local, local, quat.conjugate(q_a, parent._rot));
vec3.div(local, local, parent._scale);
quat.mul(this._lrot, quat.conjugate(q_a, parent._rot), this._rot);
vec3.div(this._lscale, this._scale, parent._scale);
} else {
vec3.copy(this._lpos, this._pos);
quat.copy(this._lrot, this._rot);
vec3.copy(this._lscale, this._scale);
}
this._eulerDirty = true;
} else {
vec3.copy(this._pos, this._lpos);
quat.copy(this._rot, this._lrot);
vec3.copy(this._scale, this._lscale);
}
this.invalidateChildren();
}
+5 -2
View File
@@ -54,7 +54,10 @@ export class Scene extends Node {
@property
public _globals = new SceneGlobals();
protected _renderScene: RenderScene | null = null;
/**
* For internal usage.
*/
public _renderScene: RenderScene | null = null;
protected _inited = !cc.game._isCloning;
protected _prefabSyncedInLiveReload = false;
@@ -82,7 +85,7 @@ export class Scene extends Node {
return this._globals;
}
protected _onHierarchyChanged () { }
public _onHierarchyChanged () { }
protected _instantiate () { }
protected _load () {
+1
View File
@@ -104,6 +104,7 @@
models.plane.node.setRotation(qt);
scene.globals.planarShadow.setPlaneFromNode(models.plane.node);
scene.globals.planarShadow.shadowColor = cc.color('#2a4e90');
// material.setProperty('matLightPlaneProj', getLightPlaneProj(cc.v3(-10, altitude + 10, -10), // light
// cc.geometry.plane.create(nm.x, nm.y, nm.z, cc.vmath.vec3.dot(nm, models.plane.node.getWorldPosition()))));
+12
View File
@@ -59,6 +59,7 @@
const root = cc.director.root;
const scene = new cc.Scene();
const cameraNode = new cc.Node('Camera');
cameraNode.parent = scene;
cameraNode.setPosition(1, 1, 4);
@@ -161,6 +162,17 @@
});
});
const n0 = new cc.Node();
n0.parent = scene;
n0.setWorldPosition(0, 0, 10);
const n1 = new cc.Node();
n1.parent = n0;
console.log(n1.getPosition());
console.log(n1.getWorldPosition());
n1.parent = scene;
console.log(n1.getPosition());
console.log(n1.getWorldPosition());
cc.director.runSceneImmediate(scene);
}
cc.game.run({ id: 'canvas' }, onStart);
+7 -14
View File
@@ -12,8 +12,7 @@
"emitDeclarationOnly": true,
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"outFile": "./bin/ts-out/cocos-3d.js", /* Concatenate and emit output to single file. */
"outDir": "./bin/ts-out", /* Redirect output structure to the directory. */
"outFile": "index.js", /* Concatenate and emit output to single file. */
"rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
@@ -44,7 +43,12 @@
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"types": [
"./@types/globals",
"./@types/ammo.js",
"./@types/wx",
"./cocos/gfx/webgl2/WebGL2",
], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
@@ -61,16 +65,5 @@
},
"files": [
"index.ts",
"globals.d.ts",
"wx.d.ts",
"cocos/gfx/webgl2/WebGL2.d.ts",
"cocos/core/vmath/fwd-decls.d.ts",
],
"exclude": [
"cocos/2d",
"docs",
"bin"
]
//"include" : ["./source"]
//"exclude" : ["js"]
}
+6 -1
View File
@@ -43,7 +43,12 @@
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"types": [
"./@types/globals",
"./@types/ammo.js",
"./@types/wx",
"./cocos/gfx/webgl2/WebGL2",
], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */