|
@@ -3,6 +3,8 @@ import { Vector3, Matrix, Vector4 } from "babylonjs/Maths/math";
|
|
|
import { Observable } from "babylonjs/Misc/observable";
|
|
|
import { PropertyChangedEvent } from "./propertyChangedEvent";
|
|
|
import { Vector4LineComponent } from './vector4LineComponent';
|
|
|
+import { OptionsLineComponent } from './optionsLineComponent';
|
|
|
+import { SliderLineComponent } from './sliderLineComponent';
|
|
|
|
|
|
interface IMatrixLineComponentProps {
|
|
|
label: string;
|
|
@@ -10,10 +12,12 @@ interface IMatrixLineComponentProps {
|
|
|
propertyName: string;
|
|
|
step?: number;
|
|
|
onChange?: (newValue: Matrix) => void;
|
|
|
+ onModeChange?: (mode: number) => void;
|
|
|
onPropertyChangedObservable?: Observable<PropertyChangedEvent>;
|
|
|
+ mode?: number;
|
|
|
}
|
|
|
|
|
|
-export class MatrixLineComponent extends React.Component<IMatrixLineComponentProps, { value: Matrix}> {
|
|
|
+export class MatrixLineComponent extends React.Component<IMatrixLineComponentProps, { value: Matrix, mode: number, angle: number}> {
|
|
|
private _localChange = false;
|
|
|
|
|
|
constructor(props: IMatrixLineComponentProps) {
|
|
@@ -21,10 +25,10 @@ export class MatrixLineComponent extends React.Component<IMatrixLineComponentPro
|
|
|
|
|
|
let matrix: Matrix = this.props.target[this.props.propertyName].clone();
|
|
|
|
|
|
- this.state = { value:matrix }
|
|
|
+ this.state = { value:matrix, mode: this.props.mode || 0, angle: 0 }
|
|
|
}
|
|
|
|
|
|
- shouldComponentUpdate(nextProps: IMatrixLineComponentProps, nextState: { value: Matrix }) {
|
|
|
+ shouldComponentUpdate(nextProps: IMatrixLineComponentProps, nextState: { value: Matrix, mode: number, angle: number }) {
|
|
|
const nextPropsValue = nextProps.target[nextProps.propertyName];
|
|
|
|
|
|
if (!nextPropsValue.equals(nextState.value) || this._localChange) {
|
|
@@ -32,7 +36,7 @@ export class MatrixLineComponent extends React.Component<IMatrixLineComponentPro
|
|
|
this._localChange = false;
|
|
|
return true;
|
|
|
}
|
|
|
- return false;
|
|
|
+ return nextState.mode !== this.state.mode || nextState.angle !== this.state.angle;
|
|
|
}
|
|
|
|
|
|
raiseOnPropertyChanged(previousValue: Vector3) {
|
|
@@ -67,7 +71,35 @@ export class MatrixLineComponent extends React.Component<IMatrixLineComponentPro
|
|
|
this.updateMatrix();
|
|
|
}
|
|
|
|
|
|
+ updateBasedOnMode(value: number) {
|
|
|
+
|
|
|
+ switch (this.state.mode) {
|
|
|
+ case 1: {
|
|
|
+ Matrix.RotationXToRef(this.state.angle, this.state.value);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 2: {
|
|
|
+ Matrix.RotationYToRef(this.state.angle, this.state.value);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 3: {
|
|
|
+ Matrix.RotationZToRef(this.state.angle, this.state.value);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.updateMatrix();
|
|
|
+
|
|
|
+ this.setState({angle: value});
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
+ var modeOptions = [
|
|
|
+ { label: "User-defined", value: 0 },
|
|
|
+ { label: "Rotation over X axis", value: 1 },
|
|
|
+ { label: "Rotation over Y axis", value: 2 },
|
|
|
+ { label: "Rotation over Z axis", value: 3 },
|
|
|
+ ];
|
|
|
+
|
|
|
return (
|
|
|
<div className="vector3Line">
|
|
|
<div className="firstLine">
|
|
@@ -76,11 +108,40 @@ export class MatrixLineComponent extends React.Component<IMatrixLineComponentPro
|
|
|
</div>
|
|
|
</div>
|
|
|
<div className="secondLine">
|
|
|
- <Vector4LineComponent label="Row #0" value={this.state.value.getRow(0)!} onChange={value => this.updateRow(value, 0)}/>
|
|
|
- <Vector4LineComponent label="Row #1" value={this.state.value.getRow(1)!} onChange={value => this.updateRow(value, 1)}/>
|
|
|
- <Vector4LineComponent label="Row #2" value={this.state.value.getRow(2)!} onChange={value => this.updateRow(value, 2)}/>
|
|
|
- <Vector4LineComponent label="Row #3" value={this.state.value.getRow(3)!} onChange={value => this.updateRow(value, 3)}/>
|
|
|
- </div>
|
|
|
+ <OptionsLineComponent label="Mode"
|
|
|
+ className="no-right-margin"
|
|
|
+ options={modeOptions} target={this}
|
|
|
+ noDirectUpdate={true}
|
|
|
+ getSelection={() => {
|
|
|
+ return this.state.mode;
|
|
|
+ }}
|
|
|
+ onSelect={(value: any) => {
|
|
|
+ this.props.target[this.props.propertyName] = Matrix.Identity();
|
|
|
+ Matrix.IdentityToRef(this.state.value);
|
|
|
+ this.setState({mode: value, angle: 0});
|
|
|
+
|
|
|
+ this.updateMatrix();
|
|
|
+
|
|
|
+ if (this.props.onModeChange) {
|
|
|
+ this.props.onModeChange(value);
|
|
|
+ }
|
|
|
+ }} />
|
|
|
+ </div>
|
|
|
+ {
|
|
|
+ this.state.mode === 0 &&
|
|
|
+ <div className="secondLine">
|
|
|
+ <Vector4LineComponent label="Row #0" value={this.state.value.getRow(0)!} onChange={value => this.updateRow(value, 0)}/>
|
|
|
+ <Vector4LineComponent label="Row #1" value={this.state.value.getRow(1)!} onChange={value => this.updateRow(value, 1)}/>
|
|
|
+ <Vector4LineComponent label="Row #2" value={this.state.value.getRow(2)!} onChange={value => this.updateRow(value, 2)}/>
|
|
|
+ <Vector4LineComponent label="Row #3" value={this.state.value.getRow(3)!} onChange={value => this.updateRow(value, 3)}/>
|
|
|
+ </div>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ this.state.mode !== 0 &&
|
|
|
+ <div className="secondLine">
|
|
|
+ <SliderLineComponent label="Angle" minimum={0} maximum={2 * Math.PI} useEuler={true} step={0.1} directValue={this.state.angle} onChange={value => this.updateBasedOnMode(value)}/>
|
|
|
+ </div>
|
|
|
+ }
|
|
|
</div>
|
|
|
);
|
|
|
}
|