Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NME: Add a RealTime input #13418

Merged
merged 3 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/dev/core/src/Engines/thinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import type { RenderTargetTexture } from "../Materials/Textures/renderTargetText
import type { WebRequest } from "../Misc/webRequest";
import type { LoadFileError } from "../Misc/fileTools";
import type { Texture } from "../Materials/Textures/texture";
import { PrecisionDate } from "core/Misc/precisionDate";

/**
* Defines the interface used by objects working like Scene
Expand Down Expand Up @@ -350,6 +351,11 @@ export class ThinEngine {
return this._frameId;
}

/**
* The time (in milliseconds elapsed since the current page has been loaded) when the engine was initialized
*/
public readonly startTime: number;

/** @internal */
public _uniformBuffers = new Array<UniformBuffer>();
/** @internal */
Expand Down Expand Up @@ -759,6 +765,8 @@ export class ThinEngine {
options?: EngineOptions,
adaptToDeviceRatio?: boolean
) {
this.startTime = PrecisionDate.Now;

let canvas: Nullable<HTMLCanvasElement> = null;

options = options || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
export enum AnimatedInputBlockTypes {
/** No animation */
None,
/** Time based animation. Will only work for floats */
/** Time based animation (is incremented by 0.6 each second). Will only work for floats */
Time,
/** Time elapsed (in seconds) since the engine was initialized. Will only work for floats */
RealTime,
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Color3, Color4, TmpColors } from "../../../../Maths/math";
import { AnimatedInputBlockTypes } from "./animatedInputBlockTypes";
import { Observable } from "../../../../Misc/observable";
import type { NodeMaterial } from "../../nodeMaterial";
import { PrecisionDate } from "core/Misc/precisionDate";

const remapAttributeName: { [name: string]: string } = {
position2d: "position",
Expand Down Expand Up @@ -377,6 +378,12 @@ export class InputBlock extends NodeMaterialBlock {
}
break;
}
case AnimatedInputBlockTypes.RealTime: {
if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {
this.value = (PrecisionDate.Now - scene.getEngine().startTime) / 1000;
}
break;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/tools/nodeEditor/src/blockTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ export class BlockTools {
timeBlock.animationType = AnimatedInputBlockTypes.Time;
return timeBlock;
}
case "RealTimeBlock": {
const realTimeBlock = new InputBlock("RealTime", undefined, NodeMaterialBlockConnectionPointTypes.Float);
realTimeBlock.animationType = AnimatedInputBlockTypes.RealTime;
return realTimeBlock;
}
case "DeltaTimeBlock": {
const deltaTimeBlock = new InputBlock("Delta time");
deltaTimeBlock.setAsSystemValue(NodeMaterialSystemValues.DeltaTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export class NodeListComponent extends React.Component<INodeListComponentProps,
DeltaTimeBlock: "A float representing the time that has passed since the last frame was rendered",
Float: "A floating point number representing a value with a fractional component",
TextureBlock: "A node for reading a linked or embedded texture file",
TimeBlock: "A float value that represents the time that has passed since the scene was loaded",
TimeBlock: "A float value that represents the time that has passed since the scene was loaded (it is incremented by 0.6 each second)",
RealTimeBlock: "A float value that represents the number of seconds that have elapsed since the engine was initialized",
Vector2: "a vector composed of X and Y channels",
Vector3: "a vector composed of X, Y, and Z channels",
Vector4: "a vector composed of X, Y, Z, and W channels",
Expand Down Expand Up @@ -323,6 +324,7 @@ export class NodeListComponent extends React.Component<INodeListComponentProps,
"TextureBlock",
"ReflectionTextureBlock",
"TimeBlock",
"RealTimeBlock",
"DeltaTimeBlock",
"MaterialAlphaBlock",
"FragCoordBlock",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export class InputPropertyTabComponent extends React.Component<IPropertyComponen
animationOptions = [
{ label: "None", value: AnimatedInputBlockTypes.None },
{ label: "Time", value: AnimatedInputBlockTypes.Time },
{ label: "RealTime", value: AnimatedInputBlockTypes.RealTime },
];
systemValuesOptions = [
{ label: "Delta time", value: NodeMaterialSystemValues.DeltaTime },
Expand Down