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

refactor #1243

Merged
merged 1 commit into from
Jan 13, 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
44 changes: 23 additions & 21 deletions src/foundation/materials/core/AbstractShaderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ type ShaderNodeInputConnectionType = {
inputNameOfThis: string;
};

/**
* AbstractShaderNode is a class that represents a shader node.
*/
export abstract class AbstractShaderNode extends RnObject {
static shaderNodes: AbstractShaderNode[] = [];
static _shaderNodes: AbstractShaderNode[] = [];
protected __shaderFunctionName: string;
private __shaderCode?: string;
protected __inputs: ShaderSocket[] = [];
protected __outputs: ShaderSocket[] = [];
protected __inputConnections: ShaderNodeInputConnectionType[] = [];
private static readonly __invalidShaderNodeUid = -1;
private static __invalidShaderNodeCount = -1;
protected __shaderNodeUid: ShaderNodeUID;
protected __shader?: GLSLShader;
Expand All @@ -26,19 +28,31 @@ export abstract class AbstractShaderNode extends RnObject {
this.__shaderFunctionName = shaderNodeName;
this.__shaderCode = shaderCode;
this.__shaderNodeUid = ++AbstractShaderNode.__invalidShaderNodeCount;
AbstractShaderNode.shaderNodes[AbstractShaderNode.__invalidShaderNodeCount] = this;
AbstractShaderNode._shaderNodes[AbstractShaderNode.__invalidShaderNodeCount] = this;
this.__shader = shader;
}

get shaderFunctionName() {
addInputConnection(
inputShaderNode: AbstractShaderNode,
outputNameOfPrev: string,
inputNameOfThis: string
): void {
this.__inputConnections.push({
shaderNodeUid: inputShaderNode.shaderNodeUid,
outputNameOfPrev: outputNameOfPrev,
inputNameOfThis: inputNameOfThis,
});
}

get shaderFunctionName(): string {
return this.__shaderFunctionName;
}

get shaderCode() {
get shaderCode(): string | undefined {
return this.__shaderCode;
}

get shaderNodeUid() {
get shaderNodeUid(): ShaderNodeUID {
return this.__shaderNodeUid;
}

Expand All @@ -51,7 +65,7 @@ export abstract class AbstractShaderNode extends RnObject {
return void 0;
}

getInputs() {
getInputs(): ShaderSocket[] {
return this.__inputs;
}

Expand All @@ -64,27 +78,15 @@ export abstract class AbstractShaderNode extends RnObject {
return void 0;
}

getOutputs() {
getOutputs(): ShaderSocket[] {
return this.__outputs;
}

addInputConnection(
inputShaderNode: AbstractShaderNode,
outputNameOfPrev: string,
inputNameOfThis: string
) {
this.__inputConnections.push({
shaderNodeUid: inputShaderNode.shaderNodeUid,
outputNameOfPrev: outputNameOfPrev,
inputNameOfThis: inputNameOfThis,
});
}

get inputConnections(): ShaderNodeInputConnectionType[] {
return this.__inputConnections;
}

get shader() {
get shader(): GLSLShader | undefined {
return this.__shader;
}
}
4 changes: 2 additions & 2 deletions src/foundation/materials/core/ShaderGraphResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ ${prerequisitesShaderityObject.code}
// Collects ExistingInputs
for (let j = 0; j < inputConnections.length; j++) {
const inputConnection = inputConnections[j];
const inputNode = AbstractShaderNode.shaderNodes[inputConnection.shaderNodeUid];
const inputNode = AbstractShaderNode._shaderNodes[inputConnection.shaderNodeUid];
if (isAnyTypeInput(materialNode.getInputs()[j])) {
continue;
}
Expand Down Expand Up @@ -227,7 +227,7 @@ ${prerequisitesShaderityObject.code}
if (prevMaterialNodeInner?.shaderNodeUid !== inputConnection.shaderNodeUid) {
continue;
}
const inputNode = AbstractShaderNode.shaderNodes[inputConnection.shaderNodeUid];
const inputNode = AbstractShaderNode._shaderNodes[inputConnection.shaderNodeUid];
if (!isAnyTypeInput(targetMaterialNode.getInputs()[k])) {
if (existingOutputs.indexOf(inputNode.shaderNodeUid) === -1) {
const outputSocketOfPrev = inputNode.getOutput(inputConnection.outputNameOfPrev);
Expand Down