Skip to content

Commit

Permalink
Posterize nge (#14890)
Browse files Browse the repository at this point in the history
* fix posterize

* Improved debug node
  • Loading branch information
deltakosh authored Mar 20, 2024
1 parent aba5db5 commit b3a351d
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class PosterizeBlock extends NodeMaterialBlock {

this._inputs[0].excludedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Matrix);
this._inputs[1].excludedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Matrix);
this._inputs[1].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Float);
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/dev/core/src/Maths/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./math.polar";
export * from "./math";
export * from "./sphericalPolynomial";
export * from "./halton2DSequence";
export * from "./math.vector.functions";
31 changes: 31 additions & 0 deletions packages/dev/core/src/Maths/math.vector.functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Vector2, Vector3, Vector4 } from "./math.vector";

/**
* Creates a string representation of the Vector2
* @param vector defines the Vector2 to stringify
* @param decimalCount defines the number of decimals to use
* @returns a string with the Vector2 coordinates.
*/
export function Vector2ToFixed(vector: Vector2, decimalCount: number): string {
return `{X: ${vector.x.toFixed(decimalCount)} Y: ${vector.y.toFixed(decimalCount)}}`;
}

/**
* Creates a string representation of the Vector3
* @param vector defines the Vector3 to stringify
* @param decimalCount defines the number of decimals to use
* @returns a string with the Vector3 coordinates.
*/
export function Vector3ToFixed(vector: Vector3, decimalCount: number): string {
return `{X: ${vector._x.toFixed(decimalCount)} Y: ${vector._y.toFixed(decimalCount)} Z: ${vector._z.toFixed(decimalCount)}}`;
}

/**
* Creates a string representation of the Vector4
* @param vector defines the Vector4 to stringify
* @param decimalCount defines the number of decimals to use
* @returns a string with the Vector4 coordinates.
*/
export function Vector4ToFixed(vector: Vector4, decimalCount: number): string {
return `{X: ${vector.x.toFixed(decimalCount)} Y: ${vector.y.toFixed(decimalCount)} Z: ${vector.z.toFixed(decimalCount)} W: ${vector.w.toFixed(decimalCount)}}`;
}
20 changes: 17 additions & 3 deletions packages/dev/core/src/Meshes/Node/Blocks/debugBlock.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Vector2ToFixed, Vector3ToFixed, Vector4ToFixed } from "../../../Maths/math.vector.functions";
import { RegisterClass } from "../../../Misc/typeStore";
import { NodeGeometryBlockConnectionPointTypes } from "../Enums/nodeGeometryConnectionPointTypes";
import { NodeGeometryBlock } from "../nodeGeometryBlock";
Expand All @@ -11,7 +12,7 @@ export class DebugBlock extends NodeGeometryBlock {
/**
* Gets the log entries
*/
public log: string[] = [];
public log: string[][] = [];

/**
* Create a new DebugBlock
Expand Down Expand Up @@ -71,11 +72,24 @@ export class DebugBlock extends NodeGeometryBlock {
const input = this.input.getConnectedValue(state);

if (input === null || input === undefined) {
this.log.push("null");
this.log.push(["null", ""]);
return input;
}

this.log.push(input.toString());
switch (this.input.type) {
case NodeGeometryBlockConnectionPointTypes.Vector2:
this.log.push([Vector2ToFixed(input, 4), input.toString()]);
break;
case NodeGeometryBlockConnectionPointTypes.Vector3:
this.log.push([Vector3ToFixed(input, 4), input.toString()]);
break;
case NodeGeometryBlockConnectionPointTypes.Vector4:
this.log.push([Vector4ToFixed(input, 4), input.toString()]);
break;
default:
this.log.push([input.toString(), input.toString()]);
break;
}

return input;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Vector2, Vector3, Vector4 } from "../../../Maths/math.vector";
import { RegisterClass } from "../../../Misc/typeStore";
import { NodeGeometryBlockConnectionPointTypes } from "../Enums/nodeGeometryConnectionPointTypes";
import { NodeGeometryBlock } from "../nodeGeometryBlock";
Expand All @@ -24,6 +25,7 @@ export class GeometryPosterizeBlock extends NodeGeometryBlock {

this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Matrix);
this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Matrix);
this._inputs[1].acceptedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Float);
}

/**
Expand Down Expand Up @@ -65,7 +67,41 @@ export class GeometryPosterizeBlock extends NodeGeometryBlock {
this.output._storedFunction = (state) => {
const source = this.value.getConnectedValue(state);
const steps = this.steps.getConnectedValue(state);
return Math.floor((source / (1.0 / steps)) * (1.0 / steps));
let stepVector = steps;

if (this.steps.type === NodeGeometryBlockConnectionPointTypes.Float) {
switch (this.value.type) {
case NodeGeometryBlockConnectionPointTypes.Vector2:
stepVector = new Vector2(steps, steps);
break;
case NodeGeometryBlockConnectionPointTypes.Vector3:
stepVector = new Vector3(steps, steps, steps);
break;
case NodeGeometryBlockConnectionPointTypes.Vector4:
stepVector = new Vector4(steps, steps, steps, steps);
break;
}
}

switch (this.value.type) {
case NodeGeometryBlockConnectionPointTypes.Vector2:
return new Vector2((source.x / (1.0 / stepVector.x)) * (1.0 / stepVector.x), (source.y / (1.0 / stepVector.y)) * (1.0 / stepVector.y));
case NodeGeometryBlockConnectionPointTypes.Vector3:
return new Vector3(
(source.x / (1.0 / stepVector.x)) * (1.0 / stepVector.x),
(source.y / (1.0 / stepVector.y)) * (1.0 / stepVector.y),
(source.z / (1.0 / stepVector.z)) * (1.0 / stepVector.z)
);
case NodeGeometryBlockConnectionPointTypes.Vector4:
return new Vector4(
(source.x / (1.0 / stepVector.x)) * (1.0 / stepVector.x),
(source.y / (1.0 / stepVector.y)) * (1.0 / stepVector.y),
(source.z / (1.0 / stepVector.z)) * (1.0 / stepVector.z),
(source.w / (1.0 / stepVector.w)) * (1.0 / stepVector.w)
);
default:
return Math.floor((source / (1.0 / steps)) * (1.0 / steps));
}
};

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export class TextLineComponent extends React.Component<ITextLineComponentProps>

if (this.props.onLink || this.props.url) {
return (
<div className="link-value" title={this.props.value} onClick={() => this.onLink()}>
<div className="link-value" title={this.props.tooltip ?? this.props.label ?? ""} onClick={() => this.onLink()}>
{this.props.url ? "doc" : this.props.value || "no name"}
</div>
);
}
return (
<div className="value" title={this.props.value} style={{ color: this.props.color ? this.props.color : "" }}>
<div className="value" title={this.props.tooltip ?? this.props.label ?? ""} style={{ color: this.props.color ? this.props.color : "" }}>
{this.props.value || "no name"}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class DebugPropertyTabComponent extends React.Component<IPropertyComponen
<GeneralPropertyTabComponent stateManager={this.props.stateManager} nodeData={this.props.nodeData} />
<LineContainerComponent title="DEBUG INFOS">
{debugBlock.log.map((str, i) => {
return <TextLineComponent key={i} label={i + " >"} value={str} />;
return <TextLineComponent key={i} label={i + " >"} value={str[0]} tooltip={str[1]} />;
})}
</LineContainerComponent>
</div>
Expand Down

0 comments on commit b3a351d

Please sign in to comment.