|
@@ -14,24 +14,29 @@ interface ITextureLineComponentProps {
|
|
width: number;
|
|
width: number;
|
|
height: number;
|
|
height: number;
|
|
globalState?: GlobalState;
|
|
globalState?: GlobalState;
|
|
- hideChannelSelect?:boolean;
|
|
|
|
|
|
+ hideChannelSelect?: boolean;
|
|
}
|
|
}
|
|
|
|
|
|
-export class TextureLineComponent extends React.Component<ITextureLineComponentProps, { displayRed: boolean, displayGreen: boolean, displayBlue: boolean, displayAlpha: boolean, face: number }> {
|
|
|
|
|
|
+enum ChannelToDisplay {
|
|
|
|
+ R,
|
|
|
|
+ G,
|
|
|
|
+ B,
|
|
|
|
+ A,
|
|
|
|
+ All
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export class TextureLineComponent extends React.Component<ITextureLineComponentProps, { channel: ChannelToDisplay, face: number }> {
|
|
constructor(props: ITextureLineComponentProps) {
|
|
constructor(props: ITextureLineComponentProps) {
|
|
super(props);
|
|
super(props);
|
|
|
|
|
|
this.state = {
|
|
this.state = {
|
|
- displayRed: true,
|
|
|
|
- displayGreen: true,
|
|
|
|
- displayBlue: true,
|
|
|
|
- displayAlpha: true,
|
|
|
|
|
|
+ channel: ChannelToDisplay.All,
|
|
face: 0
|
|
face: 0
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- shouldComponentUpdate(nextProps: ITextureLineComponentProps, nextState: { displayRed: boolean, displayGreen: boolean, displayBlue: boolean, displayAlpha: boolean, face: number }): boolean {
|
|
|
|
- return (nextProps.texture !== this.props.texture || nextState.displayRed !== this.state.displayRed || nextState.displayGreen !== this.state.displayGreen || nextState.displayBlue !== this.state.displayBlue || nextState.displayAlpha !== this.state.displayAlpha || nextState.face !== this.state.face);
|
|
|
|
|
|
+ shouldComponentUpdate(nextProps: ITextureLineComponentProps, nextState: { channel: ChannelToDisplay, face: number }): boolean {
|
|
|
|
+ return (nextProps.texture !== this.props.texture || nextState.channel !== this.state.channel || nextState.face !== this.state.face);
|
|
}
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
@@ -44,8 +49,8 @@ export class TextureLineComponent extends React.Component<ITextureLineComponentP
|
|
|
|
|
|
updatePreview() {
|
|
updatePreview() {
|
|
var texture = this.props.texture;
|
|
var texture = this.props.texture;
|
|
- if(!texture.isReady() && texture._texture){
|
|
|
|
- texture._texture.onLoadedObservable.addOnce(()=>{
|
|
|
|
|
|
+ if (!texture.isReady() && texture._texture) {
|
|
|
|
+ texture._texture.onLoadedObservable.addOnce(() => {
|
|
this.updatePreview();
|
|
this.updatePreview();
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -78,10 +83,10 @@ export class TextureLineComponent extends React.Component<ITextureLineComponentP
|
|
|
|
|
|
const previewCanvas = this.refs.canvas as HTMLCanvasElement;
|
|
const previewCanvas = this.refs.canvas as HTMLCanvasElement;
|
|
|
|
|
|
- if(this.props.globalState){
|
|
|
|
|
|
+ if (this.props.globalState) {
|
|
this.props.globalState.blockMutationUpdates = true;
|
|
this.props.globalState.blockMutationUpdates = true;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
let rtt = new RenderTargetTexture(
|
|
let rtt = new RenderTargetTexture(
|
|
"temp",
|
|
"temp",
|
|
{ width: width, height: height },
|
|
{ width: width, height: height },
|
|
@@ -104,27 +109,31 @@ export class TextureLineComponent extends React.Component<ITextureLineComponentP
|
|
var data = engine.readPixels(0, 0, width, height);
|
|
var data = engine.readPixels(0, 0, width, height);
|
|
|
|
|
|
if (!texture.isCube) {
|
|
if (!texture.isCube) {
|
|
- if (!this.state.displayRed || !this.state.displayGreen || !this.state.displayBlue) {
|
|
|
|
|
|
+ if (this.state.channel != ChannelToDisplay.All) {
|
|
for (var i = 0; i < width * height * 4; i += 4) {
|
|
for (var i = 0; i < width * height * 4; i += 4) {
|
|
|
|
|
|
- if (!this.state.displayRed) {
|
|
|
|
- data[i] = 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!this.state.displayGreen) {
|
|
|
|
- data[i + 1] = 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!this.state.displayBlue) {
|
|
|
|
- data[i + 2] = 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this.state.displayAlpha) {
|
|
|
|
- var alpha = data[i + 2];
|
|
|
|
- data[i] = alpha;
|
|
|
|
- data[i + 1] = alpha;
|
|
|
|
- data[i + 2] = alpha;
|
|
|
|
- data[i + 2] = 0;
|
|
|
|
|
|
+ switch (this.state.channel) {
|
|
|
|
+ case ChannelToDisplay.R:
|
|
|
|
+ data[i + 1] = data[i];
|
|
|
|
+ data[i + 2] = data[i];
|
|
|
|
+ data[i + 3] = 255;
|
|
|
|
+ break;
|
|
|
|
+ case ChannelToDisplay.G:
|
|
|
|
+ data[i] = data[i + 1];
|
|
|
|
+ data[i + 2] = data[i];
|
|
|
|
+ data[i + 3] = 255;
|
|
|
|
+ break;
|
|
|
|
+ case ChannelToDisplay.B:
|
|
|
|
+ data[i] = data[i + 2];
|
|
|
|
+ data[i + 1] = data[i + 2];
|
|
|
|
+ data[i + 3] = 255;
|
|
|
|
+ break;
|
|
|
|
+ case ChannelToDisplay.A:
|
|
|
|
+ data[i] = data[i + 3];
|
|
|
|
+ data[i + 1] = data[i + 3];
|
|
|
|
+ data[i + 2] = data[i + 3];
|
|
|
|
+ data[i + 3] = 255;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -165,10 +174,10 @@ export class TextureLineComponent extends React.Component<ITextureLineComponentP
|
|
passPostProcess.dispose();
|
|
passPostProcess.dispose();
|
|
|
|
|
|
previewCanvas.style.height = height + "px";
|
|
previewCanvas.style.height = height + "px";
|
|
- if(this.props.globalState){
|
|
|
|
|
|
+ if (this.props.globalState) {
|
|
this.props.globalState.blockMutationUpdates = false;
|
|
this.props.globalState.blockMutationUpdates = false;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
render() {
|
|
render() {
|
|
@@ -190,11 +199,11 @@ export class TextureLineComponent extends React.Component<ITextureLineComponentP
|
|
{
|
|
{
|
|
!this.props.hideChannelSelect && !texture.isCube &&
|
|
!this.props.hideChannelSelect && !texture.isCube &&
|
|
<div className="control">
|
|
<div className="control">
|
|
- <button className={this.state.displayRed && !this.state.displayGreen ? "red command selected" : "red command"} onClick={() => this.setState({ displayRed: true, displayGreen: false, displayBlue: false, displayAlpha: false })}>R</button>
|
|
|
|
- <button className={this.state.displayGreen && !this.state.displayBlue ? "green command selected" : "green command"} onClick={() => this.setState({ displayRed: false, displayGreen: true, displayBlue: false, displayAlpha: false })}>G</button>
|
|
|
|
- <button className={this.state.displayBlue && !this.state.displayAlpha ? "blue command selected" : "blue command"} onClick={() => this.setState({ displayRed: false, displayGreen: false, displayBlue: true, displayAlpha: false })}>B</button>
|
|
|
|
- <button className={this.state.displayAlpha && !this.state.displayRed ? "alpha command selected" : "alpha command"} onClick={() => this.setState({ displayRed: false, displayGreen: false, displayBlue: false, displayAlpha: true })}>A</button>
|
|
|
|
- <button className={this.state.displayRed && this.state.displayGreen ? "all command selected" : "all command"} onClick={() => this.setState({ displayRed: true, displayGreen: true, displayBlue: true, displayAlpha: true })}>ALL</button>
|
|
|
|
|
|
+ <button className={this.state.channel === ChannelToDisplay.R ? "red command selected" : "red command"} onClick={() => this.setState({ channel: ChannelToDisplay.R })}>R</button>
|
|
|
|
+ <button className={this.state.channel === ChannelToDisplay.G ? "green command selected" : "green command"} onClick={() => this.setState({ channel: ChannelToDisplay.G })}>G</button>
|
|
|
|
+ <button className={this.state.channel === ChannelToDisplay.B ? "blue command selected" : "blue command"} onClick={() => this.setState({ channel: ChannelToDisplay.B })}>B</button>
|
|
|
|
+ <button className={this.state.channel === ChannelToDisplay.A ? "alpha command selected" : "alpha command"} onClick={() => this.setState({ channel: ChannelToDisplay.A })}>A</button>
|
|
|
|
+ <button className={this.state.channel === ChannelToDisplay.All ? "all command selected" : "all command"} onClick={() => this.setState({ channel: ChannelToDisplay.All })}>ALL</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
<canvas ref="canvas" className="preview" />
|
|
<canvas ref="canvas" className="preview" />
|