Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as bjs from 'babylonjs';
- import {
- Scene,
- } from '../Scene'
- import { SolidParticleSystemElement } from './SolidParticleSystemElement';
- import { OrderBook } from '../../market/orderbook';
- import { MarketSide } from '../../market/enums';
- export interface IValueFieldUpdateStrategy
- {
- valueField : ValueField
- preCalculate();
- updateParticle(particle : bjs.SolidParticle)
- }
- export class ValueFieldUpdateStrategy implements IValueFieldUpdateStrategy
- {
- constructor(public valueField:ValueField)
- {
- }
- public preCalculate()
- {
- this.onPreCalculate();
- }
- public updateParticle(particle : bjs.SolidParticle)
- {
- this.onUpdateParticle(particle);
- }
- protected onPreCalculate()
- {
- }
- protected onUpdateParticle(particle : bjs.SolidParticle)
- {
- }
- }
- export class SineWaveOscillator extends ValueFieldUpdateStrategy
- {
- protected theta: number = 0;
- constructor(valueField: ValueField, public speed: number, public frequency: number)
- {
- super(valueField);
- }
- protected onPreCalculate()
- {
- console.log('SineWaveOscillator : onPreCalculate()');
- this.theta += this.speed/60;
- }
- protected onUpdateParticle(particle : bjs.SolidParticle)
- {
- console.log('SineWaveOscillator : onUpdateParticle()');
- const currentRow: number = particle.idx / this.valueField.columns;
- const currentColumn: number = particle.idx % this.valueField.columns;
- let cellOffset: number = currentRow * - this.frequency;
- particle.scaling.y = particle.scaling.y + (Math.sin(this.theta + cellOffset) * 5);
- particle.position.y = particle.scaling.y * 0.5;
- }
- }
- export class ValueField extends SolidParticleSystemElement
- {
- private cellHeight: number = 5;
- private cellWidth: number = 1;
- private cellDepth: number = 1;
- private updateStrategy:ValueFieldUpdateStrategy;
- constructor(name:string, public x: number, public y: number, public z: number, scene:Scene, public rows:number, public columns: number)
- {
- super(
- name,
- x,
- y,
- z,
- scene,
- bjs.MeshBuilder.CreateBox("box", { height: 1, width: 0.9, depth:0.9 }, scene.bjsScene),
- new bjs.PBRMaterial(name + "-material", scene.bjsScene),
- rows * columns,
- );
- console.log('ValueField : constructor()');
- console.log('ValueField : creating ValueField with ' + rows + ' rows, and ' + columns + ' columns.');
- this.create();
- }
- protected create()
- {
- console.log('ValueField : create()');
- this.material.reflectionTexture = this.scene.hdrTexture;
- this.material.microSurface = 0.7;
- this.material.reflectivityColor = new bjs.Color3(0.85, 0.85, 0.85);
- this.material.albedoColor = new bjs.Color3(0.01, 0.01, 0.01);
- this.updateStrategy = this.createUpdateStrategy(this);
- this.posOptions = {
- positionFunction: this.onSetInitialParticlePosition
- }
- this.init();
- this.mesh.position.set(0, 0, 0);
- this.sps.computeParticleTexture = false; // prevents from computing particle.uvs
- this.sps.computeParticleColor = false; // prevents from computing particle.color
- this.sps.computeParticleVertex = false; // prevents from calling the custom updateParticleVertex() function
- }
- protected createUpdateStrategy(valueField : ValueField): ValueFieldUpdateStrategy
- {
- throw new Error("Implement in subclass. Factory Method.");
- return null;
- }
- protected onSetInitialParticlePosition = (particle: bjs.SolidParticle, i: number) =>
- {
- console.log('ValueField : onSetInitialParticlePosition()');
- const currentRow = i / this.columns;
- const currentColumn = i % this.columns;
- particle.position.set(currentColumn * this.cellWidth, particle.scaling.y * 0.5, currentRow * this.cellDepth * -1);
- }
- protected onPreRender()
- {
- console.log('ValueField : onPreRender()');
- this.updateStrategy.preCalculate();
- super.onPreRender();
- }
- protected onRender()
- {
- }
- protected onUpdateParticle = (particle : bjs.SolidParticle) =>
- {
- console.log('ValueField : onUpdateParticle()');
- this.updateStrategy.updateParticle(particle);
- return particle;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement