mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
Merge pull request #9 from YunHsiao/gfx
[API BREAKING] material with passes
This commit is contained in:
@@ -26,12 +26,12 @@
|
||||
// @ts-check
|
||||
import { _decorator } from "../../core/data/index";
|
||||
const { ccclass, property } = _decorator;
|
||||
import Asset from "../../assets/CCAsset";
|
||||
import { Asset } from "../../assets/asset";
|
||||
import vec3 from "../../core/vmath/vec3";
|
||||
import quat from "../../core/vmath/quat";
|
||||
import { clamp } from "../../core/vmath/utils";
|
||||
|
||||
/**
|
||||
/**
|
||||
* @typedef {import("../framework/skeleton-instance").SkeletonMask} SkeletonMask
|
||||
* @typedef {import("../../scene-graph/node").default} Node
|
||||
*/
|
||||
@@ -205,8 +205,8 @@ export class AnimationTarget {
|
||||
*/
|
||||
export class AnimationSampler {
|
||||
/**
|
||||
*
|
||||
* @param {AnimationTarget} animationTarget
|
||||
*
|
||||
* @param {AnimationTarget} animationTarget
|
||||
*/
|
||||
constructor(animationTarget) {
|
||||
/**
|
||||
@@ -246,7 +246,7 @@ export class AnimationSampler {
|
||||
|
||||
/** Sample data of this animation clip in a specific time and blend that data
|
||||
* with a weight together with previous data(if exist, or blank if not exists) sampled before.
|
||||
*
|
||||
*
|
||||
* @param {AnimationClip} clip
|
||||
* @param {Number} t The time.
|
||||
* @param {Number} weight The weight.
|
||||
@@ -316,7 +316,7 @@ export class AnimationSampler {
|
||||
|
||||
class NodeSamplingState {
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Node} target
|
||||
* @param {cc.Vec3} defaultPosition
|
||||
* @param {cc.Vec3} defaultScale
|
||||
@@ -395,4 +395,4 @@ class NodeSamplingState {
|
||||
if (this._sumRotWeight < 1.0)
|
||||
this.blendRotation(this._defaultRotation, 1.0 - this._sumRotWeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
****************************************************************************/
|
||||
// @ts-check
|
||||
import { _decorator } from "../../core/data/index";
|
||||
import Asset from "../../assets/CCAsset";
|
||||
import { Asset } from "../../assets/asset";
|
||||
import { EventTarget } from "../../core/event/index";
|
||||
const { ccclass, mixins } = _decorator;
|
||||
|
||||
@@ -117,4 +117,4 @@ export class AudioClip extends Asset {
|
||||
}
|
||||
}
|
||||
|
||||
cc.AudioClip = AudioClip;
|
||||
cc.AudioClip = AudioClip;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import Asset from '../../assets/CCAsset';
|
||||
import { Asset } from '../../assets/asset';
|
||||
import { ccclass, property } from '../../core/data/class-decorator';
|
||||
import { PassInfo } from '../../renderer/core/pass';
|
||||
import { PassInfoBase } from '../../renderer/core/pass';
|
||||
|
||||
export interface TechniqueInfo {
|
||||
passes: PassInfo[];
|
||||
passes: PassInfoBase[];
|
||||
queue?: number;
|
||||
priority?: number;
|
||||
lod?: number;
|
||||
@@ -16,33 +16,43 @@ export interface PropertyInfo {
|
||||
pass?: number;
|
||||
}
|
||||
|
||||
export interface UniformInfo {
|
||||
export interface BlockMember {
|
||||
name: string;
|
||||
type: number;
|
||||
bindingType: number;
|
||||
count: number;
|
||||
size: number;
|
||||
}
|
||||
export interface BlockInfo {
|
||||
name: string;
|
||||
binding: number;
|
||||
defines: string[];
|
||||
members?: Array< { name: string, type: number } >;
|
||||
members: BlockMember[];
|
||||
size: number;
|
||||
}
|
||||
export interface SamplerInfo {
|
||||
name: string;
|
||||
binding: number;
|
||||
defines: string[];
|
||||
type: number;
|
||||
count: number;
|
||||
}
|
||||
export interface DefineInfo {
|
||||
name: string;
|
||||
type: string;
|
||||
range?: number[];
|
||||
defines: string[];
|
||||
}
|
||||
export interface ExtensionInfo {
|
||||
name: string;
|
||||
define: string;
|
||||
}
|
||||
export interface ShaderInfo {
|
||||
name: string;
|
||||
vert: string;
|
||||
frag: string;
|
||||
defines: DefineInfo[];
|
||||
uniforms: UniformInfo[];
|
||||
extensions: ExtensionInfo[];
|
||||
blocks: BlockInfo[];
|
||||
samplers: SamplerInfo[];
|
||||
dependencies: Record<string, string>;
|
||||
}
|
||||
|
||||
const effects: { [name: string]: EffectAsset } = {};
|
||||
const effects: Record<string, EffectAsset> = {};
|
||||
|
||||
@ccclass('cc.EffectAsset')
|
||||
export class EffectAsset extends Asset {
|
||||
@@ -63,15 +73,16 @@ export class EffectAsset extends Asset {
|
||||
return effects[n];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static getAll() { return effects; }
|
||||
protected static _effects: { [name: string]: EffectAsset } = {};
|
||||
protected static _effects: Record<string, EffectAsset> = {};
|
||||
|
||||
@property
|
||||
public techniques: TechniqueInfo[] = [];
|
||||
|
||||
@property
|
||||
public properties: { [name: string]: PropertyInfo } = {};
|
||||
public properties: Record<string, PropertyInfo> = {};
|
||||
|
||||
@property
|
||||
public shaders: ShaderInfo[] = [];
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
// @ts-check
|
||||
import { _decorator } from "../../core/data/index";
|
||||
const {ccclass} = _decorator;
|
||||
import Asset from "../../assets/CCAsset";
|
||||
import { Asset } from "../../assets/asset";
|
||||
|
||||
@ccclass('cc.Font')
|
||||
export default class Font extends Asset {
|
||||
@@ -46,7 +46,7 @@ export default class Font extends Asset {
|
||||
_lineHeight = 32;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
_useKerning = false;
|
||||
@@ -78,4 +78,4 @@ export default class Font extends Asset {
|
||||
}
|
||||
}
|
||||
|
||||
cc.Font = Font;
|
||||
cc.Font = Font;
|
||||
|
||||
+14
-14
@@ -4,7 +4,7 @@
|
||||
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,
|
||||
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
|
||||
@@ -14,7 +14,7 @@
|
||||
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
|
||||
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
|
||||
@@ -23,17 +23,17 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import "./animation-clip";
|
||||
import "./audio-clip";
|
||||
import "./dom-audio-clip";
|
||||
import "./bitmap-font";
|
||||
import "./material";
|
||||
import "./mesh";
|
||||
import "./opentype-font";
|
||||
import "./skeleton";
|
||||
import "./sprite";
|
||||
import "./web-audio-clip";
|
||||
import "./wx-game-audio-clip";
|
||||
import './animation-clip';
|
||||
import './audio-clip';
|
||||
import './dom-audio-clip';
|
||||
import './bitmap-font';
|
||||
import './material';
|
||||
import './mesh';
|
||||
import './opentype-font';
|
||||
import './skeleton';
|
||||
import './sprite';
|
||||
import './web-audio-clip';
|
||||
import './wx-game-audio-clip';
|
||||
|
||||
import { PhysicsMaterial } from './physics/material';
|
||||
cc.PhysicsMaterial = PhysicsMaterial;
|
||||
cc.PhysicsMaterial = PhysicsMaterial;
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
/****************************************************************************
|
||||
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.
|
||||
****************************************************************************/
|
||||
// @ts-check
|
||||
import { ccclass, property } from "../../core/data/class-decorator";
|
||||
import Asset from "../../assets/CCAsset";
|
||||
import TextureBase from '../../assets/texture-base';
|
||||
import Effect from '../../renderer/core/effect';
|
||||
import { EffectAsset } from './effect-asset';
|
||||
|
||||
@ccclass('cc.Material')
|
||||
class Material extends Asset {
|
||||
/**
|
||||
* @type {Object}
|
||||
*/
|
||||
@property
|
||||
_defines = {};
|
||||
|
||||
/**
|
||||
* @type {Object}
|
||||
*/
|
||||
@property
|
||||
_props = {};
|
||||
|
||||
/**
|
||||
* @type {EffectAsset}
|
||||
*/
|
||||
@property(EffectAsset)
|
||||
_effectAsset = null;
|
||||
|
||||
@property
|
||||
set effectAsset(val) {
|
||||
if (this.effectName !== val.name) this._setEffect(val);
|
||||
}
|
||||
get effectAsset() {
|
||||
return this._effectAsset;
|
||||
}
|
||||
|
||||
// helper setter
|
||||
@property
|
||||
set effectName(val) {
|
||||
if (this.effectName !== val) this._setEffect(val);
|
||||
}
|
||||
get effectName() {
|
||||
return this._effectAsset ? this._effectAsset.name : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Effect}
|
||||
*/
|
||||
_effect = null;
|
||||
|
||||
/**
|
||||
* @type {Effect}
|
||||
*/
|
||||
get effect() {
|
||||
return this._effect;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Material} mat
|
||||
*/
|
||||
copy(mat) {
|
||||
Object.assign(this._props, mat._props);
|
||||
Object.assign(this._defines, mat._defines);
|
||||
this._setEffect(mat.effectAsset);
|
||||
this._uuid = mat._uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {*} val
|
||||
*/
|
||||
setProperty(name, val) {
|
||||
this._props[name] = val;
|
||||
if (this._effect) {
|
||||
if (val instanceof TextureBase) this._effect.setProperty(name, val._texture);
|
||||
else this._effect.setProperty(name, val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {*} val
|
||||
*/
|
||||
define(name, val) {
|
||||
this._defines[name] = val;
|
||||
if (this._effect) this._effect.define(name, val);
|
||||
}
|
||||
|
||||
onLoaded() {
|
||||
this._setEffect(this.effectAsset);
|
||||
}
|
||||
|
||||
_setEffect(val) {
|
||||
let effectAsset = val;
|
||||
if (typeof val === 'string' && !(effectAsset = cc.EffectAsset.get(val))) {
|
||||
console.warn(`no effect named '${val}' found`);
|
||||
return;
|
||||
}
|
||||
this._effectAsset = effectAsset;
|
||||
if (!effectAsset) return;
|
||||
this._effect = Effect.parseEffect(effectAsset);
|
||||
for (let def in this._defines)
|
||||
this._effect.define(def, this._defines[def]);
|
||||
for (let prop in this._props)
|
||||
this.setProperty(prop, this._props[prop]);
|
||||
}
|
||||
|
||||
static getInstantiatedMaterial(mat, rndCom) {
|
||||
if (mat._owner === rndCom) {
|
||||
return mat;
|
||||
}
|
||||
else {
|
||||
let instance = new Material();
|
||||
instance.copy(mat);
|
||||
instance._native = mat._native + ' (Instance)';
|
||||
instance._owner = rndCom;
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Material;
|
||||
cc.Material = Material;
|
||||
@@ -0,0 +1,155 @@
|
||||
/****************************************************************************
|
||||
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 { Asset } from '../../assets/asset';
|
||||
import TextureBase from '../../assets/texture-base';
|
||||
import { ccclass, property } from '../../core/data/class-decorator';
|
||||
import { Effect } from '../../renderer/core/effect';
|
||||
import { Pass } from '../../renderer/core/pass';
|
||||
import { EffectAsset } from './effect-asset';
|
||||
|
||||
@ccclass('cc.Material')
|
||||
export class Material extends Asset {
|
||||
public static getInstantiatedMaterial(mat: Material, rndCom: any) {
|
||||
if (mat._owner === rndCom) {
|
||||
return mat;
|
||||
} else {
|
||||
const instance = new Material();
|
||||
instance.copy(mat);
|
||||
instance._native = mat._native + ' (Instance)';
|
||||
instance._owner = rndCom;
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
@property(EffectAsset)
|
||||
protected _effectAsset: EffectAsset | null = null;
|
||||
@property
|
||||
protected _techIdx = 0;
|
||||
@property
|
||||
protected _defines: Record<string, number | boolean> = {};
|
||||
@property
|
||||
protected _props: Array<Record<string, any>> = [];
|
||||
|
||||
protected _passes: Pass[] = [];
|
||||
protected _owner: any = null;
|
||||
|
||||
@property
|
||||
set effectAsset(val: EffectAsset | null) {
|
||||
if (!val || this.effectName !== val.name) { this.update(val, false); }
|
||||
}
|
||||
get effectAsset() {
|
||||
return this._effectAsset;
|
||||
}
|
||||
// helper setter
|
||||
@property
|
||||
set effectName(val) {
|
||||
if (this.effectName !== val) { this.update(val, false); }
|
||||
}
|
||||
get effectName() {
|
||||
return this._effectAsset ? this._effectAsset.name : '';
|
||||
}
|
||||
|
||||
@property
|
||||
set technique(val: number) {
|
||||
this._techIdx = val;
|
||||
}
|
||||
get technique() {
|
||||
return this._techIdx;
|
||||
}
|
||||
|
||||
get passes() {
|
||||
return this._passes;
|
||||
}
|
||||
|
||||
public setDefines(defines: Record<string, number | boolean>) {
|
||||
this._defines = defines;
|
||||
this.update();
|
||||
}
|
||||
|
||||
public setProperty(handle: number, val: any, passIdx = 0) {
|
||||
if (this._props.length <= passIdx) {
|
||||
console.warn('illegal pass index');
|
||||
return;
|
||||
}
|
||||
this._props[passIdx][name] = val;
|
||||
const pass = this._passes[passIdx];
|
||||
if (pass) {
|
||||
if (val instanceof TextureBase) {
|
||||
pass.setProperty(handle, val._texture);
|
||||
} else {
|
||||
pass.setProperty(handle, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public copy(mat: Material) {
|
||||
this._props.length = mat._props.length;
|
||||
for (let i = 0; i < mat._props.length; i++) {
|
||||
Object.assign(this._props[i], mat._props[i]);
|
||||
}
|
||||
Object.assign(this._defines, mat._defines);
|
||||
this.update(mat.effectAsset);
|
||||
this._uuid = mat._uuid;
|
||||
}
|
||||
|
||||
public onLoaded() {
|
||||
this.update();
|
||||
}
|
||||
|
||||
public update(val: EffectAsset | string | null = this._effectAsset, keepProps: boolean = true) {
|
||||
// get effect asset
|
||||
if (typeof val === 'string') {
|
||||
this._effectAsset = EffectAsset.get(val);
|
||||
if (!this._effectAsset) {
|
||||
console.warn(`no effect named '${val}' found`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this._effectAsset = val;
|
||||
}
|
||||
if (!this._effectAsset) { return; }
|
||||
// create passes
|
||||
this._passes = Effect.parseEffect(this._effectAsset, {
|
||||
techIdx: this._techIdx,
|
||||
defines: this._defines,
|
||||
});
|
||||
// handle property values
|
||||
this._props.length = this._passes.length;
|
||||
if (keepProps) {
|
||||
this._passes.forEach((pass, i) => {
|
||||
let props = this._props[i];
|
||||
if (!props) { props = this._props[i] = {}; }
|
||||
for (const p of Object.keys(props)) {
|
||||
const handle = pass.getPropertyHandle(p);
|
||||
pass.setProperty(handle, props[p]);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this._props.fill({});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cc.Material = Material;
|
||||
@@ -26,7 +26,7 @@
|
||||
// @ts-check
|
||||
import { _decorator } from "../../core/data/index";
|
||||
const { ccclass, property } = _decorator;
|
||||
import Asset from "../../assets/CCAsset";
|
||||
import { Asset } from "../../assets/asset";
|
||||
import gfx from "../../renderer/gfx";
|
||||
import { enums as gfxEnums } from "../../renderer/gfx/enums";
|
||||
import InputAssembler from "../../renderer/core/input-assembler";
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// @ts-check
|
||||
|
||||
import CANNON from 'cannon';
|
||||
import Asset from '../../../assets/CCAsset';
|
||||
import { Asset } from '../../../assets/asset';
|
||||
import { ccclass, property } from '../../../core/data/class-decorator';
|
||||
|
||||
@ccclass('cc.PhysicalMaterial')
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
// @ts-check
|
||||
import { _decorator } from "../../core/data";
|
||||
const { ccclass, property } = _decorator;
|
||||
import Asset from "../../assets/CCAsset";
|
||||
import { Asset } from "../../assets/asset";
|
||||
import { Mat4 } from "../../core/value-types";
|
||||
|
||||
/**
|
||||
@@ -78,4 +78,4 @@ export default class Skeleton extends Asset {
|
||||
return this._joints;
|
||||
}
|
||||
}
|
||||
cc.Skeleton = Skeleton;
|
||||
cc.Skeleton = Skeleton;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
// @ts-check
|
||||
import { _decorator } from "../../core/data/index";
|
||||
const { ccclass } = _decorator;
|
||||
import Asset from "../../assets/CCAsset";
|
||||
import { Asset } from "../../assets/asset";
|
||||
import { vec3, mat4 } from '../../core/vmath/index';
|
||||
|
||||
let _t_tmp = vec3.create(0, 0, 0);
|
||||
@@ -200,4 +200,4 @@ export default class Sprite extends Asset {
|
||||
}
|
||||
}
|
||||
|
||||
cc.Sprite = Sprite;
|
||||
cc.Sprite = Sprite;
|
||||
|
||||
Vendored
+50
-24
@@ -1,12 +1,34 @@
|
||||
export default [
|
||||
{
|
||||
"name": "test",
|
||||
"techniques": [{"queue": 0, "lod": 500, "passes": [{"stage": 100, "program": "f4c45e6cc7794309d86202e6ec9036a3871fd1ec167a9e02eb1e1574"}], "priority": 0}],
|
||||
"properties": {"u_color": {"type": 17, "value": [1, 1, 1, 1]}, "u_sampler": {"type": 29, "value": null}},
|
||||
"shaders": [
|
||||
{
|
||||
"name": "f4c45e6cc7794309d86202e6ec9036a3871fd1ec167a9e02eb1e1574",
|
||||
"vert": "\n attribute vec2 a_position;\n attribute vec2 a_texCoord;\n varying vec2 v_texCoord;\n void main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n v_texCoord = a_texCoord;\n }\n",
|
||||
"frag": "\n varying vec2 v_texCoord;\n uniform vec4 u_color;\n uniform sampler2D u_sampler;\n void main() {\n \n gl_FragColor = texture2D(u_sampler, v_texCoord);\n gl_FragColor.r = u_color.r;\n }\n",
|
||||
"defines": [],
|
||||
"blocks": [
|
||||
{"name": "Constants", "size": 16, "defines": [], "binding": 0, "members": [
|
||||
{"name": "u_color", "type": 16, "count": 1, "size": 16}
|
||||
]}
|
||||
],
|
||||
"samplers": [
|
||||
{"name": "u_sampler", "type": 29, "count": 1, "defines": [], "binding": 1}
|
||||
],
|
||||
"dependencies": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "builtin-effect-unlit",
|
||||
"techniques": [{"queue": 0, "lod": 100, "passes": [{"program": "7781d6cc411d5facce7fc3d4aeb5349e804ddd9a58c002017c53682b"}], "priority": 0}],
|
||||
"techniques": [{"queue": 0, "lod": 100, "passes": [{"program": "e238b675dacba30ad29961fac06cb18d8c771e16d4fb0f9662acbe3c"}], "priority": 0}],
|
||||
"properties": {"color": {"type": 17, "value": [1, 1, 1, 1]}, "mainTiling": {"type": 14, "value": [1, 1]}, "mainOffset": {"type": 14, "value": [0, 0]}, "mainTexture": {"type": 29, "value": null}},
|
||||
"shaders": [
|
||||
{
|
||||
"name": "7781d6cc411d5facce7fc3d4aeb5349e804ddd9a58c002017c53682b",
|
||||
"vert": "\nattribute vec3 a_position;\n uniform mat4 cc_matProj;\n uniform mat4 cc_matProjInv;\n uniform mat4 cc_matView;\n uniform mat4 cc_matViewInv;\n uniform mat4 cc_matViewProj;\n uniform mat4 cc_matViewProjInv;\n uniform vec4 cc_time;\n uniform vec4 cc_screenSize;\n uniform vec4 cc_screenScale;\n uniform vec4 cc_cameraSize;\n uniform vec4 cc_cameraPos;\n uniform vec4 cc_dirLightDirection[4];\n uniform vec4 cc_dirLightColor[4];\n uniform vec4 cc_pointLightPositionAndRange[4];\n uniform vec4 cc_pointLightColor[4];\n uniform vec4 cc_spotLightPositionAndRange[4];\n uniform vec4 cc_spotLightDirection[4];\n uniform vec4 cc_spotLightColor[4];\n uniform mat4 cc_matViewProjLight;\n uniform vec4 cc_shadowParam1;\n uniform vec4 cc_shadowParam2;\n uniform mat4 cc_matWorld;\n uniform mat4 cc_matWorldIT;\n#if USE_TEXTURE\n attribute vec2 a_texCoord1;\n uniform vec2 mainTiling;\n uniform vec2 mainOffset;\n varying vec2 uv0;\n#endif\n#if CC_USE_SKINNING\n \nattribute vec4 a_weights;\nattribute vec4 a_joints;\n uniform mat4 cc_matJoint[128];\n uniform vec4 cc_jointsTextureSize;\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n pos = cc_matViewProj * cc_matWorld * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord1 * mainTiling + mainOffset;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n",
|
||||
"name": "e238b675dacba30ad29961fac06cb18d8c771e16d4fb0f9662acbe3c",
|
||||
"vert": "\nattribute vec3 a_position;\n uniform mat4 cc_matProj;\n uniform mat4 cc_matProjInv;\n uniform mat4 cc_matView;\n uniform mat4 cc_matViewInv;\n uniform mat4 cc_matViewProj;\n uniform mat4 cc_matViewProjInv;\n uniform vec4 cc_time;\n uniform vec4 cc_screenSize;\n uniform vec4 cc_screenScale;\n uniform vec4 cc_cameraSize;\n uniform vec4 cc_cameraPos;\n uniform vec4 cc_dirLightDirection;\n uniform vec4 cc_dirLightColor;\n uniform vec4 cc_pointLightPositionAndRange;\n uniform vec4 cc_pointLightColor;\n uniform vec4 cc_spotLightPositionAndRange;\n uniform vec4 cc_spotLightDirection;\n uniform vec4 cc_spotLightColor;\n uniform mat4 cc_matViewProjLight;\n uniform vec4 cc_shadowParam1;\n uniform vec4 cc_shadowParam2;\n uniform mat4 cc_matWorld;\n uniform mat4 cc_matWorldIT;\n#if USE_TEXTURE\n attribute vec2 a_texCoord1;\n uniform vec2 mainTiling;\n uniform vec2 mainOffset;\n varying vec2 uv0;\n#endif\n#if CC_USE_SKINNING\n \nattribute vec4 a_weights;\nattribute vec4 a_joints;\n uniform mat4 cc_matJoint;\n uniform vec4 cc_jointsTextureSize;\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n pos = cc_matViewProj * cc_matWorld * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord1 * mainTiling + mainOffset;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n",
|
||||
"frag": "\n#if USE_TEXTURE\n uniform sampler2D mainTexture;\n varying vec2 uv0;\n#endif\n#if USE_COLOR\n uniform vec4 color;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #endif\n #if USE_COLOR\n o *= color;\n #endif\n return o;\n}\nvoid main() { gl_FragColor = frag(); }\n",
|
||||
"defines": [
|
||||
{"name": "USE_TEXTURE", "type": "boolean", "defines": []},
|
||||
@@ -14,54 +36,58 @@ export default [
|
||||
{"name": "CC_USE_JOINTS_TEXTURE", "type": "boolean", "defines": ["CC_USE_SKINNING"]},
|
||||
{"name": "USE_COLOR", "type": "boolean", "defines": []}
|
||||
],
|
||||
"uniforms": [
|
||||
{"name": "TexCoords", "type": 0, "bindingType": 1, "defines": ["USE_TEXTURE"], "binding": 0, "members": [
|
||||
{"name": "mainTiling", "type": 14},
|
||||
{"name": "mainOffset", "type": 14}
|
||||
"blocks": [
|
||||
{"name": "TexCoords", "defines": ["USE_TEXTURE"], "binding": 0, "size": 16, "members": [
|
||||
{"name": "mainTiling", "type": 14, "count": 1},
|
||||
{"name": "mainOffset", "type": 14, "count": 1}
|
||||
]},
|
||||
{"name": "mainTexture", "type": 29, "bindingType": 2, "defines": ["USE_TEXTURE"], "binding": 1},
|
||||
{"name": "Constant", "type": 0, "bindingType": 1, "defines": ["USE_COLOR"], "binding": 2, "members": [
|
||||
{"name": "color", "type": 16}
|
||||
{"name": "Constant", "defines": ["USE_COLOR"], "binding": 1, "size": 16, "members": [
|
||||
{"name": "color", "type": 16, "count": 1}
|
||||
]}
|
||||
],
|
||||
"extensions": []
|
||||
"samplers": [
|
||||
{"name": "mainTexture", "type": 29, "count": 1, "defines": ["USE_TEXTURE"], "binding": 2}
|
||||
],
|
||||
"dependencies": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "builtin-effect-skybox",
|
||||
"techniques": [{"queue": 0, "lod": 200, "passes": [{"rasterizerState": {"cullMode": 0}, "depthStencilState": {"depthTest": false, "depthWrite": false}, "program": "e4ea21ace566a0976909c9b0d082bf97c4a115f78bafe08d6c5edec7"}], "priority": -1000}],
|
||||
"techniques": [{"queue": 0, "lod": 200, "passes": [{"rasterizerState": {"cullMode": 0}, "depthStencilState": {"depthTest": false, "depthWrite": false}, "program": "d9cd35729516d899db5cd6b6ecf025e61a484094405a391a3056591d"}], "priority": -1000}],
|
||||
"properties": {"cubeMap": {"type": 32, "value": null}},
|
||||
"shaders": [
|
||||
{
|
||||
"name": "e4ea21ace566a0976909c9b0d082bf97c4a115f78bafe08d6c5edec7",
|
||||
"vert": "\n attribute vec3 a_position;\n \n uniform mat4 cc_matProj;\n uniform mat4 cc_matProjInv;\n uniform mat4 cc_matView;\n uniform mat4 cc_matViewInv;\n uniform mat4 cc_matViewProj;\n uniform mat4 cc_matViewProjInv;\n uniform vec4 cc_time;\n uniform vec4 cc_screenSize;\n uniform vec4 cc_screenScale;\n uniform vec4 cc_cameraSize;\n uniform vec4 cc_cameraPos;\n uniform vec4 cc_dirLightDirection[4];\n uniform vec4 cc_dirLightColor[4];\n uniform vec4 cc_pointLightPositionAndRange[4];\n uniform vec4 cc_pointLightColor[4];\n uniform vec4 cc_spotLightPositionAndRange[4];\n uniform vec4 cc_spotLightDirection[4];\n uniform vec4 cc_spotLightColor[4];\n uniform mat4 cc_matViewProjLight;\n uniform vec4 cc_shadowParam1;\n uniform vec4 cc_shadowParam2;\n varying vec3 viewDir;\n void main() {\n mat4 rotView = mat4(mat3(cc_matView));\n vec4 clipPos = cc_matProj * rotView * vec4(a_position, 1.0);\n gl_Position = clipPos.xyww;\n viewDir = a_position;\n }\n",
|
||||
"name": "d9cd35729516d899db5cd6b6ecf025e61a484094405a391a3056591d",
|
||||
"vert": "\n attribute vec3 a_position;\n \n uniform mat4 cc_matProj;\n uniform mat4 cc_matProjInv;\n uniform mat4 cc_matView;\n uniform mat4 cc_matViewInv;\n uniform mat4 cc_matViewProj;\n uniform mat4 cc_matViewProjInv;\n uniform vec4 cc_time;\n uniform vec4 cc_screenSize;\n uniform vec4 cc_screenScale;\n uniform vec4 cc_cameraSize;\n uniform vec4 cc_cameraPos;\n uniform vec4 cc_dirLightDirection;\n uniform vec4 cc_dirLightColor;\n uniform vec4 cc_pointLightPositionAndRange;\n uniform vec4 cc_pointLightColor;\n uniform vec4 cc_spotLightPositionAndRange;\n uniform vec4 cc_spotLightDirection;\n uniform vec4 cc_spotLightColor;\n uniform mat4 cc_matViewProjLight;\n uniform vec4 cc_shadowParam1;\n uniform vec4 cc_shadowParam2;\n varying vec3 viewDir;\n void main() {\n mat4 rotView = mat4(mat3(cc_matView));\n vec4 clipPos = cc_matProj * rotView * vec4(a_position, 1.0);\n gl_Position = clipPos.xyww;\n viewDir = a_position;\n }\n",
|
||||
"frag": "\n varying vec3 viewDir;\n uniform samplerCube cubeMap;\n \nvec3 gammaToLinearSpaceRGB(vec3 sRGB) { \n return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);\n}\nvec3 linearToGammaSpaceRGB(vec3 RGB) { \n vec3 S1 = sqrt(RGB);\n vec3 S2 = sqrt(S1);\n vec3 S3 = sqrt(S2);\n return 0.585122381 * S1 + 0.783140355 * S2 - 0.368262736 * S3;\n}\nvec4 gammaToLinearSpaceRGBA(vec4 sRGBA) {\n return vec4(gammaToLinearSpaceRGB(sRGBA.rgb), sRGBA.a);\n}\nvec4 linearToGammaSpaceRGBA(vec4 RGBA) {\n return vec4(linearToGammaSpaceRGB(RGBA.rgb), RGBA.a);\n}\nfloat gammaToLinearSpaceExact(float val) {\n if (val <= 0.04045) {\n return val / 12.92;\n } else if (val < 1.0) {\n return pow((val + 0.055) / 1.055, 2.4);\n } else {\n return pow(val, 2.2);\n }\n}\nfloat linearToGammaSpaceExact(float val) {\n if (val <= 0.0) {\n return 0.0;\n } else if (val <= 0.0031308) {\n return 12.92 * val;\n } else if (val < 1.0) {\n return 1.055 * pow(val, 0.4166667) - 0.055;\n } else {\n return pow(val, 0.45454545);\n }\n}\n \nvec3 unpackNormal(vec4 nmap) {\n return nmap.xyz * 2.0 - 1.0;\n}\nvec3 unpackRGBE(vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\n void main() {\n #if USE_RGBE_CUBEMAP\n vec3 c = unpackRGBE(textureCube(cubeMap, viewDir));\n c = linearToGammaSpaceRGB(c / (1.0 + c));\n gl_FragColor = vec4(c, 1.0);\n #else\n gl_FragColor = textureCube(cubeMap, viewDir);\n #endif\n }\n",
|
||||
"defines": [
|
||||
{"name": "USE_RGBE_CUBEMAP", "type": "boolean", "defines": []}
|
||||
],
|
||||
"uniforms": [
|
||||
{"name": "cubeMap", "type": 32, "bindingType": 2, "defines": [], "binding": 0}
|
||||
"blocks": [],
|
||||
"samplers": [
|
||||
{"name": "cubeMap", "type": 32, "count": 1, "defines": [], "binding": 0}
|
||||
],
|
||||
"extensions": []
|
||||
"dependencies": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "builtin-effect-sprite",
|
||||
"techniques": [{"queue": 2, "passes": [{"depthStencilState": {"depthTest": true, "depthWrite": false}, "blendState": {"targets": [{"blend": true, "blendSrc": 2, "blendDst": 4, "blendDstAlpha": 4}]}, "program": "b28a508b291d9314faba527c0f13b99420d5feebd86bd4d38554b256"}], "priority": 0}],
|
||||
"techniques": [{"queue": 2, "passes": [{"depthStencilState": {"depthTest": true, "depthWrite": false}, "blendState": {"targets": [{"blend": true, "blendSrc": 2, "blendDst": 4, "blendDstAlpha": 4}]}, "program": "a86b95b64dc75bf2cc5b528318547813f86f5cd9e03ee48ca69556f6"}], "priority": 0}],
|
||||
"properties": {"mainTexture": {"type": 29, "value": null}},
|
||||
"shaders": [
|
||||
{
|
||||
"name": "b28a508b291d9314faba527c0f13b99420d5feebd86bd4d38554b256",
|
||||
"vert": "\nattribute vec3 a_position;\nattribute vec2 a_texCoord;\nattribute vec4 a_color;\n uniform mat4 cc_matProj;\n uniform mat4 cc_matProjInv;\n uniform mat4 cc_matView;\n uniform mat4 cc_matViewInv;\n uniform mat4 cc_matViewProj;\n uniform mat4 cc_matViewProjInv;\n uniform vec4 cc_time;\n uniform vec4 cc_screenSize;\n uniform vec4 cc_screenScale;\n uniform vec4 cc_cameraSize;\n uniform vec4 cc_cameraPos;\n uniform vec4 cc_dirLightDirection[4];\n uniform vec4 cc_dirLightColor[4];\n uniform vec4 cc_pointLightPositionAndRange[4];\n uniform vec4 cc_pointLightColor[4];\n uniform vec4 cc_spotLightPositionAndRange[4];\n uniform vec4 cc_spotLightDirection[4];\n uniform vec4 cc_spotLightColor[4];\n uniform mat4 cc_matViewProjLight;\n uniform vec4 cc_shadowParam1;\n uniform vec4 cc_shadowParam2;\n uniform mat4 cc_matWorld;\n uniform mat4 cc_matWorldIT;\nvarying vec2 uv0;\nvarying vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * cc_matWorld * pos;\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n",
|
||||
"name": "a86b95b64dc75bf2cc5b528318547813f86f5cd9e03ee48ca69556f6",
|
||||
"vert": "\nattribute vec3 a_position;\nattribute vec2 a_texCoord;\nattribute vec4 a_color;\n uniform mat4 cc_matProj;\n uniform mat4 cc_matProjInv;\n uniform mat4 cc_matView;\n uniform mat4 cc_matViewInv;\n uniform mat4 cc_matViewProj;\n uniform mat4 cc_matViewProjInv;\n uniform vec4 cc_time;\n uniform vec4 cc_screenSize;\n uniform vec4 cc_screenScale;\n uniform vec4 cc_cameraSize;\n uniform vec4 cc_cameraPos;\n uniform vec4 cc_dirLightDirection;\n uniform vec4 cc_dirLightColor;\n uniform vec4 cc_pointLightPositionAndRange;\n uniform vec4 cc_pointLightColor;\n uniform vec4 cc_spotLightPositionAndRange;\n uniform vec4 cc_spotLightDirection;\n uniform vec4 cc_spotLightColor;\n uniform mat4 cc_matViewProjLight;\n uniform vec4 cc_shadowParam1;\n uniform vec4 cc_shadowParam2;\n uniform mat4 cc_matWorld;\n uniform mat4 cc_matWorldIT;\nvarying vec2 uv0;\nvarying vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * cc_matWorld * pos;\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n",
|
||||
"frag": "\nuniform sampler2D mainTexture;\nvarying vec2 uv0;\nvarying vec4 color;\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= texture2D(mainTexture, uv0);\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }\n",
|
||||
"defines": [],
|
||||
"uniforms": [
|
||||
{"name": "mainTexture", "type": 29, "bindingType": 2, "defines": [], "binding": 0}
|
||||
"blocks": [],
|
||||
"samplers": [
|
||||
{"name": "mainTexture", "type": 29, "count": 1, "defines": [], "binding": 0}
|
||||
],
|
||||
"extensions": []
|
||||
"dependencies": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Texture2D from '../../assets/texture-2d';
|
||||
import TextureCube from '../assets/texture-cube';
|
||||
import ImageAsset from '../../assets/image-asset';
|
||||
import Material from '../assets/material';
|
||||
import { Material } from '../assets/material';
|
||||
import { EffectAsset } from '../assets/effect-asset';
|
||||
import effects from './effects';
|
||||
|
||||
@@ -80,8 +80,8 @@ let builtinResMgr = {
|
||||
// default material
|
||||
// let defaultMtl = new Material();
|
||||
// defaultMtl._uuid = 'default-material';
|
||||
// defaultMtl._defines['USE_COLOR'] = true;
|
||||
// defaultMtl.effectAsset = efxs[0];
|
||||
// defaultMtl.define('USE_COLOR', true);
|
||||
// defaultMtl.setProperty('color', cc.color('#FF00FF'));
|
||||
|
||||
let builtins = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ParticleSystemRenderer from "./particle-system-renderer";
|
||||
import Material from "../../../assets/material";
|
||||
import { Material } from "../../../assets/material";
|
||||
import Particle from "../particle";
|
||||
import gfx from "../../../../renderer/gfx";
|
||||
import { CurveUniform } from "../animator/optimized-curve";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import renderer from '../../../../renderer';
|
||||
import { vec3, vec4, vec2, mat4 } from '../../../../core/vmath';
|
||||
import gfx from '../../../../renderer/gfx';
|
||||
import Material from '../../../assets/material';
|
||||
import { Material } from '../../../assets/material';
|
||||
import { RecyclePool } from '../../../memop';
|
||||
import Particle from '../particle';
|
||||
import RenderableComponent from '../../renderable-component';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//@ts-check
|
||||
import { _decorator } from '../../core/data/index';
|
||||
import Material from "../assets/material";
|
||||
import { Material } from "../assets/material";
|
||||
import Component from "../../components/CCComponent";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
// @ts-check
|
||||
import renderer from '../../renderer/index';
|
||||
import { box } from '../primitive/index';
|
||||
import Material from '../assets/material';
|
||||
import { Material } from '../assets/material';
|
||||
import { ccclass, property, menu, executeInEditMode } from '../../core/data/class-decorator';
|
||||
import TextureCube from '../assets/texture-cube';
|
||||
import Component from '../../components/CCComponent';
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
import {createMap, isChildClassOf, _getClassById} from '../core/utils/js';
|
||||
import Asset from './CCAsset';
|
||||
import { Asset } from './asset';
|
||||
import {callInNextTick} from '../core/utils/misc';
|
||||
import decodeUuid from '../core/utils/decode-uuid';
|
||||
import Loader from '../load-pipeline/CCLoader';
|
||||
@@ -348,11 +348,11 @@ let AssetLibrary = {
|
||||
_uuidToRawAsset[uuid] = new RawAssetEntry(mountPoint + '/' + url, type);
|
||||
// init resources
|
||||
var isSubAsset = info[2] === 1;
|
||||
|
||||
|
||||
if (!assetTables[mountPoint]) {
|
||||
assetTables[mountPoint] = new AssetTable();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assetTables[mountPoint].add(url, uuid, type, !isSubAsset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import Asset from './CCAsset';
|
||||
import { Asset } from './asset';
|
||||
import {ccclass} from '../core/data/class-decorator';
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
import { _decorator } from "../core/data/index";
|
||||
const { ccclass, property } = _decorator;
|
||||
import BufferAsset from "./CCBufferAsset";
|
||||
import Asset from "./CCAsset";
|
||||
import { Asset } from "./asset";
|
||||
|
||||
/**
|
||||
* @typedef {import("../../../types/glTF/glTF").GlTf} GlTf
|
||||
@@ -37,7 +37,7 @@ import Asset from "./CCAsset";
|
||||
* Class for GLTF file.
|
||||
*
|
||||
* !#zh
|
||||
* GLTF 资源类。<br>
|
||||
* GLTF 资溝类。<br>
|
||||
*
|
||||
* @class GLTFAsset
|
||||
* @extends Asset
|
||||
@@ -80,4 +80,4 @@ export default class GLTFAsset extends Asset {
|
||||
}
|
||||
}
|
||||
|
||||
cc.GLTFAsset = GLTFAsset;
|
||||
cc.GLTFAsset = GLTFAsset;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import Asset from './CCAsset';
|
||||
import { Asset } from './asset';
|
||||
import {ccclass, property} from '../core/data/class-decorator';
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
import {compile} from '../core/data/instantiate-jit';
|
||||
import Enum from '../core/value-types/enum';
|
||||
import {obsolete} from '../core/utils/js';
|
||||
import Asset from './CCAsset';
|
||||
import { Asset } from './asset';
|
||||
import {ccclass, property} from '../core/data/class-decorator';
|
||||
|
||||
/**
|
||||
@@ -203,4 +203,4 @@ export default class Prefab extends Asset {
|
||||
}
|
||||
|
||||
cc.Prefab = Prefab;
|
||||
obsolete(cc, 'cc._Prefab', 'Prefab');
|
||||
obsolete(cc, 'cc._Prefab', 'Prefab');
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import Asset from './CCAsset';
|
||||
import { Asset } from './asset';
|
||||
import {ccclass, property} from '../core/data/class-decorator';
|
||||
|
||||
/**
|
||||
@@ -60,4 +60,4 @@ export default class SceneAsset extends Asset {
|
||||
//}
|
||||
}
|
||||
|
||||
cc.SceneAsset = SceneAsset;
|
||||
cc.SceneAsset = SceneAsset;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import Asset from './CCAsset';
|
||||
import { Asset } from './asset';
|
||||
import {ccclass} from '../core/data/class-decorator';
|
||||
|
||||
/**
|
||||
@@ -62,4 +62,4 @@ cc._JavaScript = JavaScript;
|
||||
@ccclass('cc.TypeScript')
|
||||
export class TypeScript extends Script {
|
||||
}
|
||||
cc._TypeScript = TypeScript;
|
||||
cc._TypeScript = TypeScript;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import Asset from './CCAsset';
|
||||
import { Asset } from './asset';
|
||||
import {ccclass, property} from '../core/data/class-decorator';
|
||||
|
||||
/**
|
||||
@@ -64,7 +64,7 @@ export default class SpriteAtlas extends Asset {
|
||||
let sf = this._spriteFrames[key];
|
||||
if (!sf) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!sf.name) {
|
||||
sf.name = key;
|
||||
}
|
||||
@@ -88,4 +88,4 @@ export default class SpriteAtlas extends Asset {
|
||||
}
|
||||
}
|
||||
|
||||
cc.SpriteAtlas = SpriteAtlas;
|
||||
cc.SpriteAtlas = SpriteAtlas;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
import EventTarget from '../core/event/event-target';
|
||||
import textureUtil from './texture-util';
|
||||
import {addon} from '../core/utils/js';
|
||||
import Asset from './CCAsset';
|
||||
import { Asset } from './asset';
|
||||
import {ccclass, property} from '../core/data/class-decorator';
|
||||
|
||||
|
||||
@@ -712,4 +712,4 @@ proto.initWithTexture = proto.setTexture;
|
||||
|
||||
addon(proto, EventTarget.prototype);
|
||||
|
||||
cc.SpriteFrame = SpriteFrame;
|
||||
cc.SpriteFrame = SpriteFrame;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import Asset from './CCAsset';
|
||||
import { Asset } from './asset';
|
||||
import {ccclass, property} from '../core/data/class-decorator';
|
||||
|
||||
/**
|
||||
@@ -54,4 +54,4 @@ export default class TextAsset extends Asset {
|
||||
}
|
||||
}
|
||||
|
||||
cc.TextAsset = TextAsset;
|
||||
cc.TextAsset = TextAsset;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
import { ccclass, property } from '../core/data/class-decorator';
|
||||
import RawAsset from './CCRawAsset';
|
||||
import { RawAsset } from './raw-asset';
|
||||
|
||||
/**
|
||||
* !#en
|
||||
@@ -44,73 +44,92 @@ import RawAsset from './CCRawAsset';
|
||||
* - _nativeAsset 的 getset 方法<br/>
|
||||
* - cc.Object._serialize<br/>
|
||||
* - cc.Object._deserialize<br/>
|
||||
*
|
||||
* @class Asset
|
||||
* @extends RawAsset
|
||||
*/
|
||||
@ccclass('cc.Asset')
|
||||
export default class Asset extends RawAsset {
|
||||
constructor () {
|
||||
super();
|
||||
/**
|
||||
* !#en
|
||||
* Whether the asset is loaded or not
|
||||
* !#zh
|
||||
* 该资源是否已经成功加载
|
||||
*
|
||||
* @property loaded
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.loaded = true;
|
||||
export class Asset extends RawAsset {
|
||||
/**
|
||||
* !#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。
|
||||
*
|
||||
* @property {Boolean} preventDeferredLoadDependents
|
||||
* @default false
|
||||
* @static
|
||||
*/
|
||||
public static preventDeferredLoadDependents = false;
|
||||
|
||||
/**
|
||||
* !#en Indicates whether its native object should be preloaded from native url.
|
||||
* !#zh 禁止预加载原生对象。
|
||||
*
|
||||
* @property {Boolean} preventPreloadNativeObject
|
||||
* @default false
|
||||
* @static
|
||||
*/
|
||||
public static preventPreloadNativeObject = false;
|
||||
|
||||
/**
|
||||
* 应 AssetDB 要求提供这个方法
|
||||
*/
|
||||
protected static deserialize(data: string): Asset {
|
||||
return cc.deserialize(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* !#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/>
|
||||
* 如果这类资源没有相应的节点类型,该方法应该是空的。
|
||||
*
|
||||
* @param {Function} callback
|
||||
* @param {String} callback.error - null or the error info
|
||||
* @param {Object} callback.node - the created node or null
|
||||
*/
|
||||
public createNode: null | ((callback: (err: string, node: object) => void) => void) = null;
|
||||
|
||||
protected loaded = true;
|
||||
|
||||
/**
|
||||
* Serializable url for native asset.
|
||||
*/
|
||||
@property
|
||||
protected _native = '';
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Returns the url of this asset's native object, if none it will returns an empty string.
|
||||
* !#zh
|
||||
* 返回该资源对应的目标平台资源的 URL,如果没有将返回一个空字符串。
|
||||
* @property nativeUrl
|
||||
* @type {String}
|
||||
* @readOnly
|
||||
*/
|
||||
@property({
|
||||
visible: false
|
||||
visible: false,
|
||||
})
|
||||
get nativeUrl () {
|
||||
get nativeUrl(): Readonly<string> {
|
||||
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;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// imported in an independent dir
|
||||
return base + '/' + name;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cc.errorID(6400);
|
||||
}
|
||||
}
|
||||
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,104 +140,42 @@ export default class Asset extends RawAsset {
|
||||
* @type {any}
|
||||
*/
|
||||
@property
|
||||
get _nativeAsset () {
|
||||
}
|
||||
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。
|
||||
*
|
||||
* @property {Boolean} preventDeferredLoadDependents
|
||||
* @default false
|
||||
* @static
|
||||
*/
|
||||
static preventDeferredLoadDependents = false;
|
||||
|
||||
/**
|
||||
* !#en Indicates whether its native object should be preloaded from native url.
|
||||
* !#zh 禁止预加载原生对象。
|
||||
*
|
||||
* @property {Boolean} preventPreloadNativeObject
|
||||
* @default false
|
||||
* @static
|
||||
*/
|
||||
static preventPreloadNativeObject = false;
|
||||
get _nativeAsset() { return null; }
|
||||
set _nativeAsset(obj) {}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* This method may be overwritten by subclasses.
|
||||
*
|
||||
* @method toString
|
||||
* @return {String}
|
||||
*/
|
||||
toString () {
|
||||
public toString(): string {
|
||||
return this.nativeUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应 AssetDB 要求提供这个方法
|
||||
*
|
||||
* @method serialize
|
||||
* @return {String}
|
||||
* @private
|
||||
*/
|
||||
serialize () {
|
||||
return Editor.serialize(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set native file name for this asset.
|
||||
* @seealso nativeUrl
|
||||
*
|
||||
* @method _setRawAsset
|
||||
* @param {String} filename
|
||||
* @param {Boolean} [inLibrary=true]
|
||||
* @private
|
||||
*/
|
||||
_setRawAsset (filename, inLibrary) {
|
||||
protected _setRawAsset(filename: string, inLibrary: boolean = true) {
|
||||
if (inLibrary !== false) {
|
||||
this._native = filename || undefined;
|
||||
}
|
||||
else {
|
||||
this._native = filename;
|
||||
} else {
|
||||
this._native = '/' + filename; // simply use '/' to tag location where is not in the library
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 应 AssetDB 要求提供这个方法
|
||||
*/
|
||||
protected serialize(): string {
|
||||
return Editor.serialize(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* !#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
|
||||
*/
|
||||
Asset.prototype.createNode = null;
|
||||
|
||||
cc.Asset = Asset;
|
||||
cc.Asset = Asset;
|
||||
@@ -24,8 +24,8 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
export {default as RawAsset} from './CCRawAsset';
|
||||
export {default as Asset} from './CCAsset';
|
||||
export { RawAsset } from './raw-asset';
|
||||
export { Asset } from './asset';
|
||||
export {default as Prefab} from './CCPrefab';
|
||||
export * from './CCScripts';
|
||||
export {default as SceneAsset} from './CCSceneAsset';
|
||||
|
||||
@@ -24,45 +24,34 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import {isChildClassOf} from '../core/utils/js';
|
||||
import CCObject from '../core/data/object';
|
||||
import {ccclass} from '../core/data/class-decorator';
|
||||
import { ccclass } from '../core/data/class-decorator';
|
||||
import { CCObject } from '../core/data/object';
|
||||
import { isChildClassOf } from '../core/utils/js';
|
||||
|
||||
function enumerable(value: boolean) {
|
||||
return (target: any, propertyKey: string) => {
|
||||
const descriptor = Object.getOwnPropertyDescriptor(target, propertyKey) || {};
|
||||
if (descriptor.enumerable !== value) {
|
||||
descriptor.enumerable = value;
|
||||
Object.defineProperty(target, propertyKey, descriptor);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* The base class for registering asset types.
|
||||
* !#zh
|
||||
* 注册用的资源基类。
|
||||
*
|
||||
* @class RawAsset
|
||||
* @extends Object
|
||||
*/
|
||||
@ccclass('cc.RawAsset')
|
||||
export default class RawAsset extends CCObject {
|
||||
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
|
||||
});
|
||||
export class RawAsset extends CCObject {
|
||||
protected static isRawAssetType(ctor: Function): boolean {
|
||||
return isChildClassOf(ctor, RawAsset) && !isChildClassOf(ctor, cc.Asset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @method isRawAssetType
|
||||
* @param {Function} ctor
|
||||
* @returns {Boolean}
|
||||
* @static
|
||||
* @private
|
||||
*/
|
||||
static isRawAssetType (ctor) {
|
||||
return isChildClassOf(ctor, cc.RawAsset) && !isChildClassOf(ctor, cc.Asset);
|
||||
}
|
||||
@enumerable(false)
|
||||
protected _uuid = '';
|
||||
}
|
||||
|
||||
cc.RawAsset = RawAsset;
|
||||
@@ -29,7 +29,7 @@ import IDGenerator from '../core/utils/id-generator';
|
||||
import Enum from '../core/value-types/enum';
|
||||
import {addon} from '../core/utils/js';
|
||||
import {enums} from '../renderer/gfx/enums';
|
||||
import Asset from './CCAsset';
|
||||
import { Asset } from './asset';
|
||||
import {ccclass, property} from '../core/data/class-decorator';
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import CCObject from '../core/data/object';
|
||||
import { CCObject } from '../core/data/object';
|
||||
import {getClassName, value} from '../core/utils/js';
|
||||
import IDGenerator from '../core/utils/id-generator';
|
||||
import {ccclass, property} from '../core/data/class-decorator';
|
||||
|
||||
@@ -27,6 +27,6 @@ import * as _decorator from './class-decorator';
|
||||
cc._decorator = _decorator;
|
||||
export { _decorator };
|
||||
export { default as CCClass } from './class';
|
||||
export { default as CCObject } from './object';
|
||||
export { CCObject } from './object';
|
||||
export { default as deserialize } from './deserialize';
|
||||
export { default as instantiate } from './instantiate';
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
import * as js from '../utils/js';
|
||||
import CCClass from './class';
|
||||
import CCObject from './object';
|
||||
import { CCObject } from './object';
|
||||
import * as Attr from './utils/attribute';
|
||||
import {flattenCodeArray} from './utils/compiler';
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import CCObject from './object';
|
||||
import { CCObject } from './object';
|
||||
import ValueType from '../value-types/value-type';
|
||||
import {isDomNode} from '../utils/misc';
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ const DontDestroy = 1 << 6;
|
||||
const Destroying = 1 << 7;
|
||||
const Deactivating = 1 << 8;
|
||||
const LockedInEditor = 1 << 9;
|
||||
//var HideInGame = 1 << 9;
|
||||
var HideInHierarchy = 1 << 10;
|
||||
// const HideInGame = 1 << 9;
|
||||
const HideInHierarchy = 1 << 10;
|
||||
|
||||
const IsOnEnableCalled = 1 << 11;
|
||||
const IsEditorOnEnableCalled = 1 << 12;
|
||||
@@ -54,7 +54,7 @@ const IsAnchorLocked = 1 << 19;
|
||||
const IsSizeLocked = 1 << 20;
|
||||
const IsPositionLocked = 1 << 21;
|
||||
|
||||
//var Hide = HideInGame | HideInEditor;
|
||||
// const Hide = HideInGame | HideInEditor;
|
||||
// should not clone or serialize these flags
|
||||
const PersistentMask = ~(ToDestroy | Dirty | Destroying | DontDestroy | Deactivating |
|
||||
IsPreloadStarted | IsOnLoadStarted | IsOnLoadCalled | IsStartCalled |
|
||||
@@ -62,37 +62,34 @@ const PersistentMask = ~(ToDestroy | Dirty | Destroying | DontDestroy | Deactiva
|
||||
IsRotationLocked | IsScaleLocked | IsAnchorLocked | IsSizeLocked | IsPositionLocked
|
||||
/*RegisteredInEditor*/);
|
||||
|
||||
var objectsToDestroy = [];
|
||||
var deferredDestroyTimer = null;
|
||||
const objectsToDestroy: CCObject[] = [];
|
||||
let deferredDestroyTimer = null;
|
||||
|
||||
function compileDestruct (obj, ctor) {
|
||||
var shouldSkipId = obj instanceof cc._BaseNode || obj instanceof cc.Component;
|
||||
var idToSkip = shouldSkipId ? '_id' : null;
|
||||
function compileDestruct(obj: object, ctor) {
|
||||
const shouldSkipId = obj instanceof cc._BaseNode || obj instanceof cc.Component;
|
||||
const idToSkip = shouldSkipId ? '_id' : null;
|
||||
|
||||
var key, propsToReset = {};
|
||||
for (key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
if (key === idToSkip) {
|
||||
continue;
|
||||
}
|
||||
switch (typeof obj[key]) {
|
||||
case 'string':
|
||||
propsToReset[key] = '';
|
||||
break;
|
||||
case 'object':
|
||||
case 'function':
|
||||
propsToReset[key] = null;
|
||||
break;
|
||||
}
|
||||
const propsToReset = {};
|
||||
for (const key of Object.keys(obj)) {
|
||||
if (key === idToSkip) {
|
||||
continue;
|
||||
}
|
||||
switch (typeof obj[key]) {
|
||||
case 'string':
|
||||
propsToReset[key] = '';
|
||||
break;
|
||||
case 'object':
|
||||
case 'function':
|
||||
propsToReset[key] = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Overwrite propsToReset according to Class
|
||||
if (CCClass._isCCClass(ctor)) {
|
||||
var attrs = cc.Class.Attr.getClassAttrs(ctor);
|
||||
var propList = ctor.__props__;
|
||||
for (var i = 0; i < propList.length; i++) {
|
||||
key = propList[i];
|
||||
var attrKey = key + cc.Class.Attr.DELIMETER + 'default';
|
||||
const attrs = cc.Class.Attr.getClassAttrs(ctor);
|
||||
const propList = ctor.__props__;
|
||||
for (const key of propList) {
|
||||
const attrKey = key + cc.Class.Attr.DELIMETER + 'default';
|
||||
if (attrKey in attrs) {
|
||||
if (shouldSkipId && key === '_id') {
|
||||
continue;
|
||||
@@ -115,26 +112,24 @@ function compileDestruct (obj, ctor) {
|
||||
|
||||
if (CC_SUPPORT_JIT) {
|
||||
// compile code
|
||||
var func = '';
|
||||
for (key in propsToReset) {
|
||||
var statement;
|
||||
let func = '';
|
||||
for (const key of Object.keys(propsToReset)) {
|
||||
let statement: string;
|
||||
if (CCClass.IDENTIFIER_RE.test(key)) {
|
||||
statement = 'o.' + key + '=';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
statement = 'o[' + CCClass.escapeForJS(key) + ']=';
|
||||
}
|
||||
var val = propsToReset[key];
|
||||
let val = propsToReset[key];
|
||||
if (val === '') {
|
||||
val = '""';
|
||||
}
|
||||
func += (statement + val + ';\n');
|
||||
}
|
||||
return Function('o', func);
|
||||
}
|
||||
else {
|
||||
return function (o) {
|
||||
for (var key in propsToReset) {
|
||||
} else {
|
||||
return (o: object) => {
|
||||
for (const key of Object.keys(propsToReset)) {
|
||||
o[key] = propsToReset[key];
|
||||
}
|
||||
};
|
||||
@@ -149,26 +144,10 @@ function compileDestruct (obj, ctor) {
|
||||
* @private
|
||||
*/
|
||||
class CCObject {
|
||||
constructor (name = '') {
|
||||
/**
|
||||
* @property {String} _name
|
||||
* @default ""
|
||||
* @private
|
||||
*/
|
||||
this._name = name;
|
||||
|
||||
/**
|
||||
* @property {Number} _objFlags
|
||||
* @default 0
|
||||
* @private
|
||||
*/
|
||||
this._objFlags = 0;
|
||||
}
|
||||
|
||||
static _deferredDestroy () {
|
||||
var deleteCount = objectsToDestroy.length;
|
||||
for (var i = 0; i < deleteCount; ++i) {
|
||||
var obj = objectsToDestroy[i];
|
||||
protected static _deferredDestroy() {
|
||||
const deleteCount = objectsToDestroy.length;
|
||||
for (let i = 0; i < deleteCount; ++i) {
|
||||
const obj = objectsToDestroy[i];
|
||||
if (!(obj._objFlags & Destroyed)) {
|
||||
obj._destroyImmediate();
|
||||
}
|
||||
@@ -177,8 +156,7 @@ class CCObject {
|
||||
// but we only destroy the objects which called destory in this frame.
|
||||
if (deleteCount === objectsToDestroy.length) {
|
||||
objectsToDestroy.length = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
objectsToDestroy.splice(0, deleteCount);
|
||||
}
|
||||
|
||||
@@ -187,20 +165,23 @@ class CCObject {
|
||||
}
|
||||
}
|
||||
|
||||
protected _name = '';
|
||||
protected _objFlags = 0;
|
||||
|
||||
constructor(name = '') {
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
// MEMBER
|
||||
|
||||
/**
|
||||
* !#en The name of the object.
|
||||
* !#zh 该对象的名称。
|
||||
* @property {String} name
|
||||
* @default ""
|
||||
* @example
|
||||
* obj.name = "New Obj";
|
||||
*/
|
||||
get name () {
|
||||
get name() {
|
||||
return this._name;
|
||||
}
|
||||
set name (value) {
|
||||
set name(value) {
|
||||
this._name = value;
|
||||
}
|
||||
|
||||
@@ -214,20 +195,19 @@ class CCObject {
|
||||
*
|
||||
* !#zh
|
||||
* 表示该对象是否可用(被 destroy 后将不可用)。<br>
|
||||
* 当一个对象的 `destroy` 调用以后,会在这一帧结束后才真正销毁。因此从下一帧开始 `isValid` 就会返回 false,而当前帧内 `isValid` 仍然会是 true。如果希望判断当前帧是否调用过 `destroy`,请使用 `cc.isValid(obj, true)`,不过这往往是特殊的业务需求引起的,通常情况下不需要这样。
|
||||
* 当一个对象的 `destroy` 调用以后,会在这一帧结束后才真正销毁。因此从下一帧开始 `isValid` 就会返回 false
|
||||
* 而当前帧内 `isValid` 仍然会是 true。如果希望判断当前帧是否调用过 `destroy`
|
||||
* 请使用 `cc.isValid(obj, true)`,不过这往往是特殊的业务需求引起的,通常情况下不需要这样。
|
||||
*
|
||||
* @property {Boolean} isValid
|
||||
* @default true
|
||||
* @readOnly
|
||||
* @example
|
||||
* var node = new cc.Node();
|
||||
* const node = new cc.Node();
|
||||
* cc.log(node.isValid); // true
|
||||
* node.destroy();
|
||||
* cc.log(node.isValid); // true, still valid in this frame
|
||||
* // after a frame...
|
||||
* cc.log(node.isValid); // false, destroyed in the end of last frame
|
||||
*/
|
||||
get isValid () {
|
||||
get isValid(): Readonly<boolean> {
|
||||
return !(this._objFlags & Destroyed);
|
||||
}
|
||||
|
||||
@@ -241,12 +221,8 @@ class CCObject {
|
||||
* 销毁该对象,并释放所有它对其它对象的引用。<br/>
|
||||
* 实际销毁操作会延迟到当前帧渲染前执行。从下一帧开始,该对象将不再可用。
|
||||
* 您可以在访问对象之前使用 cc.isValid(obj) 来检查对象是否已被销毁。
|
||||
* @method destroy
|
||||
* @return {Boolean} whether it is the first time the destroy being called
|
||||
* @example
|
||||
* obj.destroy();
|
||||
*/
|
||||
destroy () {
|
||||
public destroy() {
|
||||
if (this._objFlags & Destroyed) {
|
||||
cc.warnID(5000);
|
||||
return false;
|
||||
@@ -270,7 +246,7 @@ class CCObject {
|
||||
* NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject.
|
||||
* You can override the _destruct method if you need, for example:
|
||||
* _destruct: function () {
|
||||
* for (var key in this) {
|
||||
* for (const key in this) {
|
||||
* if (this.hasOwnProperty(key)) {
|
||||
* switch (typeof this[key]) {
|
||||
* case 'string':
|
||||
@@ -284,12 +260,10 @@ class CCObject {
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @method _destruct
|
||||
* @private
|
||||
*/
|
||||
_destruct () {
|
||||
var ctor = this.constructor;
|
||||
var destruct = ctor.__destruct__;
|
||||
protected _destruct() {
|
||||
const ctor = this.constructor;
|
||||
let destruct = ctor.__destruct__;
|
||||
if (!destruct) {
|
||||
destruct = compileDestruct(this, ctor);
|
||||
js.value(ctor, '__destruct__', destruct, true);
|
||||
@@ -297,7 +271,7 @@ class CCObject {
|
||||
destruct(this);
|
||||
}
|
||||
|
||||
_destroyImmediate () {
|
||||
protected _destroyImmediate() {
|
||||
if (this._objFlags & Destroyed) {
|
||||
cc.errorID(5000);
|
||||
return;
|
||||
@@ -315,7 +289,7 @@ class CCObject {
|
||||
}
|
||||
}
|
||||
|
||||
let prototype = CCObject.prototype;
|
||||
const prototype = CCObject.prototype;
|
||||
if (CC_EDITOR || CC_TEST) {
|
||||
js.get(prototype, 'isRealValid', function () {
|
||||
return !(this._objFlags & RealDestroyed);
|
||||
@@ -509,31 +483,30 @@ js.value(CCObject, 'Flags', {
|
||||
* @param {Boolean} [strictMode=false] - If true, Object called destroy() in this frame will also treated as invalid.
|
||||
* @return {Boolean} whether is valid
|
||||
* @example
|
||||
* var node = new cc.Node();
|
||||
* const node = new cc.Node();
|
||||
* cc.log(cc.isValid(node)); // true
|
||||
* node.destroy();
|
||||
* cc.log(cc.isValid(node)); // true, still valid in this frame
|
||||
* // after a frame...
|
||||
* cc.log(cc.isValid(node)); // false, destroyed in the end of last frame
|
||||
*/
|
||||
cc.isValid = function (value, strictMode) {
|
||||
cc.isValid = (value, strictMode) => {
|
||||
if (typeof value === 'object') {
|
||||
return !!value && !(value._objFlags & (strictMode ? (Destroyed | ToDestroy) : Destroyed));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return typeof value !== 'undefined';
|
||||
}
|
||||
};
|
||||
|
||||
if (CC_EDITOR || CC_TEST) {
|
||||
js.value(CCObject, '_willDestroy', function (obj) {
|
||||
js.value(CCObject, '_willDestroy', (obj) => {
|
||||
return !(obj._objFlags & Destroyed) && (obj._objFlags & ToDestroy) > 0;
|
||||
});
|
||||
js.value(CCObject, '_cancelDestroy', function (obj) {
|
||||
js.value(CCObject, '_cancelDestroy', (obj) => {
|
||||
obj._objFlags &= ~ToDestroy;
|
||||
js.array.fastRemove(objectsToDestroy, obj);
|
||||
});
|
||||
}
|
||||
|
||||
cc.Object = CCObject;
|
||||
export default CCObject;
|
||||
export { CCObject };
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
import EventTarget from './event/event-target';
|
||||
import eventManager from './platform/event-manager/CCEventManager';
|
||||
import ccobject from './data/object';
|
||||
import { CCObject } from './data/object';
|
||||
import game from './game';
|
||||
import Scheduler from './scheduler';
|
||||
import { autoRelease } from '../load-pipeline/auto-release-utils';
|
||||
@@ -440,7 +440,7 @@ class Director extends EventTarget {
|
||||
this._scene = null;
|
||||
|
||||
// purge destroyed nodes belongs to old scene
|
||||
ccobject._deferredDestroy();
|
||||
CCObject._deferredDestroy();
|
||||
CC_BUILD && CC_DEBUG && console.timeEnd('Destroy');
|
||||
|
||||
if (onBeforeLoadScene) {
|
||||
@@ -916,7 +916,7 @@ class Director extends EventTarget {
|
||||
// User can use this event to do things after update
|
||||
this.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
// Destroy entities that have been removed recently
|
||||
ccobject._deferredDestroy();
|
||||
CCObject._deferredDestroy();
|
||||
}
|
||||
|
||||
// Render
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import { addon } from './utils/js';
|
||||
|
||||
import renderer from '../renderer';
|
||||
import builtinResMgr from '../3d/builtin/init';
|
||||
import ProgramLib from '../renderer/core/program-lib';
|
||||
import { ProgramLib } from '../renderer/core/program-lib';
|
||||
|
||||
/**
|
||||
* @module cc
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ export class GFXUniformBlock {
|
||||
binding: number = -1;
|
||||
name: string = "";
|
||||
//instance : string;
|
||||
uniforms: GFXUniform[] = [];
|
||||
members: GFXUniform[] = [];
|
||||
};
|
||||
|
||||
export class GFXUniformSampler {
|
||||
|
||||
@@ -897,15 +897,15 @@ export function WebGLCmdFuncCreateShader(device: WebGLGFXDevice, gpuShader: WebG
|
||||
binding: block.binding,
|
||||
name: block.name,
|
||||
size: 0,
|
||||
glUniforms: new Array<WebGLGPUUniform>(block.uniforms.length),
|
||||
glUniforms: new Array<WebGLGPUUniform>(block.members.length),
|
||||
isUniformPackage: true,
|
||||
buffer: null,
|
||||
};
|
||||
|
||||
gpuShader.glBlocks[i] = glBlock;
|
||||
|
||||
for (let u = 0; u < block.uniforms.length; ++u) {
|
||||
let uniform = block.uniforms[u];
|
||||
for (let u = 0; u < block.members.length; ++u) {
|
||||
let uniform = block.members[u];
|
||||
let glType = GFXTypeToWebGLType(uniform.type);
|
||||
let stride = WebGLGetTypeSize(glType);
|
||||
let size = stride * uniform.count;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { RenderFlow, RenderFlowInfo } from "../render-flow";
|
||||
import { RenderPipeline } from "../render-pipeline";
|
||||
import { TestStage } from "./test-stage";
|
||||
// import { TestStage } from "./test-stage";
|
||||
import { TestMaterialStage } from "./test-material-stage";
|
||||
|
||||
export enum ForwardStagePriority {
|
||||
FORWARD = 0,
|
||||
@@ -33,8 +34,8 @@ export class ForwardFlow extends RenderFlow {
|
||||
});
|
||||
*/
|
||||
|
||||
this.createStage<TestStage>(TestStage, {
|
||||
name: "TestStage",
|
||||
this.createStage<TestMaterialStage>(TestMaterialStage, {
|
||||
name: "TestMaterialStage",
|
||||
priority: ForwardStagePriority.FORWARD,
|
||||
framebuffer: mainWindow.framebuffer,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import { Material } from '../../3d/assets/material';
|
||||
import { GFXCommandBuffer } from '../../gfx/command-buffer';
|
||||
import { GFXBufferTextureCopy, GFXCommandBufferType, GFXFormat,
|
||||
GFXTextureFlagBit, GFXTextureType, GFXTextureUsageBit, GFXTextureViewType } from '../../gfx/define';
|
||||
import { GFXFramebuffer } from '../../gfx/framebuffer';
|
||||
import { GFXInputAssembler } from '../../gfx/input-assembler';
|
||||
import { GFXTexture } from '../../gfx/texture';
|
||||
import { GFXTextureView } from '../../gfx/texture-view';
|
||||
import { RenderFlow } from '../render-flow';
|
||||
import { RenderStage, RenderStageInfo } from '../render-stage';
|
||||
import { RenderView } from '../render-view';
|
||||
|
||||
export class TestMaterialStage extends RenderStage {
|
||||
|
||||
private _texture: GFXTexture | null = null;
|
||||
private _texView: GFXTextureView | null = null;
|
||||
private _material: Material = new Material();
|
||||
|
||||
constructor(flow: RenderFlow) {
|
||||
super(flow);
|
||||
}
|
||||
|
||||
public initialize(info: RenderStageInfo): boolean {
|
||||
|
||||
if (info.name !== undefined) {
|
||||
this._name = info.name;
|
||||
}
|
||||
|
||||
this._priority = info.priority;
|
||||
this._framebuffer = info.framebuffer;
|
||||
if (!this._framebuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._cmdBuff = this._device.createCommandBuffer({
|
||||
allocator: this._device.commandAllocator,
|
||||
type: GFXCommandBufferType.PRIMARY,
|
||||
});
|
||||
|
||||
// load texture
|
||||
const imgElms = this._device.canvas.getElementsByTagName('img');
|
||||
if (imgElms.length) {
|
||||
if (!this.loadTexture(<HTMLImageElement>imgElms[0])) {
|
||||
console.error('Load texture failed.');
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
console.error('Not found image, load texture failed.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
|
||||
if (this._texView) {
|
||||
this._texView.destroy();
|
||||
this._texView = null;
|
||||
}
|
||||
|
||||
if (this._texture) {
|
||||
this._texture.destroy();
|
||||
this._texture = null;
|
||||
}
|
||||
|
||||
if (this._cmdBuff) {
|
||||
this._cmdBuff.destroy();
|
||||
this._cmdBuff = null;
|
||||
}
|
||||
}
|
||||
|
||||
public render(view: RenderView) {
|
||||
if (!this._material.inited) {
|
||||
// material
|
||||
this._material.effectName = 'test'; // parsed-effect file is embedded in cocos/3d/builtin/effects.js
|
||||
const handle1 = this._material.passes[0].getPropertyHandle('u_sampler');
|
||||
this._material.setProperty(handle1, this._texView);
|
||||
const handle2 = this._material.passes[0].getPropertyHandle('u_color');
|
||||
this._material.setProperty(handle2, cc.color('#ffffff'));
|
||||
this._material.inited = true;
|
||||
}
|
||||
const cmdBuff = <GFXCommandBuffer>this._cmdBuff;
|
||||
this._renderArea.width = view.width;
|
||||
this._renderArea.height = view.height;
|
||||
|
||||
cmdBuff.begin();
|
||||
cmdBuff.beginRenderPass(<GFXFramebuffer>this._framebuffer, this._renderArea, this._clearColors,
|
||||
this._clearDepth, this._clearStencil);
|
||||
|
||||
cmdBuff.bindPipelineState(this._material.passes[0].pipelineState);
|
||||
cmdBuff.bindBindingLayout(this._material.passes[0].bindingLayout);
|
||||
|
||||
cmdBuff.bindInputAssembler(<GFXInputAssembler>this._pipeline.quadIA);
|
||||
cmdBuff.draw(<GFXInputAssembler>this._pipeline.quadIA);
|
||||
cmdBuff.endRenderPass();
|
||||
cmdBuff.end();
|
||||
|
||||
this._device.queue.submit([cmdBuff]);
|
||||
}
|
||||
|
||||
private loadTexture(image: HTMLImageElement): boolean {
|
||||
this._texture = this._device.createTexture({
|
||||
type: GFXTextureType.TEX2D,
|
||||
usage: GFXTextureUsageBit.SAMPLED | GFXTextureUsageBit.TRANSFER_DST,
|
||||
format: GFXFormat.RGBA8,
|
||||
width: image.width,
|
||||
height: image.height,
|
||||
flags: GFXTextureFlagBit.NONE,
|
||||
});
|
||||
|
||||
if (!this._texture) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._texView = this._device.createTextureView({
|
||||
texture: this._texture,
|
||||
type: GFXTextureViewType.TV2D,
|
||||
format: GFXFormat.RGBA8,
|
||||
});
|
||||
|
||||
if (!this._texView) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const region: GFXBufferTextureCopy = {
|
||||
buffOffset: 0,
|
||||
buffStride: 0,
|
||||
buffTexHeight: 0,
|
||||
texOffset: { x: 0, y: 0, z: 0 },
|
||||
texExtent: { width: image.width, height: image.height, depth: 1 },
|
||||
texSubres: { baseMipLevel: 0, levelCount: 1, baseArrayLayer: 0, layerCount: 1 },
|
||||
};
|
||||
|
||||
this._device.copyImageSourceToTexture(image, this._texture, [region]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -90,11 +90,11 @@ export class TestStage extends RenderStage {
|
||||
name: "test",
|
||||
stages: [vsStage, fsStage],
|
||||
blocks: [{
|
||||
binding: 0, name: "Global", uniforms: [
|
||||
binding: 0, name: "Global", members: [
|
||||
{ name: "u_matWorldViewProj", type: GFXType.MAT4, count: 1 },
|
||||
]
|
||||
}, {
|
||||
binding: 5, name: "UBO", uniforms: [
|
||||
binding: 5, name: "UBO", members: [
|
||||
{ name: "u_color", type: GFXType.FLOAT4, count: 1 },
|
||||
]
|
||||
}],
|
||||
|
||||
@@ -6,7 +6,7 @@ import { intersect } from '../../3d/geom-utils';
|
||||
|
||||
import enums from '../enums';
|
||||
import View from './view';
|
||||
import ProgramLib from './program-lib';
|
||||
import { ProgramLib } from './program-lib';
|
||||
import { RenderQueue } from './constants';
|
||||
|
||||
let _m3_tmp = mat3.create();
|
||||
|
||||
+87
-193
@@ -1,13 +1,13 @@
|
||||
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
import { EffectAsset, PropertyInfo, ShaderInfo, UniformInfo } from '../../3d/assets/effect-asset';
|
||||
import { BlockMember, EffectAsset, PropertyInfo, SamplerInfo, ShaderInfo } from '../../3d/assets/effect-asset';
|
||||
import { CCObject } from '../../core/data';
|
||||
import { Color, Mat4, Vec2, Vec3, Vec4 } from '../../core/value-types';
|
||||
import { GFXType } from '../../gfx/define';
|
||||
import { RenderPassStage } from '../../pipeline/render-pipeline';
|
||||
import Texture2D from '../gfx/texture-2d';
|
||||
import TextureCube from '../gfx/texture-cube';
|
||||
import { Pass } from './pass';
|
||||
import Technique from './technique';
|
||||
import { Pass, PassInfo } from './pass';
|
||||
|
||||
const _typeMap = {
|
||||
[GFXType.INT]: 'Number',
|
||||
@@ -27,143 +27,12 @@ const _typeMap = {
|
||||
default: CCObject,
|
||||
};
|
||||
const getInstanceType = (t: number | string) => _typeMap[t] || _typeMap.default;
|
||||
const typeCheck = (value: any, type: number) => {
|
||||
const instanceType = getInstanceType(type);
|
||||
switch (typeof value) {
|
||||
case 'object': return (value === null) || (value instanceof instanceType);
|
||||
case 'number': return instanceType === 'Number';
|
||||
case 'boolean': return instanceType === 'Boolean';
|
||||
default: return false;
|
||||
}
|
||||
};
|
||||
|
||||
let _globalTechLod = 600;
|
||||
|
||||
type PropValue = number | boolean | Vec2 | Vec3 | Vec4 | Color | Mat4 | Texture2D | TextureCube | null;
|
||||
interface PropertyMap { [name: string]: { type: number, value: PropValue }; }
|
||||
interface DefineMap { [name: string]: number | boolean; }
|
||||
interface DependencyMap { [name: string]: string; }
|
||||
|
||||
interface ProgramMap { [name: string]: ShaderInfo; }
|
||||
|
||||
class Effect {
|
||||
public static parseEffect(effect: EffectAsset, programs: ProgramMap) { return new Effect(); }
|
||||
public static parseForInspector(effect: EffectAsset) { return { props: {}, defines: {} }; }
|
||||
public static setGlobalLod(lod: number) { _globalTechLod = lod; }
|
||||
|
||||
protected _name: string = '';
|
||||
protected _techniques: Technique[] = [];
|
||||
protected _properties: PropertyMap = {};
|
||||
protected _defines: DefineMap = {};
|
||||
protected _dependencies: DependencyMap = {};
|
||||
|
||||
protected _maxLOD: number = 0;
|
||||
protected _activeTechIdx: number = 0;
|
||||
protected _programs: ProgramMap = {};
|
||||
|
||||
constructor(
|
||||
name: string = '',
|
||||
techniques: Technique[] = [new Technique()],
|
||||
programs: ProgramMap = {},
|
||||
properties: PropertyMap = {},
|
||||
lod = -1
|
||||
) {
|
||||
this._name = name;
|
||||
this._techniques = techniques;
|
||||
this._properties = properties;
|
||||
this._programs = programs;
|
||||
this._defines = {};
|
||||
this._dependencies = {};
|
||||
this._maxLOD = lod;
|
||||
this.selectTechnique();
|
||||
}
|
||||
|
||||
set LOD(lod: number) {
|
||||
if (lod === this._maxLOD) {
|
||||
return;
|
||||
}
|
||||
this._maxLOD = lod;
|
||||
this.selectTechnique();
|
||||
}
|
||||
|
||||
public clear() {
|
||||
this._techniques.length = 0;
|
||||
this._properties = {};
|
||||
this._defines = {};
|
||||
this._dependencies = {};
|
||||
}
|
||||
|
||||
public getTechnique(index: number) {
|
||||
if (index < 0 || index >= this._techniques.length) { return null; }
|
||||
return this._techniques[index];
|
||||
}
|
||||
|
||||
public getProperty(name: string) {
|
||||
if (!this._properties[name]) {
|
||||
console.warn(`Failed to get property ${name}, property not found.`);
|
||||
return null;
|
||||
}
|
||||
return this._properties[name].value;
|
||||
}
|
||||
|
||||
public setProperty(name: string, value: any) {
|
||||
const prop = this._properties[name];
|
||||
if (!prop) {
|
||||
console.warn(`Failed to set property ${name}, property not found.`);
|
||||
return;
|
||||
} else if (!typeCheck(value, prop.type)) {
|
||||
console.warn(`Failed to set property ${name}, property type mismatch.`);
|
||||
return;
|
||||
}
|
||||
this._properties[name].value = value;
|
||||
}
|
||||
|
||||
public getDefine(name: string) {
|
||||
const def = this._defines[name];
|
||||
if (def !== undefined) { return def; }
|
||||
console.warn(`Failed to get define ${name}, define not found.`);
|
||||
return null;
|
||||
}
|
||||
|
||||
public define(name: string, value: number | boolean) {
|
||||
if (this._defines[name] !== undefined) {
|
||||
this._defines[name] = value;
|
||||
} else {
|
||||
console.warn(`Failed to set define ${name}, define not found.`);
|
||||
}
|
||||
}
|
||||
|
||||
public extractDefines(out = {}) {
|
||||
return Object.assign(out, this._defines);
|
||||
}
|
||||
|
||||
public extractDependencies(out = {}) {
|
||||
return Object.assign(out, this._dependencies);
|
||||
}
|
||||
|
||||
public getActiveTechnique() {
|
||||
return this._techniques[this._activeTechIdx];
|
||||
}
|
||||
|
||||
public selectTechnique() {
|
||||
const lod = this._maxLOD === -1 ? _globalTechLod : this._maxLOD;
|
||||
this._activeTechIdx = 0;
|
||||
for (let i = 0; i < this._techniques.length; i++) {
|
||||
if (this._techniques[i].LOD <= lod) {
|
||||
this._activeTechIdx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// defines
|
||||
this._defines = {};
|
||||
this._techniques[this._activeTechIdx].passes.forEach((pass) =>
|
||||
this._programs[pass.programName].defines.forEach((def) =>
|
||||
this._defines[def.name] = def.type === 'number' ? 0 : false));
|
||||
// extensions
|
||||
this._dependencies = {};
|
||||
this._techniques[this._activeTechIdx].passes.forEach((pass) => this._programs[pass.programName].extensions
|
||||
.filter((ext) => ext.define).forEach((ext) => this._dependencies[ext.define] = ext.name));
|
||||
}
|
||||
export interface PropertyMap { [name: string]: { type: number, value: any }; }
|
||||
export interface DefineMap { [name: string]: number | boolean; }
|
||||
export interface EffectInfo {
|
||||
techIdx?: number;
|
||||
defines?: DefineMap;
|
||||
}
|
||||
|
||||
type DefaultValue = number | boolean | number[] | null;
|
||||
@@ -187,14 +56,20 @@ const _ctorMap = {
|
||||
};
|
||||
const getInstanceCtor = (t: number | string) => _ctorMap[getInstanceType(t)];
|
||||
|
||||
const getInvolvedPrograms = (effect: EffectAsset) => {
|
||||
const programs: ProgramMap = {};
|
||||
const getInvolvedPrograms = (effect: EffectAsset, techIdx?: number) => {
|
||||
const programs: Record<string, ShaderInfo> = {};
|
||||
const lib = cc.game._programLib;
|
||||
effect.techniques.forEach((tech) => {
|
||||
tech.passes.forEach((pass) => {
|
||||
if (techIdx) {
|
||||
effect.techniques[techIdx].passes.forEach((pass) => {
|
||||
programs[pass.program] = lib.getTemplate(pass.program);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
effect.techniques.forEach((tech) => {
|
||||
tech.passes.forEach((pass) => {
|
||||
programs[pass.program] = lib.getTemplate(pass.program);
|
||||
});
|
||||
});
|
||||
}
|
||||
return programs;
|
||||
};
|
||||
|
||||
@@ -204,31 +79,55 @@ interface ExtractedPropInfo {
|
||||
value: number | boolean | object;
|
||||
defines: string[];
|
||||
displayName?: string;
|
||||
tech: number;
|
||||
pass: number;
|
||||
}
|
||||
const parseProperties = (() => {
|
||||
function genPropInfo(propInfo: PropertyInfo, uniformInfo: UniformInfo): ExtractedPropInfo {
|
||||
interface UniformInfo { type: number; defines: string[]; }
|
||||
function genPropInfo(propInfo: PropertyInfo, uniformInfo: UniformInfo, tech: number, pass: number)
|
||||
: ExtractedPropInfo {
|
||||
const type = propInfo.type || uniformInfo.type;
|
||||
return {
|
||||
type,
|
||||
type, tech, pass,
|
||||
instanceType: getInstanceType(type),
|
||||
value: getInstanceCtor(type)(propInfo.value),
|
||||
displayName: propInfo.displayName,
|
||||
defines: uniformInfo.defines,
|
||||
};
|
||||
}
|
||||
return (effect: EffectAsset, programs: ProgramMap) => {
|
||||
const props: { [name: string]: ExtractedPropInfo } = {};
|
||||
function findUniformInfo(program: ShaderInfo, name: string) {
|
||||
for (const b of program.blocks) {
|
||||
const i = b.members.find((u) => u.name === name);
|
||||
if (i) { return Object.assign({ defines: b.defines }, i); }
|
||||
}
|
||||
return program.samplers.find((u) => u.name === name);
|
||||
}
|
||||
function findPassIdx(effect: EffectAsset, programName: string) { // just a heuristic
|
||||
effect.techniques.forEach((tech, i) => {
|
||||
tech.passes.forEach((pass, j) => {
|
||||
if (pass.program === programName) {
|
||||
return [ i, j ];
|
||||
}
|
||||
});
|
||||
});
|
||||
return [ 0, 0 ];
|
||||
}
|
||||
return (effect: EffectAsset, programs: Record<string, ShaderInfo>) => {
|
||||
const props: Record<string, ExtractedPropInfo> = {};
|
||||
for (const prop of Object.keys(effect.properties)) {
|
||||
const propInfo = effect.properties[prop];
|
||||
let uniformInfo: UniformInfo | undefined;
|
||||
let techIdx = 0;
|
||||
let passIdx = 0;
|
||||
// always try getting the type from shaders first
|
||||
if (propInfo.tech !== undefined && propInfo.pass !== undefined) {
|
||||
const pname = effect.techniques[propInfo.tech].passes[propInfo.pass].program;
|
||||
uniformInfo = programs[pname].uniforms.find((u) => u.name === prop);
|
||||
const p = effect.techniques[propInfo.tech].passes[propInfo.pass].program;
|
||||
uniformInfo = findUniformInfo(programs[p], prop);
|
||||
techIdx = propInfo.tech; passIdx = propInfo.pass;
|
||||
} else {
|
||||
for (const p of Object.keys(programs)) {
|
||||
uniformInfo = programs[p].uniforms.find((u) => u.name === prop);
|
||||
if (uniformInfo) { break; }
|
||||
uniformInfo = findUniformInfo(programs[p], prop);
|
||||
if (uniformInfo) { [techIdx, passIdx] = findPassIdx(effect, p); break; }
|
||||
}
|
||||
}
|
||||
// the property is not defined in all the shaders used in techs
|
||||
@@ -236,57 +135,53 @@ const parseProperties = (() => {
|
||||
console.warn(`illegal property: ${prop}`);
|
||||
continue;
|
||||
}
|
||||
// TODO: different param with same name for different passes
|
||||
props[prop] = genPropInfo(propInfo, uniformInfo);
|
||||
props[prop] = genPropInfo(propInfo, uniformInfo, techIdx, passIdx);
|
||||
}
|
||||
return props;
|
||||
};
|
||||
})();
|
||||
|
||||
Effect.parseEffect = (effect: EffectAsset) => {
|
||||
// techniques
|
||||
const techNum = effect.techniques.length;
|
||||
const techniques = new Array<Technique>(techNum);
|
||||
const programs = getInvolvedPrograms(effect);
|
||||
for (let j = 0; j < techNum; ++j) {
|
||||
const tech = effect.techniques[j];
|
||||
const passNum = tech.passes.length;
|
||||
const passes: Pass[] = new Array(passNum);
|
||||
for (let k = 0; k < passNum; ++k) {
|
||||
const passInfo = tech.passes[k];
|
||||
passInfo.device = cc.game._gfxDevice;
|
||||
passInfo.bindingLayoutInfo = programs[passInfo.program].uniforms.map((u) => {
|
||||
return { name: u.name, type: u.bindingType, binding: u.binding };
|
||||
});
|
||||
passes[k] = Pass.create(passInfo);
|
||||
}
|
||||
techniques[j] = new Technique(tech.queue, tech.priority, tech.lod, passes);
|
||||
}
|
||||
// uniforms
|
||||
const props = parseProperties(effect, programs);
|
||||
const uniforms = {};
|
||||
for (const pn of Object.keys(programs)) {
|
||||
programs[pn].uniforms.forEach((u) => {
|
||||
const prop = props[u.name];
|
||||
uniforms[u.name] = {
|
||||
type: prop ? prop.type : u.type,
|
||||
value: prop ? prop.value : getInstanceCtor(u.type)(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return new Effect(effect.name, techniques, programs, uniforms);
|
||||
const traverseUniforms = (shaderInfo: ShaderInfo, fn: (u: BlockMember | SamplerInfo) => any) => {
|
||||
shaderInfo.blocks.forEach((b) => b.members.forEach(fn));
|
||||
shaderInfo.samplers.forEach(fn);
|
||||
};
|
||||
|
||||
if (CC_EDITOR) {
|
||||
Effect.parseForInspector = (effect: EffectAsset) => {
|
||||
export class Effect {
|
||||
public static parseEffect(effect: EffectAsset, info?: EffectInfo) {
|
||||
// techniques
|
||||
const { techIdx, defines } = info || <EffectInfo>{};
|
||||
const programs = getInvolvedPrograms(effect, techIdx || 0);
|
||||
const tech = effect.techniques[techIdx || 0];
|
||||
const passNum = tech.passes.length;
|
||||
const passes: Pass[] = new Array(passNum);
|
||||
const props = parseProperties(effect, programs);
|
||||
for (let k = 0; k < passNum; ++k) {
|
||||
const passInfo = <PassInfo>tech.passes[k];
|
||||
const uniforms: PropertyMap = passInfo.uniforms = {};
|
||||
traverseUniforms(programs[passInfo.program], (u) => {
|
||||
const prop = props[u.name];
|
||||
uniforms[u.name] = {
|
||||
type: prop ? prop.type : u.type,
|
||||
value: prop ? prop.value : getInstanceCtor(u.type)(),
|
||||
};
|
||||
});
|
||||
passInfo.shader = cc.game._programLib.getGFXShader(passInfo.program, defines || {});
|
||||
passInfo.renderPass = cc.director.root.pipeline.getRenderPass(passInfo.stage || RenderPassStage.FORWARD);
|
||||
passInfo.blocks = programs[passInfo.program].blocks;
|
||||
passInfo.samplers = programs[passInfo.program].samplers;
|
||||
const pass = new Pass(cc.game._gfxDevice);
|
||||
pass.initialize(passInfo);
|
||||
passes[k] = pass;
|
||||
}
|
||||
return passes;
|
||||
}
|
||||
public static parseForInspector(effect: EffectAsset) {
|
||||
const programs = getInvolvedPrograms(effect);
|
||||
const props = parseProperties(effect, programs);
|
||||
const defines: { [name: string]: ExtractedPropInfo } = {};
|
||||
const defines: Record<string, object> = {};
|
||||
for (const pn of Object.keys(programs)) {
|
||||
programs[pn].defines.forEach((define) => {
|
||||
defines[define.name] = {
|
||||
type: (define.type === 'number' ? GFXType.INT : GFXType.BOOL),
|
||||
instanceType: getInstanceType(define.type),
|
||||
value: getInstanceCtor(define.type)(),
|
||||
defines: define.defines,
|
||||
@@ -294,8 +189,7 @@ if (CC_EDITOR) {
|
||||
});
|
||||
}
|
||||
return { props, defines };
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default Effect;
|
||||
cc.Effect = Effect;
|
||||
|
||||
+184
-38
@@ -1,43 +1,190 @@
|
||||
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
import { GFXBinding } from '../../gfx/binding-layout';
|
||||
import { BlockInfo, SamplerInfo } from '../../3d/assets/effect-asset';
|
||||
import { color4, mat2, mat3, mat4, vec2, vec3, vec4 } from '../../core/vmath';
|
||||
import { GFXBindingLayout } from '../../gfx/binding-layout';
|
||||
import { GFXBuffer } from '../../gfx/buffer';
|
||||
import { GFXPrimitiveMode } from '../../gfx/define';
|
||||
import { GFXBindingType, GFXBufferUsageBit, GFXMemoryUsageBit, GFXPrimitiveMode, GFXType } from '../../gfx/define';
|
||||
import { GFXDevice } from '../../gfx/device';
|
||||
import { GFXPipelineLayout } from '../../gfx/pipeline-layout';
|
||||
import { GFXBlendState, GFXBlendTarget, GFXDepthStencilState,
|
||||
GFXInputState, GFXPipelineState, GFXRasterizerState } from '../../gfx/pipeline-state';
|
||||
import { GFXRenderPass } from '../../gfx/render-pass';
|
||||
import { GFXSampler } from '../../gfx/sampler';
|
||||
import { PassStage } from './constants';
|
||||
import { GFXShader } from '../../gfx/shader';
|
||||
import { RenderPassStage } from '../../pipeline/render-pipeline';
|
||||
import { PropertyMap } from './effect';
|
||||
|
||||
export interface PassInfo {
|
||||
// generated part
|
||||
device: GFXDevice;
|
||||
bindingLayoutInfo: GFXBinding[];
|
||||
export interface PassInfoBase {
|
||||
program: string;
|
||||
// effect-writer part
|
||||
primitive?: GFXPrimitiveMode;
|
||||
stage?: PassStage;
|
||||
stage?: RenderPassStage;
|
||||
rasterizerState?: GFXRasterizerState;
|
||||
depthStencilState?: GFXDepthStencilState;
|
||||
blendState?: GFXBlendState;
|
||||
}
|
||||
export interface PassInfo extends PassInfoBase {
|
||||
// generated part
|
||||
blocks: BlockInfo[];
|
||||
samplers: SamplerInfo[];
|
||||
shader: GFXShader;
|
||||
renderPass: GFXRenderPass;
|
||||
uniforms: PropertyMap;
|
||||
}
|
||||
|
||||
const _type2fn = {
|
||||
[GFXType.INT]: (a: Float32Array, v: any) => a[0] = v,
|
||||
[GFXType.INT2]: (a: Float32Array, v: any) => vec2.array(a, v),
|
||||
[GFXType.INT3]: (a: Float32Array, v: any) => vec3.array(a, v),
|
||||
[GFXType.INT4]: (a: Float32Array, v: any) => vec4.array(a, v),
|
||||
[GFXType.FLOAT]: (a: Float32Array, v: any) => a[0] = v,
|
||||
[GFXType.FLOAT2]: (a: Float32Array, v: any) => vec2.array(a, v),
|
||||
[GFXType.FLOAT3]: (a: Float32Array, v: any) => vec3.array(a, v),
|
||||
[GFXType.FLOAT4]: (a: Float32Array, v: any) => vec4.array(a, v),
|
||||
[GFXType.COLOR4]: (a: Float32Array, v: any) => color4.array(a, v),
|
||||
[GFXType.MAT2]: (a: Float32Array, v: any) => mat2.array(a, v),
|
||||
[GFXType.MAT3]: (a: Float32Array, v: any) => mat3.array(a, v),
|
||||
[GFXType.MAT4]: (a: Float32Array, v: any) => mat4.array(a, v),
|
||||
};
|
||||
|
||||
const bindingMask = 0x0fff0000;
|
||||
const indexMask = 0x0000ffff;
|
||||
const genHandle = (binding: number, index: number = 0) => (binding << 16) | index;
|
||||
const parseHandle = (handle: number) => [(handle & bindingMask) >> 16, handle & indexMask];
|
||||
|
||||
interface Block {
|
||||
buffer: ArrayBuffer;
|
||||
views: Float32Array[];
|
||||
}
|
||||
|
||||
export class Pass {
|
||||
public static create(info: PassInfo) {
|
||||
const pass = new Pass();
|
||||
const device = pass._device = info.device;
|
||||
pass._programName = info.program;
|
||||
pass._stage = info.stage || PassStage.DEFAULT;
|
||||
// internal resources
|
||||
protected _pipelineState: GFXPipelineState | null = null;
|
||||
protected _pipelineLayout: GFXPipelineLayout | null = null;
|
||||
protected _bindingLayout: GFXBindingLayout | null = null;
|
||||
protected _buffers: GFXBuffer[] = [];
|
||||
protected _samplers: GFXSampler[] = [];
|
||||
// internal data
|
||||
protected _programName: string = '';
|
||||
protected _primitive: GFXPrimitiveMode = GFXPrimitiveMode.TRIANGLE_LIST;
|
||||
protected _stage: RenderPassStage = RenderPassStage.FORWARD;
|
||||
protected _handleMap: Record<string, number> = {};
|
||||
protected _typeMap: Record<number, GFXType> = {};
|
||||
protected _blocks: Block[] = [];
|
||||
// external references
|
||||
protected _device: GFXDevice;
|
||||
protected _shader: GFXShader | null = null;
|
||||
protected _renderPass: GFXRenderPass | null = null;
|
||||
|
||||
public constructor(device: GFXDevice) {
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public initialize(info: PassInfo) {
|
||||
this._programName = info.program;
|
||||
// pipeline state
|
||||
const shader = device.createShader({ name: info.program, stages: [] });
|
||||
if (!shader) { console.error('create shader failed'); return pass; }
|
||||
const bindingLayout = device.createBindingLayout({ bindings: info.bindingLayoutInfo });
|
||||
if (!bindingLayout) { console.error('create binding layout failed'); return pass; }
|
||||
const layout = device.createPipelineLayout({ layouts: [bindingLayout] });
|
||||
if (!layout) { console.error('create pipeline layout failed'); return pass; }
|
||||
const renderPass = cc.director.root.pipeline.getRenderPass(pass._stage);
|
||||
if (!renderPass) { console.error('create render pass failed'); return pass; }
|
||||
const device = this._device;
|
||||
const bindings = info.blocks.map((u) =>
|
||||
({ name: u.name, binding: u.binding, type: GFXBindingType.UNIFORM_BUFFER })
|
||||
).concat(info.samplers.map((u) =>
|
||||
({ name: u.name, binding: u.binding, type: GFXBindingType.SAMPLER })
|
||||
));
|
||||
this._bindingLayout = device.createBindingLayout({ bindings });
|
||||
if (!this._bindingLayout) { console.error('create binding layout failed'); return; }
|
||||
this._pipelineLayout = device.createPipelineLayout({ layouts: [this._bindingLayout] });
|
||||
if (!this._pipelineLayout) { console.error('create pipeline layout failed'); return; }
|
||||
this._shader = info.shader;
|
||||
this._renderPass = info.renderPass;
|
||||
this.createPipelineState(info);
|
||||
|
||||
for (const u of info.blocks) {
|
||||
// create gfx buffer resource
|
||||
const buffer = device.createBuffer({
|
||||
usage: GFXBufferUsageBit.UNIFORM,
|
||||
memUsage: GFXMemoryUsageBit.HOST | GFXMemoryUsageBit.DEVICE,
|
||||
size: u.size,
|
||||
stride: 1, // N/A for blocks
|
||||
});
|
||||
if (buffer) {
|
||||
this._bindingLayout.bindBuffer(u.binding, buffer);
|
||||
this._buffers[u.binding] = buffer;
|
||||
} else {
|
||||
console.error('create buffer failed.');
|
||||
return;
|
||||
}
|
||||
// buffer data processing system
|
||||
const block: Block = this._blocks[u.binding] = {
|
||||
buffer: new ArrayBuffer(u.size),
|
||||
views: [],
|
||||
};
|
||||
u.members.reduce((acc, cur, idx) => {
|
||||
// create property-specific buffer views
|
||||
const view = new Float32Array(block.buffer, acc, cur.size / Float32Array.BYTES_PER_ELEMENT);
|
||||
block.views.push(view);
|
||||
// store handle map, type and initial value
|
||||
const handle = this._handleMap[cur.name] = genHandle(u.binding, idx);
|
||||
const inf = info.uniforms[cur.name];
|
||||
this._typeMap[handle] = inf.type;
|
||||
_type2fn[inf.type](view, inf.value);
|
||||
// proceed the counter
|
||||
return acc + cur.size;
|
||||
}, 0); // === u.size
|
||||
buffer.update(block.buffer);
|
||||
}
|
||||
for (const u of info.samplers) {
|
||||
this._handleMap[u.name] = genHandle(u.binding);
|
||||
const sampler = device.createSampler({
|
||||
name: u.name,
|
||||
// TODO: specify filter modes in effect
|
||||
});
|
||||
if (sampler) {
|
||||
this._bindingLayout.bindSampler(u.binding, sampler);
|
||||
this._samplers.push(sampler);
|
||||
} else {
|
||||
console.error('create sampler failed.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getPropertyHandle(name: string) {
|
||||
return this._handleMap[name];
|
||||
}
|
||||
|
||||
public setProperty(handle: number, value: any) {
|
||||
const [ binding, idx ] = parseHandle(handle);
|
||||
const block = this._blocks[binding];
|
||||
if (block) {
|
||||
const type = this._typeMap[handle];
|
||||
_type2fn[type](block.views[idx], value);
|
||||
this._buffers[binding].update(block.buffer);
|
||||
} else if (this._bindingLayout) {
|
||||
this._bindingLayout.bindTextureView(binding, value);
|
||||
this._bindingLayout.update();
|
||||
}
|
||||
}
|
||||
|
||||
public setStates(info: PassInfoBase) {
|
||||
if (this._pipelineState) { this._pipelineState.destroy(); }
|
||||
this.createPipelineState(info);
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
if (this._buffers) { this._buffers.forEach((b) => b.destroy()); this._buffers.length = 0; }
|
||||
if (this._samplers) { this._samplers.forEach((b) => b.destroy()); this._samplers.length = 0; }
|
||||
if (this._bindingLayout) { this._bindingLayout.destroy(); this._bindingLayout = null; }
|
||||
if (this._pipelineLayout) { this._pipelineLayout.destroy(); this._pipelineLayout = null; }
|
||||
if (this._pipelineState) { this._pipelineState.destroy(); this._pipelineState = null; }
|
||||
}
|
||||
|
||||
protected createPipelineState(info: PassInfoBase) {
|
||||
if (info.primitive) { this._primitive = info.primitive; }
|
||||
if (info.stage) { this._stage = info.stage; }
|
||||
|
||||
if (!this._shader || !this._renderPass || !this._pipelineLayout) {
|
||||
console.error('gfx resouces incomplete, create pipeline state failed.');
|
||||
return null;
|
||||
}
|
||||
const bs = new GFXBlendState();
|
||||
if (info.blendState) {
|
||||
const bsInfo = Object.assign({}, info.blendState);
|
||||
@@ -48,24 +195,23 @@ export class Pass {
|
||||
delete bsInfo.targets;
|
||||
Object.assign(bs, bsInfo);
|
||||
}
|
||||
|
||||
pass._pipelineState = device.createPipelineState({
|
||||
primitive: info.primitive || GFXPrimitiveMode.TRIANGLE_LIST,
|
||||
rs: Object.assign(new GFXRasterizerState(), info.rasterizerState),
|
||||
dss: Object.assign(new GFXDepthStencilState(), info.rasterizerState),
|
||||
is: new GFXInputState(), bs,
|
||||
shader, layout, renderPass,
|
||||
});
|
||||
return pass;
|
||||
const stateInfo = {
|
||||
primitive: info.primitive || this._primitive,
|
||||
rs: Object.assign(new GFXRasterizerState(), info.rasterizerState),
|
||||
dss: Object.assign(new GFXDepthStencilState(), info.depthStencilState),
|
||||
is: new GFXInputState(), bs,
|
||||
shader: this._shader,
|
||||
layout: this._pipelineLayout,
|
||||
renderPass: this._renderPass,
|
||||
};
|
||||
if (this._pipelineState) {
|
||||
this._pipelineState.initialize(stateInfo);
|
||||
} else {
|
||||
this._pipelineState = this._device.createPipelineState(stateInfo);
|
||||
}
|
||||
}
|
||||
|
||||
get programName() { return this._programName; }
|
||||
get pipelineState(): GFXPipelineState { return <GFXPipelineState>this._pipelineState; }
|
||||
|
||||
protected _device: GFXDevice | null = null;
|
||||
protected _programName: string = '';
|
||||
protected _stage: PassStage = PassStage.DEFAULT;
|
||||
protected _pipelineState: GFXPipelineState | null = null;
|
||||
protected _buffers: GFXBuffer[] = [];
|
||||
protected _samplers: GFXSampler[] = [];
|
||||
get pipelineState() { return <GFXPipelineState>this._pipelineState; }
|
||||
get bindingLayout() { return <GFXBindingLayout>this._bindingLayout; }
|
||||
}
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
import gfx from '../gfx';
|
||||
|
||||
let _shdID = 0;
|
||||
|
||||
function _generateDefines(device, defs, deps) {
|
||||
let defines = [];
|
||||
for (let def in defs) {
|
||||
let d = defs[def];
|
||||
let result = typeof d === 'number' ? d : d ? 1 : 0;
|
||||
// fallback if extension dependency not supported
|
||||
if (result && deps[def] && !device[deps[def]]) {
|
||||
console.warn(`${deps[def]} not supported on this platform, disabled ${def}`);
|
||||
result = 0;
|
||||
}
|
||||
defines.push(`#define ${def} ${result}`);
|
||||
}
|
||||
return defines.join('\n');
|
||||
}
|
||||
|
||||
function _replaceMacroNums(string, defs) {
|
||||
let cache = {};
|
||||
let tmp = string;
|
||||
for (let def in defs) {
|
||||
if (Number.isInteger(defs[def])) {
|
||||
cache[def] = defs[def];
|
||||
}
|
||||
}
|
||||
for (let def in cache) {
|
||||
let reg = new RegExp(def, 'g');
|
||||
tmp = tmp.replace(reg, cache[def]);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
function _unrollLoops(string) {
|
||||
let pattern = /#pragma for (\w+) in range\(\s*(\d+)\s*,\s*(\d+)\s*\)([\s\S]+?)#pragma endFor/g;
|
||||
function replace(match, index, begin, end, snippet) {
|
||||
let unroll = '';
|
||||
let parsedBegin = parseInt(begin);
|
||||
let parsedEnd = parseInt(end);
|
||||
if (parsedBegin.isNaN || parsedEnd.isNaN) {
|
||||
console.error('Unroll For Loops Error: begin and end of range must be an int num.');
|
||||
}
|
||||
for (let i = parsedBegin; i < parsedEnd; ++i) {
|
||||
unroll += snippet.replace(new RegExp(`{${index}}`, 'g'), i);
|
||||
}
|
||||
return unroll;
|
||||
}
|
||||
return string.replace(pattern, replace);
|
||||
}
|
||||
|
||||
export default class ProgramLib {
|
||||
/**
|
||||
* @param {gfx.Device} device
|
||||
* @param {Array} templates
|
||||
*/
|
||||
constructor(device) {
|
||||
this._device = device;
|
||||
this._precision = `precision highp float;\n`;
|
||||
this._templates = {};
|
||||
this._cache = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {string} vert
|
||||
* @param {string} frag
|
||||
* @param {Object[]} defines
|
||||
*
|
||||
* @example:
|
||||
* // this object is auto-generated from your actual shaders
|
||||
* let program = {
|
||||
* name: 'foobar',
|
||||
* vert: vertTmpl,
|
||||
* frag: fragTmpl,
|
||||
* defines: [
|
||||
* { name: 'shadow', type: 'boolean' },
|
||||
* { name: 'lightCount', type: 'number', min: 1, max: 4 }
|
||||
* ],
|
||||
* attributes: [{ name: 'a_position', type: 'vec3' }],
|
||||
* uniforms: [{ name: 'color', type: 'vec4' }],
|
||||
* extensions: [{ name: 'GL_OES_standard_derivatives', defines: ['USE_NORMAL_TEXTURE'] }],
|
||||
* };
|
||||
* programLib.define(program);
|
||||
*/
|
||||
define(prog) {
|
||||
const { name, defines } = prog;
|
||||
if (this._templates[name]) return;
|
||||
|
||||
prog.id = ++_shdID;
|
||||
prog.vert = this._precision + prog.vert;
|
||||
prog.frag = this._precision + prog.frag;
|
||||
|
||||
// calculate option mask offset
|
||||
let offset = 0;
|
||||
for (let i = 0; i < defines.length; ++i) {
|
||||
let def = defines[i];
|
||||
let cnt = 1;
|
||||
|
||||
if (def.type === 'number') {
|
||||
let range = def.range || [];
|
||||
def.min = range[0] || 0;
|
||||
def.max = range[1] || 4;
|
||||
cnt = Math.ceil(Math.log2(def.max - def.min));
|
||||
|
||||
def._map = function (value) {
|
||||
return (value - this.min) << this._offset;
|
||||
}.bind(def);
|
||||
} else { // boolean
|
||||
def._map = function (value) {
|
||||
if (value) {
|
||||
return 1 << this._offset;
|
||||
}
|
||||
return 0;
|
||||
}.bind(def);
|
||||
}
|
||||
|
||||
offset += cnt;
|
||||
def._offset = offset;
|
||||
}
|
||||
|
||||
// store it
|
||||
this._templates[name] = prog;
|
||||
}
|
||||
|
||||
getTemplate(name) {
|
||||
return this._templates[name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this library has the specified program?
|
||||
* @param {string} name
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasProgram(name) {
|
||||
return this._templates[name] !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {Object} defines
|
||||
*/
|
||||
getKey(name, defines) {
|
||||
let tmpl = this._templates[name];
|
||||
let key = 0;
|
||||
for (let i = 0; i < tmpl.defines.length; ++i) {
|
||||
let tmplDefs = tmpl.defines[i];
|
||||
let value = defines[tmplDefs.name];
|
||||
if (value === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
key |= tmplDefs._map(value);
|
||||
}
|
||||
|
||||
return key << 8 | (tmpl.id & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {Object} defines
|
||||
* @param {Object} extensions
|
||||
*/
|
||||
getProgram(name, defines, extensions, effectName) {
|
||||
let key = this.getKey(name, defines);
|
||||
let program = this._cache[key];
|
||||
if (program) {
|
||||
return program;
|
||||
}
|
||||
|
||||
// get template
|
||||
let tmpl = this._templates[name];
|
||||
let customDef = _generateDefines(this._device, defines, extensions) + '\n';
|
||||
let vert = _replaceMacroNums(tmpl.vert, defines);
|
||||
vert = customDef + _unrollLoops(vert);
|
||||
let frag = _replaceMacroNums(tmpl.frag, defines);
|
||||
frag = customDef + _unrollLoops(frag);
|
||||
|
||||
program = new gfx.Program(this._device, {
|
||||
vert,
|
||||
frag
|
||||
});
|
||||
program.link();
|
||||
if (!program._linked) {
|
||||
console.warn(`Failed to link program from effect ${effectName}.`);
|
||||
}
|
||||
this._cache[key] = program;
|
||||
|
||||
return program;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
import { DefineInfo, ShaderInfo } from '../../3d/assets/effect-asset';
|
||||
import { GFXShaderType } from '../../gfx/define';
|
||||
import { GFXDevice } from '../../gfx/device';
|
||||
import { GFXShader } from '../../gfx/shader';
|
||||
import { DefineMap } from './effect';
|
||||
|
||||
function _generateDefines(
|
||||
device: GFXDevice,
|
||||
defs: DefineMap,
|
||||
tDefs: DefineInfo[],
|
||||
deps: Record<string, string>
|
||||
) {
|
||||
const defines: string[] = [];
|
||||
for (const { name } of tDefs) {
|
||||
const d = defs[name];
|
||||
let result = (typeof d === 'number') ? d : (d ? 1 : 0);
|
||||
// fallback if extension dependency not supported
|
||||
if (result && deps[name] && !device[deps[name]]) {
|
||||
console.warn(`${deps[name]} not supported on this platform, disabled ${name}`);
|
||||
result = 0;
|
||||
}
|
||||
defines.push(`#define ${name} ${result}`);
|
||||
}
|
||||
return defines.join('\n');
|
||||
}
|
||||
|
||||
let _shdID = 0;
|
||||
interface DefineRecord extends DefineInfo {
|
||||
_map: (value: any) => number;
|
||||
_offset: number;
|
||||
}
|
||||
interface ProgramInfo extends ShaderInfo {
|
||||
id: number;
|
||||
defines: DefineRecord[];
|
||||
}
|
||||
export class ProgramLib {
|
||||
protected _device: GFXDevice;
|
||||
protected _precision: string;
|
||||
protected _templates: Record<string, ProgramInfo>;
|
||||
protected _cache: Record<string, GFXShader | null>;
|
||||
|
||||
constructor(device: GFXDevice) {
|
||||
this._device = device;
|
||||
this._precision = `precision highp float;\n`;
|
||||
this._templates = {};
|
||||
this._cache = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @example:
|
||||
* // this object is auto-generated from your actual shaders
|
||||
* let program = {
|
||||
* name: 'foobar',
|
||||
* vert: vertTmpl,
|
||||
* frag: fragTmpl,
|
||||
* defines: [
|
||||
* { name: 'shadow', type: 'boolean' },
|
||||
* { name: 'lightCount', type: 'number', range: [1, 4] }
|
||||
* ],
|
||||
* blocks: [{ name: 'Constants', binding: 0, size: 16, members: [{ name: 'color', type: 'vec4' }], defines: [] }],
|
||||
* dependencies: { 'USE_NORMAL_TEXTURE': 'OES_standard_derivatives' },
|
||||
* };
|
||||
* programLib.define(program);
|
||||
*/
|
||||
public define(prog: ShaderInfo) {
|
||||
if (this._templates[prog.name]) { return; }
|
||||
const tmpl = <ProgramInfo>Object.assign({ id: ++_shdID }, prog);
|
||||
tmpl.vert = this._precision + prog.vert;
|
||||
tmpl.frag = this._precision + prog.frag;
|
||||
|
||||
// calculate option mask offset
|
||||
let offset = 0;
|
||||
for (const def of tmpl.defines) {
|
||||
let cnt = 1;
|
||||
if (def.type === 'number') {
|
||||
const range = def.range || [0, 4];
|
||||
cnt = Math.ceil(Math.log2(range[1] - range[0]));
|
||||
def._map = ((value: number) => (value - range[0]) << def._offset);
|
||||
} else { // boolean
|
||||
def._map = ((value: any) => (value ? (1 << def._offset) : 0));
|
||||
}
|
||||
offset += cnt;
|
||||
def._offset = offset;
|
||||
}
|
||||
// store it
|
||||
this._templates[prog.name] = tmpl;
|
||||
}
|
||||
|
||||
public getTemplate(name: string) {
|
||||
return this._templates[name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this library has the specified program?
|
||||
*/
|
||||
public hasProgram(name: string) {
|
||||
return this._templates[name] !== undefined;
|
||||
}
|
||||
|
||||
public getKey(name: string, defines: DefineMap) {
|
||||
const tmpl = this._templates[name];
|
||||
let key = 0;
|
||||
for (const tmplDef of tmpl.defines) {
|
||||
const value = defines[tmplDef.name];
|
||||
if (value === undefined || !tmplDef._map) {
|
||||
continue;
|
||||
}
|
||||
key |= tmplDef._map(value);
|
||||
}
|
||||
return key << 8 | (tmpl.id & 0xff);
|
||||
}
|
||||
|
||||
public getGFXShader(name: string, defines: DefineMap = {}) {
|
||||
const key = this.getKey(name, defines);
|
||||
let program = this._cache[key];
|
||||
if (program !== undefined) {
|
||||
return program;
|
||||
}
|
||||
|
||||
// get template
|
||||
const tmpl = this._templates[name];
|
||||
const customDef = _generateDefines(this._device, defines, tmpl.defines, tmpl.dependencies) + '\n';
|
||||
const vert = customDef + tmpl.vert;
|
||||
const frag = customDef + tmpl.frag;
|
||||
|
||||
program = this._device.createShader({
|
||||
name,
|
||||
blocks: tmpl.blocks,
|
||||
samplers: tmpl.samplers,
|
||||
stages: [
|
||||
{ type: GFXShaderType.VERTEX, source: vert },
|
||||
{ type: GFXShaderType.FRAGMENT, source: frag },
|
||||
],
|
||||
});
|
||||
this._cache[key] = program;
|
||||
return program;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
import { RenderQueue } from './constants';
|
||||
import { Pass } from './pass';
|
||||
|
||||
let _genID = 0;
|
||||
|
||||
export default class Technique {
|
||||
protected _id: number = -1;
|
||||
protected _renderQueue: number = RenderQueue.OPAQUE;
|
||||
protected _priority: number = 0;
|
||||
protected _lod: number = -1;
|
||||
protected _passes: Pass[] = [];
|
||||
|
||||
constructor(renderQueue = RenderQueue.OPAQUE, priority = 0, lod = -1, passes: Pass[] = []) {
|
||||
this._id = _genID++;
|
||||
this._renderQueue = renderQueue;
|
||||
this._priority = priority;
|
||||
this._lod = lod;
|
||||
this._passes = passes;
|
||||
}
|
||||
|
||||
public setRenderQueue(renderQueue: number) {
|
||||
this._renderQueue = renderQueue;
|
||||
}
|
||||
|
||||
get LOD() {
|
||||
return this._lod;
|
||||
}
|
||||
|
||||
get renderQueue() {
|
||||
return this._renderQueue;
|
||||
}
|
||||
|
||||
get passes() {
|
||||
return this._passes;
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,7 @@ import config from './config';
|
||||
|
||||
import { RenderQueue, PassStage } from './core/constants';
|
||||
import { Pass } from './core/pass';
|
||||
import Technique from './core/technique';
|
||||
import Effect from './core/effect';
|
||||
import { Effect } from './core/effect';
|
||||
import InputAssembler from './core/input-assembler';
|
||||
import View from './core/view';
|
||||
|
||||
@@ -32,7 +31,6 @@ let renderer = {
|
||||
RenderQueue,
|
||||
PassStage,
|
||||
Pass,
|
||||
Technique,
|
||||
Effect,
|
||||
InputAssembler,
|
||||
View,
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
import * as js from '../core/utils/js';
|
||||
import IdGenerator from '../core/utils/id-generator';
|
||||
import CCObject from '../core/data/object';
|
||||
import { CCObject } from '../core/data/object';
|
||||
import { ccclass, property } from '../core/data/class-decorator';
|
||||
|
||||
const Destroying = CCObject.Flags.Destroying;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import CCObject from '../core/data/object';
|
||||
import { CCObject } from '../core/data/object';
|
||||
import { MutableForwardIterator } from '../core/utils/array';
|
||||
import { tryCatchFunctor_EDITOR } from '../core/utils/misc';
|
||||
|
||||
@@ -193,7 +193,7 @@ class ReusableInvoker extends LifeCycleInvoker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
invoke (dt) {
|
||||
if (this._neg.array.length > 0) {
|
||||
this._invoke(this._neg, dt);
|
||||
@@ -479,4 +479,4 @@ if (CC_EDITOR) {
|
||||
};
|
||||
}
|
||||
|
||||
export default ComponentScheduler;
|
||||
export default ComponentScheduler;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
import ComponentScheduler from './component-scheduler';
|
||||
import CCObject from '../core/data/object';
|
||||
import { CCObject } from '../core/data/object';
|
||||
import { Pool, array } from '../core/utils/js';
|
||||
import { tryCatchFunctor_EDITOR } from '../core/utils/misc';
|
||||
|
||||
|
||||
@@ -31,6 +31,13 @@
|
||||
<!-- <script src="./loadScene.js"></script> -->
|
||||
<script>
|
||||
function onStart() {
|
||||
const $body = document.body;
|
||||
const bcr = $body.getBoundingClientRect();
|
||||
// cc.view.setCanvasSize(bcr.width, bcr.height);
|
||||
window.addEventListener('resize', () => {
|
||||
const bcr = $body.getBoundingClientRect();
|
||||
cc.view.setCanvasSize(bcr.width, bcr.height);
|
||||
});
|
||||
|
||||
let root = cc.director.root;
|
||||
let scene = root.createScene({
|
||||
@@ -86,4 +93,4 @@
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user