Merge pull request #57 from JoneLau/new-3d

commit ui format
This commit is contained in:
Weiliang Wang
2019-01-16 13:34:31 +08:00
committed by GitHub
6 changed files with 130 additions and 70 deletions
+2 -1
View File
@@ -117,10 +117,11 @@ export class Root {
for (const view of this._views) {
if (view.isEnable()) {
this._pipeline!.render(view);
this._ui!.render(view);
}
}
this._ui!.update(deltaTime);
( this._device as GFXDevice).present();
}
-13
View File
@@ -1,13 +0,0 @@
import { UI } from './ui';
import { UIWidget, UIWidgetType } from './ui-widget';
export class LabelWidget extends UIWidget {
constructor (ui: UI) {
super(ui, UIWidgetType.LABEL);
}
public update () {
}
}
+95
View File
@@ -0,0 +1,95 @@
import { Material } from '../../3d/assets/material';
import { RecyclePool } from '../../3d/memop/recycle-pool';
class BaseRenderData {
public material: Material | null = null;
public vertexCount: number = 0;
public indiceCount: number = 0;
}
export class RenderData extends BaseRenderData {
get dataLength () {
return this._data.length;
}
set dataLength (length: number) {
const data = this._data;
if (data.length !== length) {
// // Free extra data
const value = data.length;
let i = 0;
for (i = value; i < length; i++) {
data[i] = _dataPool.add();
}
for (i = value; i > length; i--) {
_dataPool.remove(i);
data.splice(i, 1);
}
}
}
public static add () {
const data = _pool.add();
return {
pooID: _pool.length - 1,
data,
};
}
public static remove (idx: number) {
_pool.data[idx].clear();
_pool.remove(idx);
}
public _data: number[] = [];
public _indices: number[] = [];
public _pivotX: number = 0;
public _pivotY: number = 0;
public _width: number = 0;
public _height: number = 0;
public uvDirty: boolean = true;
public vertDirty: boolean = true;
public updateSizeNPivot (width: number, height: number, pivotX: number, pivotY: number) {
if (width !== this._width ||
height !== this._height ||
pivotX !== this._pivotX ||
pivotY !== this._pivotY) {
this._width = width;
this._height = height;
this._pivotX = pivotX;
this._pivotY = pivotY;
this.vertDirty = true;
}
}
public clear () {
this._data.length = 0;
this._indices.length = 0;
this._pivotX = 0;
this._pivotY = 0;
this._width = 0;
this._height = 0;
this.uvDirty = true;
this.vertDirty = true;
this.material = null;
this.vertexCount = 0;
this.indiceCount = 0;
}
}
const _dataPool = new RecyclePool(128, () => {
return {
x: 0.0,
y: 0.0,
z: 0.0,
u: 0.0,
v: 0.0,
color: 0,
};
});
const _pool = new RecyclePool(32, () => {
return new RenderData();
});
+5
View File
@@ -0,0 +1,5 @@
import { Model } from "../scene/model";
export class UIBatchModel extends Model {
}
-25
View File
@@ -1,25 +0,0 @@
import { UI } from './ui';
export enum UIWidgetType {
LABEL,
SPRITE,
}
export abstract class UIWidget {
protected _ui: UI;
protected _type: UIWidgetType;
protected _vertices: Float32Array | null = null;
protected _indices: Uint16Array | null = null;
constructor (ui: UI, type: UIWidgetType) {
this._ui = ui;
this._type = type;
}
public type (): UIWidgetType {
return this._type;
}
public abstract update ();
}
+28 -31
View File
@@ -1,57 +1,54 @@
import { MeshBuffer} from './mesh-buffer';
// import { vfmt3D } from '../../2d/renderer/webgl/vertex-format';
import { RecyclePool } from '../../3d/memop/recycle-pool';
import { Root } from '../../core/root';
import { RenderView } from '../../pipeline/render-view';
import { RenderScene } from '../scene/render-scene';
import { UIWidget } from './ui-widget';
import { UIBatchModel } from './ui-batch-model';
export class UI {
// private _buffer: MeshBuffer | null = new MeshBuffer(this, vfmt3D);
private _batchedModels: UIBatchModel[] = [];
private _iaPool: RecyclePool | null = new RecyclePool(16, () => {
// return this._root.device.createInputAssembler({
public get root (): Root {
return this._root;
}
public get scene (): RenderScene {
return this._scene;
}
private _root: Root;
// });
});
private _modelPool: RecyclePool | null = new RecyclePool(16, () => {
return this._scene.createModel(UIBatchModel);
});
private _scene: RenderScene;
private _widgets: UIWidget[] = [];
constructor (root: Root) {
this._root = root;
constructor (private _root: Root) {
this._scene = this._root.createScene({
name: 'GUIScene',
});
}
public initialize (): boolean {
public initialize () {
return true;
}
public destroy () {
this.destroyWidgets();
// this._reset();
}
public render (view: RenderView) {
public addScreen (comp) {
}
public createWidget<T extends UIWidget> (clazz: new () => T): T {
const widget = new clazz();
this._widgets.push(widget);
return widget;
public removeScreen (comp) {
}
public destroyWidget (widget: UIWidget) {
for (let i = 0; i < this._widgets.length; ++i) {
if (this._widgets[i] === widget) {
this._widgets.splice(i);
return;
}
}
public update (dt: number) {
const models = this._emit();
this._render(models);
}
public destroyWidgets () {
this._widgets = [];
private _emit (): UIBatchModel[] {
return this._batchedModels;
}
private _render (models: UIBatchModel[]) {
}
}