ソースを参照

"Generate replay code" adds toLinearSpace() as appropriate

Popov72 5 年 前
コミット
71d0ae2d2d

+ 6 - 4
inspector/src/components/actionTabs/lines/color3LineComponent.tsx

@@ -26,6 +26,8 @@ export class Color3LineComponent extends React.Component<IColor3LineComponentPro
         if (props.isLinear) {
             this.state.color.toGammaSpaceToRef(this.state.color);
         }
+
+        props.target._isLinearColor = props.isLinear; // so that replayRecorder can append toLinearSpace() as appropriate
     }
 
     shouldComponentUpdate(nextProps: IColor3LineComponentProps, nextState: { color: Color3 }) {
@@ -55,8 +57,8 @@ export class Color3LineComponent extends React.Component<IColor3LineComponentPro
             this.props.onPropertyChangedObservable.notifyObservers({
                 object: this.props.target,
                 property: this.props.propertyName,
-                value: this.props.isLinear ? newColor.toLinearSpace() : newColor,
-                initialValue: this.props.isLinear ? this.state.color.toLinearSpace() : this.state.color,
+                value: newColor,
+                initialValue: this.state.color,
             });
         }
 
@@ -77,8 +79,8 @@ export class Color3LineComponent extends React.Component<IColor3LineComponentPro
         this.props.onPropertyChangedObservable.notifyObservers({
             object: this.props.target,
             property: this.props.propertyName,
-            value: this.props.isLinear ? this.state.color.toLinearSpace() : this.state.color,
-            initialValue: this.props.isLinear ? previousValue.toLinearSpace() : previousValue,
+            value: this.state.color,
+            initialValue: previousValue,
         });
     }
 

+ 6 - 4
inspector/src/components/actionTabs/lines/color4LineComponent.tsx

@@ -29,6 +29,8 @@ export class Color4LineComponent extends React.Component<IColor4LineComponentPro
         if (props.isLinear) {
             this.state.color.toGammaSpaceToRef(this.state.color);
         }
+
+        props.target._isLinearColor = props.isLinear; // so that replayRecorder can append toLinearSpace() as appropriate
     }
 
     shouldComponentUpdate(nextProps: IColor4LineComponentProps, nextState: { color: Color4 }) {
@@ -63,8 +65,8 @@ export class Color4LineComponent extends React.Component<IColor4LineComponentPro
             this.props.onPropertyChangedObservable.notifyObservers({
                 object: this.props.target,
                 property: this.props.propertyName,
-                value: this.props.isLinear ? newColor.toLinearSpace() : newColor,
-                initialValue: this.props.isLinear ? this.state.color.toLinearSpace() : this.state.color,
+                value: newColor,
+                initialValue: this.state.color,
             });
         }
 
@@ -91,8 +93,8 @@ export class Color4LineComponent extends React.Component<IColor4LineComponentPro
         this.props.onPropertyChangedObservable.notifyObservers({
             object: this.props.target,
             property: this.props.propertyName,
-            value: this.props.isLinear ? this.state.color.toLinearSpace() : this.state.color,
-            initialValue: this.props.isLinear ? previousValue.toLinearSpace() : previousValue,
+            value: this.state.color,
+            initialValue: previousValue,
         });
     }
 

+ 6 - 0
inspector/src/components/replayRecorder.ts

@@ -61,8 +61,14 @@ export class ReplayRecorder {
             value = `new BABYLON.Vector2(${value.x}, ${value.y})`;
         } else if (value.a !== undefined) { // Color4
             value = `new BABYLON.Color4(${value.r}, ${value.g}, ${value.b}, ${value.a})`;
+            if (event.object._isLinearColor) {
+                value += '.toLinearSpace()';
+            }
         } else if (value.b !== undefined) { // Color3
             value = `new BABYLON.Color3(${value.r}, ${value.g}, ${value.b})`;
+            if (event.object._isLinearColor) {
+                value += '.toLinearSpace()';
+            }
         } else if (value.getClassName) {
             value = this._getIndirectData(value);
         }