mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
support base component (#3377)
This commit is contained in:
@@ -27,7 +27,7 @@ import RenderSystemActor from './renderSystemActor';
|
||||
import renderer from '../../renderer/index';
|
||||
import { toRadian } from '../../core/vmath';
|
||||
import { ccclass, menu, property, executeInEditMode } from "../../core/data/class-decorator";
|
||||
import { Color, Enum } from '../../core/value-types';
|
||||
import { Color, Enum, Rect } from '../../core/value-types';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../core/value-types/index').Color} Color
|
||||
@@ -70,6 +70,7 @@ let CameraProjection = Enum({
|
||||
*/
|
||||
@ccclass('cc.CameraComponent')
|
||||
@menu('Components/CameraComponent')
|
||||
@executeInEditMode
|
||||
export default class CameraComponent extends RenderSystemActor{
|
||||
@property
|
||||
_projection = CameraProjection.Perspective;
|
||||
@@ -102,7 +103,7 @@ export default class CameraComponent extends RenderSystemActor{
|
||||
_clearFlags = 3;
|
||||
|
||||
@property
|
||||
_rect = [0, 0, 1, 1];
|
||||
_rect = new Rect(0, 0, 1, 1);
|
||||
|
||||
/**
|
||||
* !#en The projection type of the camera
|
||||
@@ -121,7 +122,7 @@ export default class CameraComponent extends RenderSystemActor{
|
||||
this._projection = val;
|
||||
|
||||
let type = renderer.PROJ_PERSPECTIVE;
|
||||
if (this._projection === 'ortho') {
|
||||
if (this._projection === CameraProjection.Ortho) {
|
||||
type = renderer.PROJ_ORTHO;
|
||||
}
|
||||
this._camera.setType(type);
|
||||
@@ -275,7 +276,7 @@ export default class CameraComponent extends RenderSystemActor{
|
||||
* !#en The screen rect of the camera
|
||||
*
|
||||
* !#ch 相机的屏幕矩形
|
||||
* @type {Array}
|
||||
* @type {Rect}
|
||||
*/
|
||||
@property
|
||||
get rect() {
|
||||
@@ -284,7 +285,7 @@ export default class CameraComponent extends RenderSystemActor{
|
||||
|
||||
set rect(val) {
|
||||
this._rect = val;
|
||||
this._camera.setRect(val[0], val[1], val[2], val[3]);
|
||||
this._camera.setRect(val.x, val.y, val.width, val.height);
|
||||
}
|
||||
|
||||
static Projection = CameraProjection;
|
||||
|
||||
@@ -27,7 +27,7 @@ import RenderSystemActor from './renderSystemActor';
|
||||
import renderer from '../../renderer/index';
|
||||
import { Color, Enum } from '../../core/value-types';
|
||||
import { toRadian } from '../../core/vmath';
|
||||
import { ccclass, menu, property } from "../../core/data/class-decorator";
|
||||
import { ccclass, menu, property, executeInEditMode } from "../../core/data/class-decorator";
|
||||
|
||||
/**
|
||||
* !#en The light source type
|
||||
@@ -112,6 +112,7 @@ const LightShadowType = Enum({
|
||||
*/
|
||||
@ccclass('cc.LightComponent')
|
||||
@menu('Components/LightComponent')
|
||||
@executeInEditMode
|
||||
export default class LightComponent extends RenderSystemActor {
|
||||
@property
|
||||
_type = LightType.Directional;
|
||||
@@ -173,9 +174,9 @@ export default class LightComponent extends RenderSystemActor {
|
||||
this._type = val;
|
||||
|
||||
let type = renderer.LIGHT_DIRECTIONAL;
|
||||
if (this._type === 'point') {
|
||||
if (this._type === LightType.Point) {
|
||||
type = renderer.LIGHT_POINT;
|
||||
} else if (this._type === 'spot') {
|
||||
} else if (this._type === LightType.Spot) {
|
||||
type = renderer.LIGHT_SPOT;
|
||||
}
|
||||
this._light.setType(type);
|
||||
@@ -194,7 +195,7 @@ export default class LightComponent extends RenderSystemActor {
|
||||
|
||||
set color(val) {
|
||||
this._color = val;
|
||||
this._light.setColor(val.r, val.g, val.b);
|
||||
this._light.setColor(val.r / 255, val.g / 255, val.b / 255);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,9 +268,9 @@ export default class LightComponent extends RenderSystemActor {
|
||||
* !#ch 阴影类型
|
||||
* @type {Number} shadowType
|
||||
*/
|
||||
@property({
|
||||
type: LightShadowType
|
||||
})
|
||||
// @property({
|
||||
// type: LightShadowType
|
||||
// })
|
||||
get shadowType() {
|
||||
return this._shadowType;
|
||||
}
|
||||
@@ -278,9 +279,9 @@ export default class LightComponent extends RenderSystemActor {
|
||||
this._shadowType = val;
|
||||
|
||||
let type = renderer.SHADOW_NONE;
|
||||
if (val === 'hard') {
|
||||
if (val === LightShadowType.Hard) {
|
||||
type = renderer.SHADOW_HARD;
|
||||
} else if (val === 'soft') {
|
||||
} else if (val === LightShadowType.Soft) {
|
||||
type = renderer.SHADOW_SOFT;
|
||||
}
|
||||
this._light.setShadowType(type);
|
||||
@@ -293,7 +294,7 @@ export default class LightComponent extends RenderSystemActor {
|
||||
*
|
||||
* @type {Number}
|
||||
*/
|
||||
@property
|
||||
// @property
|
||||
get shadowResolution() {
|
||||
return this._shadowResolution;
|
||||
}
|
||||
@@ -310,7 +311,7 @@ export default class LightComponent extends RenderSystemActor {
|
||||
*
|
||||
* @type {Number}
|
||||
*/
|
||||
@property
|
||||
// @property
|
||||
get shadowDarkness() {
|
||||
return this._shadowDarkness;
|
||||
}
|
||||
@@ -327,7 +328,7 @@ export default class LightComponent extends RenderSystemActor {
|
||||
*
|
||||
* @type {Number}
|
||||
*/
|
||||
@property
|
||||
// @property
|
||||
get shadowMinDepth() {
|
||||
return this._shadowMinDepth;
|
||||
}
|
||||
@@ -344,7 +345,7 @@ export default class LightComponent extends RenderSystemActor {
|
||||
*
|
||||
* @type {Number}
|
||||
*/
|
||||
@property
|
||||
// @property
|
||||
get shadowMaxDepth() {
|
||||
return this._shadowMaxDepth;
|
||||
}
|
||||
@@ -361,7 +362,7 @@ export default class LightComponent extends RenderSystemActor {
|
||||
*
|
||||
* @type {Number}
|
||||
*/
|
||||
@property
|
||||
// @property
|
||||
get shadowDepthScale() {
|
||||
return this._shadowDepthScale;
|
||||
}
|
||||
@@ -378,7 +379,7 @@ export default class LightComponent extends RenderSystemActor {
|
||||
*
|
||||
* @type {Number}
|
||||
*/
|
||||
@property
|
||||
// @property
|
||||
get shadowFrustumSize() {
|
||||
return this._shadowFrustumSize;
|
||||
}
|
||||
@@ -395,7 +396,7 @@ export default class LightComponent extends RenderSystemActor {
|
||||
*
|
||||
* @type {Number}
|
||||
*/
|
||||
@property
|
||||
// @property
|
||||
get shadowBias() {
|
||||
return this._shadowBias;
|
||||
}
|
||||
@@ -415,7 +416,7 @@ export default class LightComponent extends RenderSystemActor {
|
||||
this._light = new renderer.Light();
|
||||
}
|
||||
|
||||
onInit() {
|
||||
onLoad() {
|
||||
this._light.setNode(this.node);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,8 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
// @ts-check
|
||||
import RenderSystemActor from './renderSystemActor';
|
||||
import renderer from '../../renderer/index';
|
||||
import { ccclass, property, menu } from '../../core/data/class-decorator';
|
||||
import { ccclass, property, menu, executeInEditMode } from '../../core/data/class-decorator';
|
||||
import Mesh from '../assets/mesh';
|
||||
import Enum from '../../core/value-types/enum';
|
||||
import RenderableComponent from './renderable-component';
|
||||
@@ -88,9 +87,8 @@ let ModelShadowCastingMode = Enum({
|
||||
*/
|
||||
@ccclass('cc.ModelComponent')
|
||||
@menu('Components/ModelComponent')
|
||||
@executeInEditMode
|
||||
export default class ModelComponent extends RenderableComponent {
|
||||
@property
|
||||
_materials = [];
|
||||
|
||||
/**
|
||||
* @type {Mesh}
|
||||
@@ -104,22 +102,6 @@ export default class ModelComponent extends RenderableComponent {
|
||||
@property
|
||||
_receiveShadows = false;
|
||||
|
||||
/**
|
||||
* !#en The material of the model
|
||||
*
|
||||
* !#ch 模型材质
|
||||
* @type {Material[]}
|
||||
*/
|
||||
@property
|
||||
get materials() {
|
||||
return this._materials;
|
||||
}
|
||||
|
||||
set materials(val) {
|
||||
this._materials = val;
|
||||
this._updateModelParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en The mesh of the model
|
||||
*
|
||||
@@ -182,6 +164,15 @@ export default class ModelComponent extends RenderableComponent {
|
||||
this._models = [];
|
||||
}
|
||||
|
||||
onLoad() {
|
||||
if (this.mesh == null) {
|
||||
this.mesh = cc.game._builtins['builtin-cube'];
|
||||
let mtl = new cc.Material();
|
||||
mtl.effect = cc.game._builtins['builtin-effect-unlit'];
|
||||
this.material = mtl;
|
||||
}
|
||||
}
|
||||
|
||||
onEnable() {
|
||||
for (let i = 0; i < this._models.length; ++i) {
|
||||
this.scene.addModel(this._models[i]);
|
||||
@@ -272,7 +263,7 @@ export default class ModelComponent extends RenderableComponent {
|
||||
}
|
||||
return mat;
|
||||
}
|
||||
|
||||
|
||||
_onMaterialModified(idx, mat) {
|
||||
this._models[idx].setEffect(mat.effectInst);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ export default class RenderSystem {
|
||||
}
|
||||
|
||||
update (dt) {
|
||||
this._scene.tick();
|
||||
cc.game._renderer.render(this._scene);
|
||||
this._scene.reset();
|
||||
}
|
||||
|
||||
@@ -110,6 +110,8 @@ export default class ForwardRenderer extends BaseRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
let hasViewWithDefautlFramebuffer = false;
|
||||
|
||||
// render by cameras
|
||||
this._viewPools.sort((a, b) => {
|
||||
return (a._priority - b._priority);
|
||||
@@ -119,14 +121,27 @@ export default class ForwardRenderer extends BaseRenderer {
|
||||
});
|
||||
for (let i = 0; i < this._viewPools.length; ++i) {
|
||||
let view = this._viewPools.data[i];
|
||||
if (view._framebuffer === null)
|
||||
hasViewWithDefautlFramebuffer = true;
|
||||
this._render(view, scene);
|
||||
}
|
||||
|
||||
// render by views (ui)
|
||||
for (let i = 0; i < scene._views.length; ++i) {
|
||||
let view = scene._views[i];
|
||||
if (view._framebuffer === null)
|
||||
hasViewWithDefautlFramebuffer = true;
|
||||
this._render(view, scene);
|
||||
}
|
||||
|
||||
// hack:to resolve the situation where no camera exist in the scene,can be optimized later.
|
||||
if (!hasViewWithDefautlFramebuffer) {
|
||||
this._device.clear({
|
||||
color: [0, 0, 0, 1],
|
||||
depth: 1,
|
||||
stencil: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_submitLightUniforms() {
|
||||
@@ -509,4 +524,4 @@ export default class ForwardRenderer extends BaseRenderer {
|
||||
}
|
||||
this._draw(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user