mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 08:42:43 +08:00
Vendored
-58
File diff suppressed because one or more lines are too long
@@ -165,8 +165,8 @@ export default class LightComponent extends Component {
|
||||
}
|
||||
|
||||
set type (val) {
|
||||
this._type = val;
|
||||
this._destroyLight();
|
||||
this._type = parseInt(val);
|
||||
this._createLight();
|
||||
}
|
||||
|
||||
@@ -279,6 +279,9 @@ export default class LightComponent extends Component {
|
||||
this.range = this._range;
|
||||
this.spotAngle = this._spotAngle;
|
||||
break;
|
||||
default:
|
||||
console.warn(`illegal light type ${this._type}`);
|
||||
return;
|
||||
}
|
||||
if (!this._light) { console.warn('we don\'t support this many lights in forward pipeline.'); }
|
||||
this.color = this._color;
|
||||
|
||||
@@ -104,7 +104,7 @@ export class ModelComponent extends RenderableComponent {
|
||||
|
||||
set mesh (val) {
|
||||
this._mesh = val;
|
||||
this._updateModels(true);
|
||||
this._updateModels();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,12 +167,11 @@ export class ModelComponent extends RenderableComponent {
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
this._updateModels();
|
||||
if (!this._model) { this._updateModels(); }
|
||||
this._updateCastShadow();
|
||||
this._updateReceiveShadow();
|
||||
|
||||
if (this._model) {
|
||||
this._model.enabled = this.enabledInHierarchy;
|
||||
this._model.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,11 +187,8 @@ export class ModelComponent extends RenderableComponent {
|
||||
}
|
||||
}
|
||||
|
||||
protected _updateModels (forceUpdate: boolean = false) {
|
||||
if (!this.enabled || !this.node._scene || !this._mesh || (this._model && !forceUpdate)) {
|
||||
if (this._model) {
|
||||
this._model.enabled = false;
|
||||
}
|
||||
protected _updateModels () {
|
||||
if (!this.enabledInHierarchy || !this.node._scene || !this._mesh) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -205,6 +201,10 @@ export class ModelComponent extends RenderableComponent {
|
||||
this._model!.createBoundingShape(this._mesh.minPosition, this._mesh.maxPosition);
|
||||
|
||||
this._updateModelParams();
|
||||
|
||||
if (this._model) {
|
||||
this._model.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected _createModel () {
|
||||
@@ -252,7 +252,7 @@ export class ModelComponent extends RenderableComponent {
|
||||
}
|
||||
|
||||
private _updateCastShadow () {
|
||||
if (!this.enabled || !this._model) {
|
||||
if (!this.enabledInHierarchy || !this._model) {
|
||||
return;
|
||||
}
|
||||
if (this._shadowCastingMode === ModelShadowCastingMode.Off) {
|
||||
@@ -271,15 +271,15 @@ export class ModelComponent extends RenderableComponent {
|
||||
}
|
||||
|
||||
private _updateReceiveShadow () {
|
||||
if (!this.enabled || !this._model) {
|
||||
if (!this.enabledInHierarchy || !this._model) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < this._model.subModelNum; ++i) {
|
||||
const subModel = this._model.getSubModel(i);
|
||||
// if (subModel._defines['CC_USE_SHADOW_MAP'] != undefined) {
|
||||
// this.getMaterial(i).define('CC_USE_SHADOW_MAP', this._receiveShadows);
|
||||
// }
|
||||
}
|
||||
// for (let i = 0; i < this._model.subModelNum; ++i) {
|
||||
// const subModel = this._model.getSubModel(i);
|
||||
// if (subModel._defines['CC_USE_SHADOW_MAP'] != undefined) {
|
||||
// this.getMaterial(i).define('CC_USE_SHADOW_MAP', this._receiveShadows);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private _getBuiltinMaterial () {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { intersect } from '../3d/geom-utils';
|
||||
import { Root } from '../core/root';
|
||||
import { Mat4, Vec3 } from '../core/value-types';
|
||||
import { Mat4 } from '../core/value-types';
|
||||
import { mat4, vec3 } from '../core/vmath';
|
||||
import { GFXBuffer } from '../gfx/buffer';
|
||||
import { GFXBufferUsageBit, GFXFormat, GFXMemoryUsageBit, GFXType } from '../gfx/define';
|
||||
@@ -30,13 +30,13 @@ export class UBOGlobal {
|
||||
public static MAT_VIEW_PROJ_INV_OFFSET: number = UBOGlobal.MAT_VIEW_PROJ_OFFSET + 16;
|
||||
public static CAMERA_POS_OFFSET: number = UBOGlobal.MAT_VIEW_PROJ_INV_OFFSET + 16;
|
||||
public static DIR_LIGHT_DIR_OFFSET: number = UBOGlobal.CAMERA_POS_OFFSET + 4;
|
||||
public static DIR_LIGHT_COLOR_OFFSET: number = UBOGlobal.DIR_LIGHT_DIR_OFFSET + 16;
|
||||
public static POINT_LIGHT_POS_RANGE_OFFSET: number = UBOGlobal.DIR_LIGHT_COLOR_OFFSET + 16;
|
||||
public static POINT_LIGHT_COLOR_OFFSET: number = UBOGlobal.POINT_LIGHT_POS_RANGE_OFFSET + 16;
|
||||
public static SPOT_LIGHT_POS_RANGE_OFFSET: number = UBOGlobal.POINT_LIGHT_COLOR_OFFSET + 16;
|
||||
public static SPOT_LIGHT_DIR_OFFSET: number = UBOGlobal.SPOT_LIGHT_POS_RANGE_OFFSET + 16;
|
||||
public static SPOT_LIGHT_COLOR_OFFSET: number = UBOGlobal.SPOT_LIGHT_DIR_OFFSET + 16;
|
||||
public static COUNT: number = UBOGlobal.SPOT_LIGHT_COLOR_OFFSET + 16;
|
||||
public static DIR_LIGHT_COLOR_OFFSET: number = UBOGlobal.DIR_LIGHT_DIR_OFFSET + UBOGlobal.MAX_DIR_LIGHTS * 4;
|
||||
public static POINT_LIGHT_POS_RANGE_OFFSET: number = UBOGlobal.DIR_LIGHT_COLOR_OFFSET + UBOGlobal.MAX_DIR_LIGHTS * 4;
|
||||
public static POINT_LIGHT_COLOR_OFFSET: number = UBOGlobal.POINT_LIGHT_POS_RANGE_OFFSET + UBOGlobal.MAX_POINT_LIGHTS * 4;
|
||||
public static SPOT_LIGHT_POS_RANGE_OFFSET: number = UBOGlobal.POINT_LIGHT_COLOR_OFFSET + UBOGlobal.MAX_POINT_LIGHTS * 4;
|
||||
public static SPOT_LIGHT_DIR_OFFSET: number = UBOGlobal.SPOT_LIGHT_POS_RANGE_OFFSET + UBOGlobal.MAX_SPOT_LIGHTS * 4;
|
||||
public static SPOT_LIGHT_COLOR_OFFSET: number = UBOGlobal.SPOT_LIGHT_DIR_OFFSET + UBOGlobal.MAX_SPOT_LIGHTS * 4;
|
||||
public static COUNT: number = UBOGlobal.SPOT_LIGHT_COLOR_OFFSET + UBOGlobal.MAX_SPOT_LIGHTS * 4;
|
||||
public static SIZE: number = UBOGlobal.COUNT * 4;
|
||||
|
||||
public static BLOCK: GFXUniformBlock = {
|
||||
@@ -363,11 +363,11 @@ export abstract class RenderPipeline {
|
||||
const light = dLights[i];
|
||||
if (light && light.enabled) {
|
||||
light.update();
|
||||
this._uboGlobal.view.set(light.directionArray, UBOGlobal.DIR_LIGHT_DIR_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(light.colorData, UBOGlobal.DIR_LIGHT_COLOR_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(light.directionArray, UBOGlobal.DIR_LIGHT_DIR_OFFSET + i * 4);
|
||||
this._uboGlobal.view.set(light.colorData, UBOGlobal.DIR_LIGHT_COLOR_OFFSET + i * 4);
|
||||
} else {
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.DIR_LIGHT_DIR_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.DIR_LIGHT_COLOR_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.DIR_LIGHT_DIR_OFFSET + i * 4);
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.DIR_LIGHT_COLOR_OFFSET + i * 4);
|
||||
}
|
||||
}
|
||||
const pLights = scene.pointLights;
|
||||
@@ -375,11 +375,11 @@ export abstract class RenderPipeline {
|
||||
const light = pLights[i];
|
||||
if (light && light.enabled) {
|
||||
light.update();
|
||||
this._uboGlobal.view.set(light.positionAndRange, UBOGlobal.POINT_LIGHT_POS_RANGE_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(light.colorData, UBOGlobal.POINT_LIGHT_COLOR_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(light.positionAndRange, UBOGlobal.POINT_LIGHT_POS_RANGE_OFFSET + i * 4);
|
||||
this._uboGlobal.view.set(light.colorData, UBOGlobal.POINT_LIGHT_COLOR_OFFSET + i * 4);
|
||||
} else {
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.POINT_LIGHT_POS_RANGE_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.POINT_LIGHT_COLOR_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.POINT_LIGHT_POS_RANGE_OFFSET + i * 4);
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.POINT_LIGHT_COLOR_OFFSET + i * 4);
|
||||
}
|
||||
}
|
||||
const sLights = scene.spotLights;
|
||||
@@ -387,13 +387,13 @@ export abstract class RenderPipeline {
|
||||
const light = sLights[i];
|
||||
if (light && light.enabled) {
|
||||
light.update();
|
||||
this._uboGlobal.view.set(light.positionAndRange, UBOGlobal.SPOT_LIGHT_POS_RANGE_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(light.directionArray, UBOGlobal.SPOT_LIGHT_DIR_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(light.colorData, UBOGlobal.SPOT_LIGHT_COLOR_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(light.positionAndRange, UBOGlobal.SPOT_LIGHT_POS_RANGE_OFFSET + i * 4);
|
||||
this._uboGlobal.view.set(light.directionArray, UBOGlobal.SPOT_LIGHT_DIR_OFFSET + i * 4);
|
||||
this._uboGlobal.view.set(light.colorData, UBOGlobal.SPOT_LIGHT_COLOR_OFFSET + i * 4);
|
||||
} else {
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.SPOT_LIGHT_POS_RANGE_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.SPOT_LIGHT_DIR_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.SPOT_LIGHT_COLOR_OFFSET + 4 * i);
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.SPOT_LIGHT_POS_RANGE_OFFSET + i * 4);
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.SPOT_LIGHT_DIR_OFFSET + i * 4);
|
||||
this._uboGlobal.view.set(_idVec4Array, UBOGlobal.SPOT_LIGHT_COLOR_OFFSET + i * 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Light, LightType } from './light';
|
||||
import { RenderScene } from './render-scene';
|
||||
import { Node } from '../../scene-graph/node';
|
||||
|
||||
const _forward = new Vec3(0, 0, 1);
|
||||
const _forward = new Vec3(0, 0, -1);
|
||||
const _v3 = new Vec3();
|
||||
const _qt = new Quat();
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ import { RenderScene } from './render-scene';
|
||||
import { Node } from '../../scene-graph/node';
|
||||
|
||||
export enum LightType {
|
||||
UNKNOWN,
|
||||
DIRECTIONAL,
|
||||
POINT,
|
||||
SPOT,
|
||||
UNKNOWN,
|
||||
}
|
||||
|
||||
export class Light {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Light, LightType } from './light';
|
||||
import { RenderScene } from './render-scene';
|
||||
import { Node } from '../../scene-graph/node';
|
||||
|
||||
const _forward = new Vec3(0, 0, 1);
|
||||
const _forward = new Vec3(0, 0, -1);
|
||||
const _v3 = new Vec3();
|
||||
const _qt = new Quat();
|
||||
|
||||
|
||||
+12
-15
@@ -567,9 +567,9 @@ class Node extends EventTarget(BaseNode) {
|
||||
*/
|
||||
public setPosition (val: Vec3 | number, y?: number, z?: number) {
|
||||
if (y === undefined || z === undefined) {
|
||||
vec3.copy(this._lpos, val);
|
||||
vec3.copy(this._lpos, val as Vec3);
|
||||
} else if (arguments.length === 3) {
|
||||
vec3.set(this._lpos, val, y, z);
|
||||
vec3.set(this._lpos, val as number, y, z);
|
||||
}
|
||||
vec3.copy(this._pos, this._lpos);
|
||||
|
||||
@@ -607,9 +607,9 @@ class Node extends EventTarget(BaseNode) {
|
||||
|
||||
public setRotation (val: Quat | number, y?: number, z?: number, w?: number) {
|
||||
if (y === undefined || z === undefined || w === undefined) {
|
||||
quat.copy(this._lrot, val);
|
||||
quat.copy(this._lrot, val as Quat);
|
||||
} else if (arguments.length === 4) {
|
||||
quat.set(this._lrot, val, y, z, w);
|
||||
quat.set(this._lrot, val as number, y, z, w);
|
||||
}
|
||||
quat.copy(this._rot, this._lrot);
|
||||
this._eulerDirty = true;
|
||||
@@ -669,9 +669,9 @@ class Node extends EventTarget(BaseNode) {
|
||||
*/
|
||||
public setScale (val: Vec3 | number, y?: number, z?: number) {
|
||||
if (y === undefined || z === undefined) {
|
||||
vec3.copy(this._lscale, val);
|
||||
vec3.copy(this._lscale, val as Vec3);
|
||||
} else if (arguments.length === 3) {
|
||||
vec3.set(this._lscale, val, y, z);
|
||||
vec3.set(this._lscale, val as number, y, z);
|
||||
}
|
||||
vec3.copy(this._scale, this._lscale);
|
||||
|
||||
@@ -714,9 +714,9 @@ class Node extends EventTarget(BaseNode) {
|
||||
*/
|
||||
public setWorldPosition (val: Vec3 | number, y?: number, z?: number) {
|
||||
if (y === undefined || z === undefined) {
|
||||
vec3.copy(this._pos, val);
|
||||
vec3.copy(this._pos, val as Vec3);
|
||||
} else if (arguments.length === 3) {
|
||||
vec3.set(this._pos, val, y, z);
|
||||
vec3.set(this._pos, val as number, y, z);
|
||||
}
|
||||
const parent = this._parent;
|
||||
const local = this._lpos;
|
||||
@@ -771,9 +771,9 @@ class Node extends EventTarget(BaseNode) {
|
||||
*/
|
||||
public setWorldRotation (val: Quat | number, y?: number, z?: number, w?: number) {
|
||||
if (y === undefined || z === undefined || w === undefined) {
|
||||
quat.copy(this._rot, val);
|
||||
quat.copy(this._rot, val as Quat);
|
||||
} else if (arguments.length === 4) {
|
||||
quat.set(this._rot, val, y, z, w);
|
||||
quat.set(this._rot, val as number, y, z, w);
|
||||
}
|
||||
if (this._parent) {
|
||||
this._parent.getWorldRotation(q_a);
|
||||
@@ -894,11 +894,8 @@ class Node extends EventTarget(BaseNode) {
|
||||
*/
|
||||
public getWorldRS (out?: Mat4): Mat4 {
|
||||
this.updateWorldTransformFull();
|
||||
if (out) {
|
||||
mat4.copy(out, this._mat);
|
||||
} else {
|
||||
out = mat4.copy(new Mat4(), this._mat);
|
||||
}
|
||||
if (out === undefined) { out = new Mat4(); }
|
||||
mat4.copy(out, this._mat);
|
||||
out.m12 = 0; out.m13 = 0; out.m14 = 0;
|
||||
return out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user