mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 02:02:41 +08:00
change particle rendermode defines & adapt line billboard to new renderscene interface (#5806)
This commit is contained in:
@@ -161,12 +161,16 @@ export class Camera {
|
||||
|
||||
public attachToScene (scene: RenderScene) {
|
||||
this._scene = scene;
|
||||
if (this._view) { this._view.enable(true); }
|
||||
if (this._view) {
|
||||
this._view.enable(true);
|
||||
}
|
||||
}
|
||||
|
||||
public detachFromScene () {
|
||||
this._scene = null;
|
||||
if (this._view) { this._view.enable(false); }
|
||||
if (this._view) {
|
||||
this._view.enable(false);
|
||||
}
|
||||
}
|
||||
|
||||
public resize (width: number, height: number) {
|
||||
|
||||
@@ -117,10 +117,12 @@ export class BillboardComponent extends Component {
|
||||
super();
|
||||
}
|
||||
|
||||
public onLoad () {
|
||||
this.createModel();
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
if (!this._model) {
|
||||
this.createModel();
|
||||
}
|
||||
this.attachToScene();
|
||||
this._model!.enabled = true;
|
||||
this.width = this._width;
|
||||
this.height = this._height;
|
||||
@@ -129,8 +131,21 @@ export class BillboardComponent extends Component {
|
||||
}
|
||||
|
||||
public onDisable () {
|
||||
if (this._model) {
|
||||
this._model.enabled = false;
|
||||
this.detachFromScene();
|
||||
}
|
||||
|
||||
private attachToScene () {
|
||||
if (this._model && this.node && this.node.scene) {
|
||||
if (this._model.scene) {
|
||||
this.detachFromScene();
|
||||
}
|
||||
this._getRenderScene().addModel(this._model);
|
||||
}
|
||||
}
|
||||
|
||||
private detachFromScene () {
|
||||
if (this._model && this._model.scene) {
|
||||
this._model.scene.removeModel(this._model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +172,8 @@ export class BillboardComponent extends Component {
|
||||
],
|
||||
indices: [0, 1, 2, 1, 2, 3],
|
||||
}, undefined, { calculateBounds: false });
|
||||
this._model = this._getRenderScene().createModel(Model, this.node);
|
||||
this._model = cc.director.root.createModel(Model, this.node);
|
||||
this._model.initialize(this.node);
|
||||
if (this._material == null) {
|
||||
this._material = new Material();
|
||||
this._material.copy(builtinResMgr.get<Material>('default-billboard-material'));
|
||||
|
||||
@@ -199,19 +199,24 @@ export class LineComponent extends Component {
|
||||
super();
|
||||
}
|
||||
|
||||
public onLoad () {
|
||||
this._model = cc.director.root.createModel(LineModel);
|
||||
this._model.initialize(this.node);
|
||||
this._model.setCapacity(100);
|
||||
if (this._material == null) {
|
||||
this._material = new Material();
|
||||
this._material.copy(builtinResMgr.get<Material>('default-trail-material'));
|
||||
define[CC_USE_WORLD_SPACE] = this.worldSpace;
|
||||
this._material.recompileShaders(define);
|
||||
}
|
||||
this._model.setSubModelMaterial(0, this._material!);
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
if (!this._model) {
|
||||
this._model = this._getRenderScene().createModel(LineModel, this.node);
|
||||
this._model.setCapacity(100);
|
||||
if (this._material == null) {
|
||||
this._material = new Material();
|
||||
this._material.copy(builtinResMgr.get<Material>('default-trail-material'));
|
||||
define[CC_USE_WORLD_SPACE] = this.worldSpace;
|
||||
this._material.recompileShaders(define);
|
||||
}
|
||||
this._model.setSubModelMaterial(0, this._material!);
|
||||
return;
|
||||
}
|
||||
this._model!.enabled = true;
|
||||
this.attachToScene();
|
||||
this.texture = this.texture;
|
||||
this.tile = this._tile;
|
||||
this.offset = this._offset;
|
||||
@@ -220,7 +225,22 @@ export class LineComponent extends Component {
|
||||
|
||||
public onDisable () {
|
||||
if (this._model) {
|
||||
this._model.enabled = false;
|
||||
this.detachFromScene();
|
||||
}
|
||||
}
|
||||
|
||||
private attachToScene () {
|
||||
if (this._model && this.node && this.node.scene) {
|
||||
if (this._model.scene) {
|
||||
this.detachFromScene();
|
||||
}
|
||||
this._getRenderScene().addModel(this._model);
|
||||
}
|
||||
}
|
||||
|
||||
private detachFromScene () {
|
||||
if (this._model && this._model.scene) {
|
||||
this._model.scene.removeModel(this._model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ export class LineModel extends Model {
|
||||
private _vertCount: number = 0;
|
||||
private _indexCount: number = 0;
|
||||
|
||||
constructor (scene: RenderScene, node: INode) {
|
||||
super(scene, node);
|
||||
constructor () {
|
||||
super();
|
||||
this._capacity = 100;
|
||||
this._iaInfo = {
|
||||
drawInfos: [{
|
||||
|
||||
@@ -23,11 +23,13 @@ const _uvs = [
|
||||
];
|
||||
|
||||
const CC_USE_WORLD_SPACE = 'CC_USE_WORLD_SPACE';
|
||||
const CC_USE_BILLBOARD = 'CC_USE_BILLBOARD';
|
||||
const CC_USE_STRETCHED_BILLBOARD = 'CC_USE_STRETCHED_BILLBOARD';
|
||||
const CC_USE_HORIZONTAL_BILLBOARD = 'CC_USE_HORIZONTAL_BILLBOARD';
|
||||
const CC_USE_VERTICAL_BILLBOARD = 'CC_USE_VERTICAL_BILLBOARD';
|
||||
const CC_USE_MESH = 'CC_USE_MESH';
|
||||
|
||||
const CC_RENDER_MODE = 'CC_RENDER_MODE';
|
||||
const RENDER_MODE_BILLBOARD = 0;
|
||||
const RENDER_MODE_STRETCHED_BILLBOARD = 1;
|
||||
const RENDER_MODE_HORIZONTAL_BILLBOARD = 2;
|
||||
const RENDER_MODE_VERTICAL_BILLBOARD = 3;
|
||||
const RENDER_MODE_MESH = 4;
|
||||
|
||||
const _vertex_attrs = [
|
||||
{ name: GFXAttributeName.ATTR_POSITION, format: GFXFormat.RGB32F }, // position
|
||||
@@ -466,37 +468,17 @@ export default class ParticleSystemRenderer {
|
||||
}
|
||||
|
||||
if (this._renderMode === RenderMode.Billboard) {
|
||||
this._defines[CC_USE_BILLBOARD] = true;
|
||||
this._defines[CC_USE_STRETCHED_BILLBOARD] = false;
|
||||
this._defines[CC_USE_HORIZONTAL_BILLBOARD] = false;
|
||||
this._defines[CC_USE_VERTICAL_BILLBOARD] = false;
|
||||
this._defines[CC_USE_MESH] = false;
|
||||
this._defines[CC_RENDER_MODE] = RENDER_MODE_BILLBOARD;
|
||||
} else if (this._renderMode === RenderMode.StrecthedBillboard) {
|
||||
this._defines[CC_USE_BILLBOARD] = false;
|
||||
this._defines[CC_USE_STRETCHED_BILLBOARD] = true;
|
||||
this._defines[CC_USE_HORIZONTAL_BILLBOARD] = false;
|
||||
this._defines[CC_USE_VERTICAL_BILLBOARD] = false;
|
||||
this._defines[CC_USE_MESH] = false;
|
||||
this._defines[CC_RENDER_MODE] = RENDER_MODE_STRETCHED_BILLBOARD;
|
||||
this.frameTile_velLenScale.z = this._velocityScale;
|
||||
this.frameTile_velLenScale.w = this._lengthScale;
|
||||
} else if (this._renderMode === RenderMode.HorizontalBillboard) {
|
||||
this._defines[CC_USE_BILLBOARD] = false;
|
||||
this._defines[CC_USE_STRETCHED_BILLBOARD] = false;
|
||||
this._defines[CC_USE_HORIZONTAL_BILLBOARD] = true;
|
||||
this._defines[CC_USE_VERTICAL_BILLBOARD] = false;
|
||||
this._defines[CC_USE_MESH] = false;
|
||||
this._defines[CC_RENDER_MODE] = RENDER_MODE_HORIZONTAL_BILLBOARD;
|
||||
} else if (this._renderMode === RenderMode.VerticalBillboard) {
|
||||
this._defines[CC_USE_BILLBOARD] = false;
|
||||
this._defines[CC_USE_STRETCHED_BILLBOARD] = false;
|
||||
this._defines[CC_USE_HORIZONTAL_BILLBOARD] = false;
|
||||
this._defines[CC_USE_VERTICAL_BILLBOARD] = true;
|
||||
this._defines[CC_USE_MESH] = false;
|
||||
this._defines[CC_RENDER_MODE] = RENDER_MODE_VERTICAL_BILLBOARD;
|
||||
} else if (this._renderMode === RenderMode.Mesh) {
|
||||
this._defines[CC_USE_BILLBOARD] = false;
|
||||
this._defines[CC_USE_STRETCHED_BILLBOARD] = false;
|
||||
this._defines[CC_USE_HORIZONTAL_BILLBOARD] = false;
|
||||
this._defines[CC_USE_VERTICAL_BILLBOARD] = false;
|
||||
this._defines[CC_USE_MESH] = true;
|
||||
this._defines[CC_RENDER_MODE] = RENDER_MODE_MESH;
|
||||
} else {
|
||||
console.warn(`particle system renderMode ${this._renderMode} not support.`);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ export class UIModelComponent extends UIComponent {
|
||||
}
|
||||
|
||||
this._modelComponent._sceneGetter = null;
|
||||
if (cc.isValid(this.node, true)) {
|
||||
if (cc.isValid(this._modelComponent, true)) {
|
||||
this._modelComponent._attachToScene();
|
||||
}
|
||||
this._models = null;
|
||||
|
||||
Reference in New Issue
Block a user