Merge pull request #34 from YunHsiao/gfx

node from component
This commit is contained in:
Weiliang Wang
2019-01-10 20:39:10 +08:00
committed by GitHub
17 changed files with 122 additions and 148 deletions
@@ -22,17 +22,12 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
// @ts-check
import { toRadian, color4 } from '../../core/vmath';
import { ccclass, menu, property, executeInEditMode } from "../../core/data/class-decorator";
import { Enum, Rect } from '../../core/value-types';
import { Component } from '../../components/component';
import { CameraProjection } from '../../renderer/scene/camera';
import { ccclass, executeInEditMode, menu, property } from '../../core/data/class-decorator';
import { Enum, Rect } from '../../core/value-types';
import { color4, toRadian } from '../../core/vmath';
import { GFXClearFlag } from '../../gfx/define';
/**
* @typedef {import('../../core/value-types/index').Color} Color
*/
import { Camera, CameraProjection } from '../../renderer/scene/camera';
/**
* !#en The light source type
@@ -41,7 +36,7 @@ import { GFXClearFlag } from '../../gfx/define';
* @static
* @enum CameraComponent.Projection
*/
let ProjectionType = Enum({
const ProjectionType = Enum({
/**
* !#en The orthogonal camera
*
@@ -59,14 +54,14 @@ let ProjectionType = Enum({
* @readonly
* @type {Number}
*/
PERSPECTIVE: 1
PERSPECTIVE: 1,
});
let CameraClearFlag = Enum({
const CameraClearFlag = Enum({
SKYBOX: GFXClearFlag.SKYBOX | GFXClearFlag.DEPTH | GFXClearFlag.STENCIL,
SOLID_COLOR: GFXClearFlag.COLOR | GFXClearFlag.DEPTH | GFXClearFlag.STENCIL,
DEPTH_ONLY: GFXClearFlag.DEPTH | GFXClearFlag.STENCIL,
DONT_CLEAR: 0
DONT_CLEAR: 0,
});
/**
@@ -79,39 +74,37 @@ let CameraClearFlag = Enum({
@ccclass('cc.CameraComponent')
@menu('Components/CameraComponent')
@executeInEditMode
export default class CameraComponent extends Component {
@property
_projection = ProjectionType.PERSPECTIVE;
export class CameraComponent extends Component {
public static ProjectionType = ProjectionType;
@property
_priority = 0;
protected _projection = ProjectionType.PERSPECTIVE;
@property
_fov = 45;
protected _priority = 0;
@property
_orthoHeight = 10;
protected _fov = 45;
@property
_near = 0.01;
protected _orthoHeight = 10;
@property
_far = 1000.0;
protected _near = 0.01;
@property
_color = cc.color('#334C78');
protected _far = 1000.0;
@property
_depth = 1;
protected _color = cc.color('#334C78');
@property
_stencil = 0;
protected _depth = 1;
@property
_clearFlags = CameraClearFlag.SOLID_COLOR;
protected _stencil = 0;
@property
_rect = new Rect(0, 0, 1, 1);
protected _clearFlags = CameraClearFlag.SOLID_COLOR;
@property
protected _rect = new Rect(0, 0, 1, 1);
protected _camera: Camera | null = null;
constructor () {
super();
}
/**
* !#en The projection type of the camera
@@ -120,20 +113,20 @@ export default class CameraComponent extends Component {
* @type {Number}
*/
@property({
type: ProjectionType
type: ProjectionType,
})
get projection() {
get projection () {
return this._projection;
}
set projection(val) {
set projection (val) {
this._projection = val;
let type = CameraProjection.PERSPECTIVE;
if (this._projection === ProjectionType.ORTHO) {
type = CameraProjection.ORTHO;
}
if (this.enabled) this._camera.projectionType = type;
if (this._camera) { this._camera.projectionType = type; }
}
/**
@@ -143,13 +136,13 @@ export default class CameraComponent extends Component {
* @type {Number}
*/
@property
get fov() {
get fov () {
return this._fov;
}
set fov(val) {
set fov (val) {
this._fov = val;
if (this.enabled) this._camera.fov = toRadian(val);
if (this._camera) { this._camera.fov = toRadian(val); }
}
/**
@@ -159,13 +152,13 @@ export default class CameraComponent extends Component {
* @type {Number}
*/
@property
get orthoHeight() {
get orthoHeight () {
return this._orthoHeight;
}
set orthoHeight(val) {
set orthoHeight (val) {
this._orthoHeight = val;
if (this.enabled) this._camera.orthoHeight = val;
if (this._camera) { this._camera.orthoHeight = val; }
}
/**
@@ -175,13 +168,13 @@ export default class CameraComponent extends Component {
* @type {Number}
*/
@property
get near() {
get near () {
return this._near;
}
set near(val) {
set near (val) {
this._near = val;
if (this.enabled) this._camera.nearClip =val;
if (this._camera) { this._camera.nearClip = val; }
}
/**
@@ -191,13 +184,13 @@ export default class CameraComponent extends Component {
* @type {Number}
*/
@property
get far() {
get far () {
return this._far;
}
set far(val) {
set far (val) {
this._far = val;
if (this.enabled) this._camera.farClip = val;
if (this._camera) { this._camera.farClip = val; }
}
/**
@@ -207,14 +200,15 @@ export default class CameraComponent extends Component {
* @type {Color}
*/
@property
get color() {
get color () {
return this._color;
}
set color(val) {
set color (val) {
this._color = val;
if (this.enabled) this._camera.clearColor =
if (this._camera) { this._camera.clearColor =
color4.create(val.r / 255, val.g / 255, val.b / 255, val.a / 255);
}
}
/**
@@ -224,14 +218,15 @@ export default class CameraComponent extends Component {
* @type {Number}
*/
@property
get depth() {
get depth () {
return this._depth;
}
set depth(val) {
set depth (val) {
this._depth = val;
if (this.enabled)
if (this._camera) {
this._camera.clearDepth = val;
}
}
/**
@@ -241,13 +236,13 @@ export default class CameraComponent extends Component {
* @type {Number}
*/
@property
get stencil() {
get stencil () {
return this._stencil;
}
set stencil(val) {
set stencil (val) {
this._stencil = val;
if (this.enabled) this._camera.clearStencil = val;
if (this._camera) { this._camera.clearStencil = val; }
}
/**
@@ -257,15 +252,15 @@ export default class CameraComponent extends Component {
* @type {Number}
*/
@property({
type: CameraClearFlag
type: CameraClearFlag,
})
get clearFlags() {
get clearFlags () {
return this._clearFlags;
}
set clearFlags(val) {
set clearFlags (val) {
this._clearFlags = val;
if (this.enabled) this._camera.clearFlag = val;
if (this._camera) { this._camera.clearFlag = val; }
}
/**
@@ -275,29 +270,23 @@ export default class CameraComponent extends Component {
* @type {Rect}
*/
@property
get rect() {
get rect () {
return this._rect;
}
set rect(val) {
set rect (val) {
this._rect = val;
if (this.enabled) this._camera.viewport = val;
if (this._camera) { this._camera.viewport = val; }
}
static Projection = CameraProjection;
constructor() {
super();
}
onLoad() {
public onLoad () {
}
onEnable() {
public onEnable () {
this._camera = this._getRenderScene().createCamera(this.name);
this._camera.node = this.node;
this.projection = this._projection;
this.priority = this._priority;
this.fov = this._fov;
this.orthoHeight = this._orthoHeight;
this.near = this._near;
@@ -307,14 +296,13 @@ export default class CameraComponent extends Component {
this.stencil = this._stencil;
this.clearFlags = this._clearFlags;
this.rect = this._rect;
this._camera.node = this.node;
}
onDisable() {
this._getRenderScene().destroyCamera(this._camera);
public onDisable () {
if (this._camera) { this._getRenderScene().destroyCamera(this._camera); }
}
onDestroy() {
public onDestroy () {
}
}
+1 -1
View File
@@ -24,7 +24,7 @@
THE SOFTWARE.
****************************************************************************/
import CameraComponent from './camera-component';
import { CameraComponent } from './camera-component';
import AnimationComponent from './animation-component';
import LightComponent from './light-component';
import ModelComponent from './model-component';
-7
View File
@@ -22,15 +22,11 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
// @ts-check
import Model from '../../renderer/scene/model';
import { ccclass, property, menu, executionOrder, executeInEditMode } from '../../core/data/class-decorator';
import { Mesh } from '../assets/mesh';
import Enum from '../../core/value-types/enum';
import RenderableComponent from './renderable-component';
/**
* @typedef {import('../assets/material').default} Material
*/
/**
* !#en Shadow projection mode
@@ -103,9 +99,6 @@ export default class ModelComponent extends RenderableComponent {
@property
_receiveShadows = false;
/**
* @type {Material}
*/
static _builtinMaterial = null;
/**
+10 -10
View File
@@ -39,14 +39,14 @@ export class Component extends CCObject {
public constructor();
_getRenderScene(index?: number): RenderScene | undefined;
addComponent(typeOrClassName: Function | string): Component;
getComponent(typeOrClassName: Function | string): Component;
getComponents(typeOrClassName: Function | string): Component[];
getComponentInChildren(typeOrClassName: Function | string): Component;
getComponentsInChildren(typeOrClassName: Function | string): Component[];
schedule(callback: Function, interval: number, repeat: number, delay: number): void;
scheduleOnce(callback: Function, delay: number): void;
unschedule(callback: Function): void;
unscheduleAllCallbacks(): void;
protected _getRenderScene(index?: number): RenderScene;
public addComponent(typeOrClassName: Function | string): Component;
public getComponent(typeOrClassName: Function | string): Component;
public getComponents(typeOrClassName: Function | string): Component[];
public getComponentInChildren(typeOrClassName: Function | string): Component;
public getComponentsInChildren(typeOrClassName: Function | string): Component[];
public schedule(callback: Function, interval: number, repeat: number, delay: number): void;
public scheduleOnce(callback: Function, delay: number): void;
public unschedule(callback: Function): void;
public unscheduleAllCallbacks(): void;
}
+2 -2
View File
@@ -25,8 +25,8 @@
****************************************************************************/
import { CCObject } from './object';
import ValueType from '../value-types/value-type';
import {isDomNode} from '../utils/misc';
import { ValueType } from '../value-types/value-type';
import { isDomNode } from '../utils/misc';
const Destroyed = CCObject.Flags.Destroyed;
const PersistentMask = CCObject.Flags.PersistentMask;
+1 -1
View File
@@ -24,7 +24,7 @@
THE SOFTWARE.
****************************************************************************/
import ValueType from './value-type';
import { ValueType } from './value-type';
import CCClass from '../data/class';
/**
+2 -2
View File
@@ -25,7 +25,7 @@
****************************************************************************/
export { default as Enum } from './enum';
export { default as ValueType } from './value-type';
export { ValueType } from './value-type';
export { default as Vec2} from './vec2';
export { default as Vec3} from './vec3';
export { default as Vec4} from './vec4';
@@ -34,4 +34,4 @@ export { default as Mat4} from './mat4';
export { default as AffineTransform} from './affine-transform';
export { default as Size} from './size';
export { default as Rect} from './rect';
export { default as Color} from './color';
export { default as Color} from './color';
+1 -1
View File
@@ -23,7 +23,7 @@
THE SOFTWARE.
****************************************************************************/
import ValueType from './value-type';
import { ValueType } from './value-type';
import CCClass from '../data/class';
import {mat4} from '../vmath';
+1 -1
View File
@@ -23,7 +23,7 @@
THE SOFTWARE.
****************************************************************************/
import ValueType from './value-type';
import { ValueType } from './value-type';
import CCClass from '../data/class';
import quat from '../vmath/quat';
+2 -2
View File
@@ -24,7 +24,7 @@
THE SOFTWARE.
****************************************************************************/
import ValueType from './value-type';
import { ValueType } from './value-type';
import CCClass from '../data/class';
/**
@@ -420,4 +420,4 @@ cc.Rect = Rect;
*/
cc.rect = function rect (x, y, w, h) {
return new Rect(x, y, w, h);
};
};
+1 -1
View File
@@ -24,7 +24,7 @@
THE SOFTWARE.
****************************************************************************/
import ValueType from './value-type';
import { ValueType } from './value-type';
import CCClass from '../data/class';
/**
@@ -32,26 +32,23 @@ import * as js from '../utils/js';
* @class ValueType
*
*/
export default class ValueType {
export class ValueType {
/**
* !#en This method returns an exact copy of current value.
* !#zh 克隆当前值,该方法返回一个新对象,新对象的值和原对象相等。
* @method clone
* @return {ValueType}
*/
clone () {
public clone (): this {
cc.errorID('0100', js.getClassName(this) + '.clone');
return null;
return this;
}
/**
* !#en Compares this object with the other one.
* !#zh 当前对象是否等于指定对象。
* @method equals
* @param {ValueType} other
* @return {Boolean}
* @param other
*/
equals (other) {
public equals (other: this) {
cc.errorID('0100', js.getClassName(this) + '.equals');
return false;
}
@@ -63,12 +60,11 @@ export default class ValueType {
* !#zh
* 线性插值。<br/>
* 当 ratio = 0 时返回自身,ratio = 1 时返回目标,ratio = 0.5 返回自身和目标的平均值。。
* @method lerp
* @param {ValueType} to - the to value
* @param {number} ratio - the interpolation coefficient
* @return {ValueType}
* @param to - the to value
* @param ratio - the interpolation coefficient
* @returns
*/
lerp (to, ratio) {
public lerp (to: this, ratio: this) {
cc.errorID('0100', js.getClassName(this) + '.lerp');
return this.clone();
}
@@ -78,20 +74,17 @@ export default class ValueType {
* Copys all the properties from another given object to this value.
* !#zh
* 从其它对象把所有属性复制到当前对象。
* @method set
* @param {ValueType} source - the source to copy
* @param source - the source to copy
*/
set (source) {
public set (source: this) {
cc.errorID('0100', js.getClassName(this) + '.set');
}
/**
* !#en TODO
* !#zh 转换为方便阅读的字符串。
* @method toString
* @return {string}
*/
toString () {
public toString () {
return '' + {};
}
}
+2 -2
View File
@@ -24,7 +24,7 @@
THE SOFTWARE.
****************************************************************************/
import ValueType from './value-type';
import { ValueType } from './value-type';
import CCClass from '../data/class';
import {vec2} from '../vmath';
import {clampf} from '../utils/misc';
@@ -664,4 +664,4 @@ cc.Vec2 = Vec2;
*/
cc.v2 = function v2 (x, y) {
return new Vec2(x, y);
};
};
+2 -2
View File
@@ -24,7 +24,7 @@
THE SOFTWARE.
****************************************************************************/
import ValueType from './value-type';
import { ValueType } from './value-type';
import CCClass from '../data/class';
import {vec3} from '../vmath';
import {clampf} from '../utils/misc';
@@ -469,4 +469,4 @@ cc.Vec3 = Vec3;
*/
cc.v3 = function v3 (x, y, z) {
return new Vec3(x, y, z);
};
};
+2 -2
View File
@@ -24,7 +24,7 @@
THE SOFTWARE.
****************************************************************************/
import ValueType from './value-type';
import { ValueType } from './value-type';
import CCClass from '../data/class';
import {vec4} from '../vmath';
import {clampf} from '../utils/misc';
@@ -500,4 +500,4 @@ cc.Vec4 = Vec4;
*/
cc.v4 = function v4 (x, y, z, w) {
return new Vec4(x, y, z, w);
};
};
+2 -2
View File
@@ -17,7 +17,6 @@ export class Camera {
private _scene: RenderScene;
private _name: string;
private _node: Node;
private _proj: CameraProjection;
private _width: number;
private _height: number;
@@ -36,11 +35,11 @@ export class Camera {
private _matViewProj: mat4 = new Mat4();
private _matViewProjInv: mat4 = new Mat4();
private _frustum: frustum = new frustum();
private _node: Node | null = null;
constructor (scene: RenderScene, name: string) {
this._scene = scene;
this._name = name;
this._node = scene.createNode({ name: name + 'Node', isStatic: false });
this._proj = CameraProjection.PERSPECTIVE;
const win = scene.root.mainWindow;
@@ -70,6 +69,7 @@ export class Camera {
}
public update () {
if (!this._node) { return; }
// view matrix
this._node.getWorldRT(this._matView);
mat4.invert(this._matView, this._matView);
+13 -13
View File
@@ -33,28 +33,28 @@ class Node extends BaseNode {
}
// local transform
@property
public _lpos = new Vec3();
protected _lpos = new Vec3();
@property
public _lrot = new Quat();
protected _lrot = new Quat();
@property
public _lscale = new Vec3(1, 1, 1);
protected _lscale = new Vec3(1, 1, 1);
@property
public _layer = Layers.Default; // the layer this node belongs to
protected _layer = Layers.Default; // the layer this node belongs to
@property
public _euler = new Vec3(); // local rotation in euler angles, maintained here so that rotation angles could be greater than 360 degree.
protected _euler = new Vec3(); // local rotation in euler angles, maintained here so that rotation angles could be greater than 360 degree.
// world transform
public _pos = new Vec3();
public _rot = new Quat();
public _scale = new Vec3(1, 1, 1);
public _mat = new Mat4();
protected _pos = new Vec3();
protected _rot = new Quat();
protected _scale = new Vec3(1, 1, 1);
protected _mat = new Mat4();
public _dirty = false; // does the world transform need to update?
public _hasChanged = false; // has the transform changed in this frame?
protected _dirty = false; // does the world transform need to update?
protected _hasChanged = false; // has the transform changed in this frame?
public _matDirty = false;
public _eulerDirty = false;
protected _matDirty = false;
protected _eulerDirty = false;
@property({
type: Vec3,