mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Raw renderable (#3272)
* add renderer to ccgame, add camera component * apply stash * fix predefine.js * add renderable and rendersystem * fix format
This commit is contained in:
@@ -1,198 +1,212 @@
|
||||
import { Component } from '../ecs';
|
||||
import renderer from '../renderer';
|
||||
import { toRadian } from '../vmath';
|
||||
import RenderableComponent from './renderable-component';
|
||||
import _decorator from '../../core/data/class-decorator';
|
||||
import renderer from '../../renderer';
|
||||
import { toRadian, color4 } from '../../core/vmath';
|
||||
import Rect from '../../core/value-types/rect';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export default class CameraComponent extends Component {
|
||||
constructor() {
|
||||
super();
|
||||
@ccclass('CameraComponent')
|
||||
export default class CameraComponent extends RenderableComponent {
|
||||
|
||||
this._camera = new renderer.Camera();
|
||||
}
|
||||
onInit() {
|
||||
this._camera.setStages([
|
||||
'opaque',
|
||||
'transparent'
|
||||
]);
|
||||
this._camera.setNode(this._entity);
|
||||
constructor() {
|
||||
super();
|
||||
this._projection = 'perspective';
|
||||
this._priority = 0;
|
||||
this._fov = 45;
|
||||
this._orthoHeight = 10;
|
||||
this._near = 0.01;
|
||||
this._far = 1000.0;
|
||||
this._color = new color4(0.2, 0.3, 0.47, 1.0);
|
||||
this._depth = 1.0;
|
||||
this._stencil = 0;
|
||||
this._clearFlags = renderer.CLEAR_COLOR | renderer.CLEAR_DEPTH;
|
||||
this._rect = new Rect(0, 0, 1, 1);
|
||||
this._camera = new renderer.Camera();
|
||||
}
|
||||
|
||||
/**
|
||||
* **@schema** The projection type of the camera
|
||||
* @type {string}
|
||||
*/
|
||||
this.projection = this._projection;
|
||||
/**
|
||||
* **@schema** The camera priority
|
||||
* @type {number}
|
||||
*/
|
||||
this.priority = this._priority;
|
||||
/**
|
||||
* **@schema** The camera field of view
|
||||
* @type {number}
|
||||
*/
|
||||
this.fov = this._fov;
|
||||
/**
|
||||
* **@schema** The camera height when in orthogonal mode
|
||||
* @type {number}
|
||||
*/
|
||||
this.orthoHeight = this._orthoHeight;
|
||||
/**
|
||||
* **@schema** The near clipping distance of the camera
|
||||
* @type {number}
|
||||
*/
|
||||
this.near = this._near;
|
||||
/**
|
||||
* **@schema** The far clipping distance of the camera
|
||||
* @type {number}
|
||||
*/
|
||||
this.far = this._far;
|
||||
/**
|
||||
* **@schema** The clearing color of the camera
|
||||
* @type {color4}
|
||||
*/
|
||||
this.color = this._color;
|
||||
/**
|
||||
* **@schema** The clearing depth value of the camera
|
||||
* @type {number}
|
||||
*/
|
||||
this.depth = this._depth;
|
||||
/**
|
||||
* **@schema** The clearing stencil value of the camera
|
||||
* @type {number}
|
||||
*/
|
||||
this.stencil = this._stencil;
|
||||
/**
|
||||
* **@schema** The clearing flags of this camera
|
||||
* @type {number}
|
||||
*/
|
||||
this.clearFlags = this._clearFlags;
|
||||
/**
|
||||
* **@schema** The screen rect of the camera
|
||||
* @type {Object}
|
||||
*/
|
||||
this.rect = this._rect;
|
||||
}
|
||||
@property
|
||||
get projection() {
|
||||
return this._projection;
|
||||
}
|
||||
set projection(val) {
|
||||
this._projection = val;
|
||||
let type = renderer.PROJ_PERSPECTIVE;
|
||||
if (this._projection === 'ortho') {
|
||||
type = renderer.PROJ_ORTHO;
|
||||
}
|
||||
this._camera.setType(this._projection);
|
||||
}
|
||||
|
||||
onEnable() {
|
||||
this._app.scene.addCamera(this._camera);
|
||||
}
|
||||
@property
|
||||
get priority() {
|
||||
return this._priority;
|
||||
}
|
||||
set priority(val) {
|
||||
this._priority = val;
|
||||
this._camera.setPriority(this._priority);
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
this._app.scene.removeCamera(this._camera);
|
||||
}
|
||||
@property
|
||||
get fov() {
|
||||
return this._fov;
|
||||
}
|
||||
set fov(val) {
|
||||
this._fov = val;
|
||||
this._camera.setFov(toRadian(this._fov));
|
||||
}
|
||||
|
||||
@property
|
||||
get orthoHeight() {
|
||||
return this._orthoHeight;
|
||||
}
|
||||
set orthoHeight(val) {
|
||||
this._orthoHeight = val;
|
||||
this._camera.setOrthoHeight(this._orthoHeight);
|
||||
}
|
||||
|
||||
@property
|
||||
get near() {
|
||||
return this._near;
|
||||
}
|
||||
|
||||
set near(val) {
|
||||
this._near = val;
|
||||
this._camera.setNear(this._near);
|
||||
}
|
||||
|
||||
@property
|
||||
get far() {
|
||||
return this._far;
|
||||
}
|
||||
set far(val) {
|
||||
this._far = val;
|
||||
this._camera.setFar(this._far);
|
||||
}
|
||||
|
||||
@property
|
||||
get color() {
|
||||
return this._color;
|
||||
}
|
||||
|
||||
set color(val) {
|
||||
this._color.r = val.r;
|
||||
this._color.g = val.g;
|
||||
this._color.b = val.b;
|
||||
this._color.a = val.a;
|
||||
let color = this._color;
|
||||
this._camera.setColor(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
@property
|
||||
get depth() {
|
||||
return this._depth;
|
||||
}
|
||||
set depth(val) {
|
||||
this._depth = val;
|
||||
this._camera.setDepth(this._depth);
|
||||
}
|
||||
|
||||
@property
|
||||
get stencil() {
|
||||
return this._stencil;
|
||||
}
|
||||
|
||||
set stencil(val) {
|
||||
this._stencil = val;
|
||||
this._camera.setStencil(this._stencil);
|
||||
}
|
||||
|
||||
@property
|
||||
get clearFlags() {
|
||||
return this._clearFlags;
|
||||
}
|
||||
|
||||
set clearFlags(val) {
|
||||
this._clearFlags = val;
|
||||
this._camera.setClearFlags(this._clearFlags);
|
||||
}
|
||||
|
||||
@property
|
||||
get rect() {
|
||||
return this._rect;
|
||||
}
|
||||
|
||||
set rect(val) {
|
||||
this._rect.set(val);
|
||||
this._camera.setRect(this._rect);
|
||||
}
|
||||
|
||||
onLoad() {
|
||||
this._camera.setStages([
|
||||
'opaque',
|
||||
'transparent'
|
||||
]);
|
||||
this._camera.setNode(this.node);
|
||||
|
||||
/**
|
||||
* **@schema** The projection type of the camera
|
||||
* @type {string}
|
||||
*/
|
||||
this.projection = this._projection;
|
||||
/**
|
||||
* **@schema** The camera priority
|
||||
* @type {number}
|
||||
*/
|
||||
this.priority = this._priority;
|
||||
/**
|
||||
* **@schema** The camera field of view
|
||||
* @type {number}
|
||||
*/
|
||||
this.fov = this._fov;
|
||||
/**
|
||||
* **@schema** The camera height when in orthogonal mode
|
||||
* @type {number}
|
||||
*/
|
||||
this.orthoHeight = this._orthoHeight;
|
||||
/**
|
||||
* **@schema** The near clipping distance of the camera
|
||||
* @type {number}
|
||||
*/
|
||||
this.near = this._near;
|
||||
/**
|
||||
* **@schema** The far clipping distance of the camera
|
||||
* @type {number}
|
||||
*/
|
||||
this.far = this._far;
|
||||
/**
|
||||
* **@schema** The clearing color of the camera
|
||||
* @type {color4}
|
||||
*/
|
||||
this.color = this._color;
|
||||
/**
|
||||
* **@schema** The clearing depth value of the camera
|
||||
* @type {number}
|
||||
*/
|
||||
this.depth = this._depth;
|
||||
/**
|
||||
* **@schema** The clearing stencil value of the camera
|
||||
* @type {number}
|
||||
*/
|
||||
this.stencil = this._stencil;
|
||||
/**
|
||||
* **@schema** The clearing flags of this camera
|
||||
* @type {number}
|
||||
*/
|
||||
this.clearFlags = this._clearFlags;
|
||||
/**
|
||||
* **@schema** The screen rect of the camera
|
||||
* @type {Object}
|
||||
*/
|
||||
this.rect = this._rect;
|
||||
}
|
||||
|
||||
onEnable() {
|
||||
this.scene.addCamera(this._camera);
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
this.scene.removeCamera(this._camera);
|
||||
}
|
||||
}
|
||||
|
||||
CameraComponent.schema = {
|
||||
projection: {
|
||||
type: 'enums',
|
||||
default: 'perspective',
|
||||
options: ['ortho', 'perspective'],
|
||||
set(val) {
|
||||
this._projection = val;
|
||||
|
||||
let type = renderer.PROJ_PERSPECTIVE;
|
||||
if (this._projection === 'ortho') {
|
||||
type = renderer.PROJ_ORTHO;
|
||||
}
|
||||
this._camera.setType(type);
|
||||
}
|
||||
},
|
||||
|
||||
priority: {
|
||||
type: 'number',
|
||||
default: 0,
|
||||
set(val) {
|
||||
this._priority = val;
|
||||
this._camera.setPriority(val);
|
||||
}
|
||||
},
|
||||
|
||||
// fov (in angle)
|
||||
fov: {
|
||||
type: 'number',
|
||||
default: 45,
|
||||
set(val) {
|
||||
this._fov = val;
|
||||
this._camera.setFov(toRadian(val));
|
||||
}
|
||||
},
|
||||
|
||||
// orthoHeight
|
||||
orthoHeight: {
|
||||
type: 'number',
|
||||
default: 10,
|
||||
set(val) {
|
||||
this._orthoHeight = val;
|
||||
this._camera.setOrthoHeight(val);
|
||||
}
|
||||
},
|
||||
|
||||
// near
|
||||
near: {
|
||||
type: 'number',
|
||||
default: 0.01,
|
||||
set(val) {
|
||||
this._near = val;
|
||||
this._camera.setNear(val);
|
||||
}
|
||||
},
|
||||
|
||||
// far
|
||||
far: {
|
||||
type: 'number',
|
||||
default: 1000.0,
|
||||
set(val) {
|
||||
this._far = val;
|
||||
this._camera.setFar(val);
|
||||
}
|
||||
},
|
||||
|
||||
// color
|
||||
color: {
|
||||
type: 'color4',
|
||||
default: [0.2, 0.3, 0.47, 1],
|
||||
set(val) {
|
||||
this._color = val;
|
||||
this._camera.setColor(val.r, val.g, val.b, val.a);
|
||||
}
|
||||
},
|
||||
|
||||
// depth
|
||||
depth: {
|
||||
type: 'number',
|
||||
default: 1,
|
||||
set(val) {
|
||||
this._depth = val;
|
||||
this._camera.setDepth(val);
|
||||
}
|
||||
},
|
||||
|
||||
// stencil
|
||||
stencil: {
|
||||
type: 'number',
|
||||
default: 0,
|
||||
set(val) {
|
||||
this._stencil = val;
|
||||
this._camera.setStencil(val);
|
||||
}
|
||||
},
|
||||
|
||||
// clearFlags
|
||||
clearFlags: {
|
||||
type: 'number',
|
||||
default: 3, // enums.CLEAR_COLOR | enums.CLEAR_DEPTH;
|
||||
set(val) {
|
||||
this._clearFlags = val;
|
||||
this._camera.setClearFlags(val);
|
||||
}
|
||||
},
|
||||
|
||||
// rect
|
||||
rect: {
|
||||
type: 'rect',
|
||||
default: [0, 0, 1, 1],
|
||||
set(val) {
|
||||
this._rect = val;
|
||||
this._camera.setRect(val[0], val[1], val[2], val[3]);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
import render from '../../renderer';
|
||||
export default class RenderSystem {
|
||||
constructor () {
|
||||
this._scene = new render.Scene();
|
||||
}
|
||||
|
||||
init () {
|
||||
|
||||
}
|
||||
|
||||
add (comp) {
|
||||
|
||||
}
|
||||
|
||||
remove (comp) {
|
||||
|
||||
}
|
||||
|
||||
update (dt) {
|
||||
cc.render.render(this._scene);
|
||||
this._scene.reset();
|
||||
}
|
||||
|
||||
get scene () {
|
||||
return this._scene;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import Component from '../../Components/CCComponent';
|
||||
|
||||
export default class RenderableComponent extends Component {
|
||||
constructor() {
|
||||
this._system = RenderableComponent.system;
|
||||
this._scene = this._system.scene;
|
||||
}
|
||||
|
||||
// todo add implementation
|
||||
get renderSystem() {
|
||||
return this._system;
|
||||
}
|
||||
|
||||
// todo add scene
|
||||
get scene() {
|
||||
return this._scene;
|
||||
}
|
||||
};
|
||||
@@ -30,11 +30,12 @@ import eventManager from './platform/event-manager/CCEventManager';
|
||||
import ccobject from './data/object';
|
||||
import game from './CCGame';
|
||||
import Scheduler from './CCScheduler';
|
||||
import {autoRelease} from '../load-pipeline/auto-release-utils';
|
||||
import { autoRelease } from '../load-pipeline/auto-release-utils';
|
||||
import ComponentScheduler from '../scene-graph/component-scheduler';
|
||||
import NodeActivator from '../scene-graph/node-activator';
|
||||
// import AnimationSystem from '../3d/framework/animation-system';
|
||||
// import SkinningModelSystem from '../3d/framework/skinning-model-system';
|
||||
import RenderSystem from '../3d/framework/render-system';
|
||||
import { getClassByName } from './utils/js';
|
||||
|
||||
// const ComponentScheduler = require('./component-scheduler');
|
||||
@@ -176,6 +177,14 @@ class Director extends EventTarget {
|
||||
|
||||
// this.registerSystem('animation', AnimationSystem, ['AnimationComponent'], 200);
|
||||
// this.registerSystem('skinning-model', SkinningModelSystem, ['SkinningModelComponent'], 100);
|
||||
// init renderSystem
|
||||
{
|
||||
this._renderSystem = new RenderSystem();
|
||||
let renderComps = ['CameraComponent'];
|
||||
renderComps.forEach((compName) => {
|
||||
getClassByName(compName).system = this._renderSystem;
|
||||
});
|
||||
}
|
||||
|
||||
cc.loader.init(this);
|
||||
}
|
||||
@@ -319,7 +328,7 @@ class Director extends EventTarget {
|
||||
if (eventManager)
|
||||
eventManager.setEnabled(false);
|
||||
|
||||
cc.renderer.clear();
|
||||
// cc.renderer.clear();
|
||||
|
||||
if (!CC_EDITOR) {
|
||||
if (cc.isValid(this._scene)) {
|
||||
@@ -785,7 +794,7 @@ class Director extends EventTarget {
|
||||
* @param {number} priority
|
||||
* @return {System}
|
||||
*/
|
||||
registerSystem(name, cls, compClsNames, priority) {
|
||||
registerSystem (name, cls, compClsNames, priority) {
|
||||
let sys = new cls();
|
||||
sys._id = name;
|
||||
sys._priority = priority;
|
||||
@@ -804,7 +813,7 @@ class Director extends EventTarget {
|
||||
* @param {string} name
|
||||
* @return {System}
|
||||
*/
|
||||
getSystem(name) {
|
||||
getSystem (name) {
|
||||
return this._systems.find((sys) => {
|
||||
return sys._id === name;
|
||||
});
|
||||
@@ -882,8 +891,7 @@ class Director extends EventTarget {
|
||||
|
||||
// Render
|
||||
this.emit(cc.Director.EVENT_BEFORE_DRAW);
|
||||
renderer.render(this._scene);
|
||||
|
||||
this._renderSystem.update(this._deltaTime);
|
||||
// After draw
|
||||
this.emit(cc.Director.EVENT_AFTER_DRAW);
|
||||
|
||||
|
||||
+52
-36
@@ -27,7 +27,10 @@
|
||||
import EventTarget from './event/event-target';
|
||||
import inputManager from './platform/event-manager/CCInputManager';
|
||||
import debug from './platform/CCDebug';
|
||||
import {addon} from './utils/js';
|
||||
import { addon } from './utils/js';
|
||||
|
||||
import renderer from '../renderer';
|
||||
import gfx from '../renderer/gfx';
|
||||
|
||||
/**
|
||||
* @module cc
|
||||
@@ -80,7 +83,7 @@ var game = {
|
||||
EVENT_GAME_INITED: "game_inited",
|
||||
|
||||
/**
|
||||
* Event triggered after engine inited, at this point you will be able to use all engine classes.
|
||||
* Event triggered after engine inited, at this point you will be able to use all engine classes.
|
||||
* It was defined as EVENT_RENDERER_INITED in cocos creator v1.x and renamed in v2.0
|
||||
* @property EVENT_ENGINE_INITED
|
||||
* @constant
|
||||
@@ -231,9 +234,9 @@ var game = {
|
||||
*/
|
||||
onStart: null,
|
||||
|
||||
//@Public Methods
|
||||
//@Public Methods
|
||||
|
||||
// @Game play control
|
||||
// @Game play control
|
||||
/**
|
||||
* !#en Set frame rate of game.
|
||||
* !#zh 设置游戏帧率。
|
||||
@@ -340,7 +343,7 @@ var game = {
|
||||
close();
|
||||
},
|
||||
|
||||
// @Game loading
|
||||
// @Game loading
|
||||
|
||||
_initEngine () {
|
||||
if (this._rendererInitialized) {
|
||||
@@ -473,7 +476,7 @@ var game = {
|
||||
this.prepare(game.onStart && game.onStart.bind(game));
|
||||
},
|
||||
|
||||
// @ Persist root node section
|
||||
// @ Persist root node section
|
||||
/**
|
||||
* !#en
|
||||
* Add a persistent root node to the game, the persistent node won't be destroyed during scene transition.<br/>
|
||||
@@ -496,7 +499,7 @@ var game = {
|
||||
if (!node.parent) {
|
||||
node.parent = scene;
|
||||
}
|
||||
else if ( !(node.parent instanceof cc.Scene) ) {
|
||||
else if (!(node.parent instanceof cc.Scene)) {
|
||||
cc.warnID(3801);
|
||||
return;
|
||||
}
|
||||
@@ -535,9 +538,9 @@ var game = {
|
||||
return node._persistNode;
|
||||
},
|
||||
|
||||
//@Private Methods
|
||||
//@Private Methods
|
||||
|
||||
// @Time ticker section
|
||||
// @Time ticker section
|
||||
_setAnimFrame: function () {
|
||||
this._lastTime = new Date();
|
||||
var frameRate = game.config.frameRate;
|
||||
@@ -555,34 +558,34 @@ var game = {
|
||||
}
|
||||
else {
|
||||
window.requestAnimFrame = window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
this._stTime;
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
this._stTime;
|
||||
window.cancelAnimFrame = window.cancelAnimationFrame ||
|
||||
window.cancelRequestAnimationFrame ||
|
||||
window.msCancelRequestAnimationFrame ||
|
||||
window.mozCancelRequestAnimationFrame ||
|
||||
window.oCancelRequestAnimationFrame ||
|
||||
window.webkitCancelRequestAnimationFrame ||
|
||||
window.msCancelAnimationFrame ||
|
||||
window.mozCancelAnimationFrame ||
|
||||
window.webkitCancelAnimationFrame ||
|
||||
window.oCancelAnimationFrame ||
|
||||
this._ctTime;
|
||||
window.cancelRequestAnimationFrame ||
|
||||
window.msCancelRequestAnimationFrame ||
|
||||
window.mozCancelRequestAnimationFrame ||
|
||||
window.oCancelRequestAnimationFrame ||
|
||||
window.webkitCancelRequestAnimationFrame ||
|
||||
window.msCancelAnimationFrame ||
|
||||
window.mozCancelAnimationFrame ||
|
||||
window.webkitCancelAnimationFrame ||
|
||||
window.oCancelAnimationFrame ||
|
||||
this._ctTime;
|
||||
}
|
||||
}
|
||||
},
|
||||
_stTime: function(callback){
|
||||
_stTime: function (callback) {
|
||||
var currTime = new Date().getTime();
|
||||
var timeToCall = Math.max(0, game._frameTime - (currTime - game._lastTime));
|
||||
var id = window.setTimeout(function() { callback(); },
|
||||
var id = window.setTimeout(function () { callback(); },
|
||||
timeToCall);
|
||||
game._lastTime = currTime + timeToCall;
|
||||
return id;
|
||||
},
|
||||
_ctTime: function(id){
|
||||
_ctTime: function (id) {
|
||||
window.clearTimeout(id);
|
||||
},
|
||||
//Run game.
|
||||
@@ -609,7 +612,7 @@ var game = {
|
||||
self._paused = false;
|
||||
},
|
||||
|
||||
// @Game loading section
|
||||
// @Game loading section
|
||||
_initConfig (config) {
|
||||
// Configs adjustment
|
||||
if (typeof config.debugMode !== 'number') {
|
||||
@@ -644,11 +647,11 @@ var game = {
|
||||
_determineRenderType () {
|
||||
let config = this.config,
|
||||
userRenderMode = parseInt(config.renderMode) || 0;
|
||||
|
||||
|
||||
// Determine RenderType
|
||||
this.renderType = this.RENDER_TYPE_CANVAS;
|
||||
let supportRender = false;
|
||||
|
||||
|
||||
if (userRenderMode === 0) {
|
||||
if (cc.sys.capabilities['opengl']) {
|
||||
this.renderType = this.RENDER_TYPE_WEBGL;
|
||||
@@ -667,7 +670,7 @@ var game = {
|
||||
this.renderType = this.RENDER_TYPE_WEBGL;
|
||||
supportRender = true;
|
||||
}
|
||||
|
||||
|
||||
if (!supportRender) {
|
||||
throw new Error(debug.getError(3820, userRenderMode));
|
||||
}
|
||||
@@ -756,14 +759,27 @@ var game = {
|
||||
if (isWeChatGame || isQQPlay) {
|
||||
opts['preserveDrawingBuffer'] = true;
|
||||
}
|
||||
renderer.initWebGL(localCanvas, opts);
|
||||
this._renderContext = renderer.device._gl;
|
||||
|
||||
{
|
||||
// todo, adjust opts here
|
||||
let device = this._renderContext = new gfx.Device(localCanvas, {});
|
||||
// todo, fix builtins here
|
||||
this._renderer = new renderer.ForwardRenderer(device);
|
||||
}
|
||||
// renderer.initWebGL(localCanvas, opts);
|
||||
// this._renderContext = renderer.device._gl;
|
||||
}
|
||||
if (!this._renderContext) {
|
||||
// todo fix here for wechat game
|
||||
console.error('can not support canvas rendering in 3D');
|
||||
this._renderer = null;
|
||||
this._renderContext = null;
|
||||
this.renderType = this.RENDER_TYPE_CANVAS;
|
||||
return;
|
||||
// this.renderType = this.RENDER_TYPE_CANVAS;
|
||||
// Could be ignored by module settings
|
||||
renderer.initCanvas(localCanvas);
|
||||
this._renderContext = renderer.device._ctx;
|
||||
// renderer.initCanvas(localCanvas);
|
||||
// this._renderContext = renderer.device._ctx;
|
||||
}
|
||||
|
||||
this.canvas.oncontextmenu = function () {
|
||||
@@ -859,4 +875,4 @@ EventTarget.call(game);
|
||||
addon(game, EventTarget.prototype);
|
||||
|
||||
cc.game = game;
|
||||
export default game;
|
||||
export default game;
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
* @static
|
||||
*/
|
||||
|
||||
export {default as MutableForwardIterator} from './mutable-forward-iterator';
|
||||
|
||||
/**
|
||||
* Removes the array item at the specified index.
|
||||
* @method removeAt
|
||||
@@ -99,7 +97,7 @@ export function fastRemove (array, value) {
|
||||
export function verifyType (array, type) {
|
||||
if (array && array.length > 0) {
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (!(array[i] instanceof type)) {
|
||||
if (!(array[i] instanceof type)) {
|
||||
cc.logID(1300);
|
||||
return false;
|
||||
}
|
||||
@@ -167,4 +165,4 @@ export function copy (array) {
|
||||
for (i = 0; i < len; i += 1)
|
||||
arr_clone[i] = array[i];
|
||||
return arr_clone;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
import IdGenerater from './id-generater';
|
||||
|
||||
import * as jsarray from './array';
|
||||
import IDGenerater from './id-generater';
|
||||
|
||||
@@ -41,8 +41,6 @@ const { ccclass, property } = _decorator;
|
||||
export default class Scene extends Node {
|
||||
constructor(name) {
|
||||
super(name);
|
||||
this._anchorPoint.x = 0.0;
|
||||
this._anchorPoint.y = 0.0;
|
||||
|
||||
this._activeInHierarchy = false;
|
||||
this._inited = !cc.game._isCloning;
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
window.files = {
|
||||
"aa": [
|
||||
"simple"
|
||||
],
|
||||
// "animation": [
|
||||
// "spec-skeleton"
|
||||
// ],
|
||||
// "audio": [
|
||||
// "spec-audio"
|
||||
// ],
|
||||
// "enabled": [
|
||||
// "spec-comp-disabled",
|
||||
// "spec-entity-disabled",
|
||||
// "spec-prefab-disabled",
|
||||
// ],
|
||||
// "model": [
|
||||
// "spec-blood-and-fire",
|
||||
// "spec-mesh-asset",
|
||||
// "spec-primitives"
|
||||
// ],
|
||||
// "prefab": [
|
||||
// "spec-multiple-children",
|
||||
// "spec-prefab-instantiate",
|
||||
// "spec-prefab-skeleton-instantiate",
|
||||
// "spec-use-default-transform",
|
||||
// "spec-use-new-name"
|
||||
// ],
|
||||
// "preload": [
|
||||
// "spec-mix-preload",
|
||||
// "spec-no-prefab-preload"
|
||||
// ],
|
||||
// "script": [
|
||||
// "spec-script-comps",
|
||||
// "spec-script-materials",
|
||||
// "spec-script-mesh",
|
||||
// "spec-script-refs",
|
||||
// "spec-script-simple",
|
||||
// "spec-script-sprite"
|
||||
// ],
|
||||
// "subasset": [
|
||||
// "spec-model-subasset"
|
||||
// ],
|
||||
// "ui": [
|
||||
// "spec-bitmap-font",
|
||||
// "spec-button",
|
||||
// "spec-mask-nested",
|
||||
// "spec-mask-same-level",
|
||||
// "spec-opentype-font",
|
||||
// "spec-simple",
|
||||
// "spec-system-font",
|
||||
// "spec-screen-scaler",
|
||||
// "spec-toggle-and-group",
|
||||
// "spec-grid-layout",
|
||||
// "spec-scroll-bar",
|
||||
// "spec-scroll-view",
|
||||
// "spec-slider",
|
||||
// "spec-edit-box",
|
||||
// "spec-transition-state",
|
||||
// ],
|
||||
// "particle": [
|
||||
// "spec-particlesystem-box",
|
||||
// "spec-particlesystem-circle",
|
||||
// "spec-particlesystem-colorovertime",
|
||||
// "spec-particlesystem-cone",
|
||||
// "spec-particlesystem-forceovertime",
|
||||
// "spec-particlesystem-hemisphere",
|
||||
// "spec-particlesystem-limitvelocity",
|
||||
// "spec-particlesystem-renderer",
|
||||
// "spec-particlesystem-rotationovertime",
|
||||
// "spec-particlesystem-sizeovertime",
|
||||
// "spec-particlesystem-sphere",
|
||||
// "spec-particlesystem-texturesheet",
|
||||
// "spec-particlesystem-velocityovertime",
|
||||
// "spec-particlesystem-performance"
|
||||
// ],
|
||||
// "physics": [
|
||||
// "spec-boxes",
|
||||
// "spec-spheres",
|
||||
// "spec-body-params",
|
||||
// "spec-skiing"
|
||||
// ]
|
||||
};
|
||||
@@ -0,0 +1,446 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>engine-3d / examples</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
||||
<style>
|
||||
html {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #ffffff;
|
||||
margin: 0px;
|
||||
height: 100%;
|
||||
color: #555;
|
||||
font-family: 'inconsolata';
|
||||
font-size: 15px;
|
||||
line-height: 18px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: 30px;
|
||||
margin-bottom: 40px;
|
||||
margin-left: 20px;
|
||||
font-size: 25px;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #2194CE;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#panel {
|
||||
position: fixed;
|
||||
left: 0px;
|
||||
width: 310px;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
#panel #content {
|
||||
padding: 0px 20px 20px 20px;
|
||||
}
|
||||
|
||||
#panel #content .link {
|
||||
color: #2194CE;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#panel #content .selected {
|
||||
color: #ff0000;
|
||||
}
|
||||
|
||||
#panel #content .link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#viewer {
|
||||
position: absolute;
|
||||
border: 0px;
|
||||
left: 310px;
|
||||
width: calc(100% - 310px);
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#viewSrcButton {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
padding: 8px;
|
||||
color: #fff;
|
||||
background-color: #555;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
#viewSrcButton:hover {
|
||||
cursor: pointer;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.filterBlock{
|
||||
margin: 20px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.filterBlock p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#filterInput {
|
||||
width: 100%;
|
||||
padding: 5px;
|
||||
font-family: inherit;
|
||||
font-size: 15px;
|
||||
outline: none;
|
||||
border: 1px solid #dedede;
|
||||
}
|
||||
|
||||
#filterInput:focus{
|
||||
border: 1px solid #2194CE;
|
||||
}
|
||||
|
||||
#clearFilterButton {
|
||||
position: absolute;
|
||||
right: 6px;
|
||||
top: 50%;
|
||||
margin-top: -8px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
font-size: 14px;
|
||||
color: grey;
|
||||
text-align: center;
|
||||
line-height: 0;
|
||||
padding-top: 7px;
|
||||
opacity: .5;
|
||||
}
|
||||
|
||||
#clearFilterButton:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.filtered {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
#panel li b {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* mobile */
|
||||
|
||||
#expandButton {
|
||||
display: none;
|
||||
position: absolute;
|
||||
right: 20px;
|
||||
top: 12px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
#expandButton span {
|
||||
height: 2px;
|
||||
background-color: #2194CE;
|
||||
width: 16px;
|
||||
position: absolute;
|
||||
left: 8px;
|
||||
top: 10px;
|
||||
}
|
||||
|
||||
#expandButton span:nth-child(1) {
|
||||
top: 16px;
|
||||
}
|
||||
|
||||
#expandButton span:nth-child(2) {
|
||||
top: 22px;
|
||||
}
|
||||
|
||||
@media all and ( max-width: 640px ) {
|
||||
h1{
|
||||
margin-top: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
#panel{
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
height: 480px;
|
||||
width: 100%;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
overflow: hidden;
|
||||
border-bottom: 1px solid #dedede;
|
||||
}
|
||||
#content{
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 90px;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
font-size: 17px;
|
||||
line-height: 22px;
|
||||
overflow: auto;
|
||||
}
|
||||
#viewer{
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 56px;
|
||||
width: 100%;
|
||||
height: calc(100% - 56px);
|
||||
}
|
||||
#expandButton{
|
||||
display: block;
|
||||
}
|
||||
#panel.collapsed{
|
||||
height: 56px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="panel">
|
||||
<h1>engine-3d</a> / examples</h1>
|
||||
<a id="expandButton" href="#">
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
</a>
|
||||
<div class="filterBlock" >
|
||||
<input type="text" id="filterInput" placeholder="Type to filter" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||||
<a href="#" id="clearFilterButton" >x</a>
|
||||
</div>
|
||||
<div id="content"></div>
|
||||
</div>
|
||||
<iframe id="viewer" name="viewer" allowfullscreen allowvr onmousewheel="" src = "spec-bitmap-font.html"></iframe>
|
||||
|
||||
<script src="files.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
function extractQuery() {
|
||||
var p = window.location.search.indexOf( '?q=' );
|
||||
if( p !== -1 ) {
|
||||
return window.location.search.substr( 3 );
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
var panel = document.getElementById( 'panel' );
|
||||
var content = document.getElementById( 'content' );
|
||||
var viewer = document.getElementById( 'viewer' );
|
||||
|
||||
var filterInput = document.getElementById( 'filterInput' );
|
||||
var clearFilterButton = document.getElementById( 'clearFilterButton' );
|
||||
|
||||
var expandButton = document.getElementById( 'expandButton' );
|
||||
expandButton.addEventListener( 'click', function ( event ) {
|
||||
event.preventDefault();
|
||||
panel.classList.toggle( 'collapsed' );
|
||||
});
|
||||
|
||||
// iOS iframe auto-resize workaround
|
||||
if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
|
||||
|
||||
viewer.style.width = getComputedStyle( viewer ).width;
|
||||
viewer.style.height = getComputedStyle( viewer ).height;
|
||||
viewer.setAttribute( 'scrolling', 'no' );
|
||||
}
|
||||
|
||||
var container = document.createElement( 'div' );
|
||||
content.appendChild( container );
|
||||
|
||||
var viewSrcButton = document.createElement( 'a' );
|
||||
viewSrcButton.id = 'viewSrcButton';
|
||||
viewSrcButton.target = '-blank';
|
||||
viewSrcButton.textContent = 'View source';
|
||||
viewSrcButton.style.display = 'none';
|
||||
document.body.appendChild( viewSrcButton );
|
||||
|
||||
var links = {};
|
||||
var selected = null;
|
||||
|
||||
function createLink( file ) {
|
||||
|
||||
var link = document.createElement( 'a' );
|
||||
link.className = 'link';
|
||||
link.href = file + '.html';
|
||||
link.textContent = getName( file );
|
||||
link.setAttribute( 'target', 'viewer' );
|
||||
link.addEventListener( 'click', function ( event ) {
|
||||
|
||||
if ( event.button === 0 ) {
|
||||
|
||||
selectFile( file );
|
||||
}
|
||||
});
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
for ( var key in window.files ) {
|
||||
|
||||
var section = window.files[ key ];
|
||||
var header = document.createElement( 'h2' );
|
||||
header.textContent = key;
|
||||
header.setAttribute( 'data-category', key );
|
||||
container.appendChild( header );
|
||||
|
||||
for ( var i = 0; i < section.length; i ++ ) {
|
||||
|
||||
var file = section[ i ];
|
||||
|
||||
var link = createLink( file );
|
||||
container.appendChild( link );
|
||||
|
||||
links[ file ] = link;
|
||||
}
|
||||
}
|
||||
|
||||
function loadFile( file ) {
|
||||
|
||||
selectFile( file );
|
||||
viewer.src = file + '.html';
|
||||
}
|
||||
|
||||
function selectFile( file ) {
|
||||
|
||||
if ( selected !== null ) links[ selected ].classList.remove( 'selected' );
|
||||
|
||||
links[ file ].classList.add( 'selected' );
|
||||
|
||||
window.location.hash = file;
|
||||
viewer.focus();
|
||||
|
||||
panel.classList.add( 'collapsed' );
|
||||
|
||||
selected = file;
|
||||
|
||||
// Reveal "View source" button and set attributes to this example
|
||||
viewSrcButton.style.display = '';
|
||||
viewSrcButton.href = selected + '.html';
|
||||
viewSrcButton.title = 'View source code for ' + getName(selected) + ' on GitHub';
|
||||
}
|
||||
|
||||
if ( window.location.hash !== '' ) {
|
||||
|
||||
loadFile( window.location.hash.substring( 1 ) );
|
||||
}
|
||||
|
||||
// filter
|
||||
|
||||
filterInput.addEventListener( 'input', function() {
|
||||
|
||||
updateFilter();
|
||||
});
|
||||
|
||||
clearFilterButton.addEventListener( 'click', function( e ) {
|
||||
|
||||
filterInput.value = '';
|
||||
updateFilter();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
function updateFilter() {
|
||||
|
||||
var v = filterInput.value;
|
||||
if( v !== '' ) {
|
||||
window.history.replaceState( {} , '', '?q=' + v + window.location.hash );
|
||||
} else {
|
||||
window.history.replaceState( {} , '', window.location.pathname + window.location.hash );
|
||||
}
|
||||
|
||||
var exp = new RegExp( v, 'gi' );
|
||||
|
||||
for ( var key in window.files ) {
|
||||
|
||||
var section = window.files[ key ];
|
||||
|
||||
for ( var i = 0; i < section.length; i ++ ) {
|
||||
|
||||
filterExample( section[ i ], exp );
|
||||
}
|
||||
}
|
||||
|
||||
layoutList();
|
||||
}
|
||||
|
||||
function filterExample( file, exp ){
|
||||
|
||||
var link = links[ file ];
|
||||
var name = getName( file );
|
||||
var res = file.match( exp );
|
||||
var text;
|
||||
|
||||
if ( res && res.length > 0 ) {
|
||||
|
||||
link.classList.remove( 'filtered' );
|
||||
|
||||
for( var i = 0; i < res.length; i++ ) {
|
||||
text = name.replace( res[ i ], '<b>' + res[ i ] + '</b>' );
|
||||
}
|
||||
|
||||
link.innerHTML = text;
|
||||
|
||||
} else {
|
||||
|
||||
link.classList.add( 'filtered' );
|
||||
link.innerHTML = name;
|
||||
}
|
||||
}
|
||||
|
||||
function getName( file ) {
|
||||
|
||||
var name = file;
|
||||
return name;
|
||||
}
|
||||
|
||||
function layoutList() {
|
||||
|
||||
for ( var key in window.files ) {
|
||||
|
||||
var collapsed = true;
|
||||
var section = window.files[ key ];
|
||||
|
||||
for ( var i = 0; i < section.length; i ++ ) {
|
||||
|
||||
var file = section[ i ];
|
||||
|
||||
if( !links[ file ].classList.contains( 'filtered' ) ){
|
||||
|
||||
collapsed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var element = document.querySelector( 'h2[data-category="' + key + '"]' );
|
||||
|
||||
if( collapsed ){
|
||||
|
||||
element.classList.add( 'filtered' );
|
||||
} else {
|
||||
|
||||
element.classList.remove( 'filtered' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filterInput.value = extractQuery();
|
||||
updateFilter();
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>spec-scroll-view</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
||||
<style>
|
||||
body {
|
||||
background-color: #333;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.fit {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="fit">
|
||||
<canvas id="canvas" tabindex="-1" class="fit"></canvas>
|
||||
<script src="../bin/cocos-3d.dev.js"></script>
|
||||
<!-- <script src="./loadScene.js"></script> -->
|
||||
<script>
|
||||
function onStart() {
|
||||
//todo initialization
|
||||
let scene = new cc.Scene();
|
||||
let node = new cc.Node();
|
||||
scene.addChild(node);
|
||||
let comp = node.addComponent('cc.Camera');
|
||||
cc.director.runSceneImmediate(scene);
|
||||
};
|
||||
cc.game.run({}, onStart);
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+3
-3
@@ -128,10 +128,10 @@ var _global = typeof window === 'undefined' ? global : window;
|
||||
* @module cc
|
||||
* @main cc
|
||||
*/
|
||||
cc = _global.cc || {};
|
||||
let cc = _global.cc = _global.cc || {};
|
||||
|
||||
// For internal usage
|
||||
_cc = _global._cc || {};
|
||||
_global._cc = _global._cc || {};
|
||||
|
||||
|
||||
function defineMacro (name, defaultValue) {
|
||||
@@ -202,4 +202,4 @@ if (CC_DEV) {
|
||||
const engineVersion = '2.0.0 alpha';
|
||||
_global['CocosEngine'] = cc.ENGINE_VERSION = engineVersion;
|
||||
|
||||
export default cc;
|
||||
export default cc;
|
||||
|
||||
Reference in New Issue
Block a user