Skip to main content

Material

TypeNameInterface Description
VariablesmainPass: Pass

The first Pass.

Example

const mainPass = material.mainPass;

Use Case

@customNode()
export class Use Case_Material_mainPass extends BasicScriptNode{

@input()
sceneObject: APJS.SceneObject;

@output()
info: string;

execute() {

const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
const mainPass = material.mainPass
this.info = `
depthTest: ${mainPass.depthTest}
depthWrite: ${mainPass.depthWrite}
depthFunction: ${mainPass.depthFunction}
colorMask: ${mainPass.colorMask}
cullMode: ${mainPass.cullMode}
stencilState.enable: ${mainPass.stencilState.enable}
stencilStat.failOperation: ${mainPass.stencilState.failOperation}
stencilStat.passOperation: ${mainPass.stencilState.passOperation}
stencilStat.compareFunction: ${mainPass.stencilState.compareFunction}
stencilStat.readMask: 0x${mainPass.stencilState.readMask.toString(16).toUpperCase()}
stencilStat.writeMask: 0x${mainPass.stencilState.writeMask.toString(16).toUpperCase()}
stencilStat.referenceValue: 0x${mainPass.stencilState.referenceValue.toString(16).toUpperCase()}
`
}
}
TypeNameInterface Description
Variablespasses: Pass[]

Pass List

Example

const passes = material.passes;
const pass0 = passes[0];

Use Case

@customNode()
export class Use Case_Material_passes extends BasicScriptNode{

@input()
sceneObject: APJS.SceneObject;

@output()
info: string;

execute() {

const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
const passes = material.passes
const pass0 = passes[0]
this.info = `
passes.length: ${passes.length}
depthTest: ${pass0.depthTest}
depthWrite: ${pass0.depthWrite}
depthFunction: ${pass0.depthFunction}
colorMask: ${pass0.colorMask}
cullMode: ${pass0.cullMode}
stencilState.enable: ${pass0.stencilState.enable}
stencilStat.failOperation: ${pass0.stencilState.failOperation}
stencilStat.passOperation: ${pass0.stencilState.passOperation}
stencilStat.compareFunction: ${pass0.stencilState.compareFunction}
stencilStat.readMask: 0x${pass0.stencilState.readMask.toString(16).toUpperCase()}
stencilStat.writeMask: 0x${pass0.stencilState.writeMask.toString(16).toUpperCase()}
stencilStat.referenceValue: 0x${pass0.stencilState.referenceValue.toString(16).toUpperCase()}
`
}
}
TypeNameInterface Description
VariablesrenderQueue: number

Rendering order value. The smaller the value, the earlier the rendering; conversely, the larger the value, the later the drawing.

Example

material.renderQueue = 2;

Use Case

@customNode()
export class Use Case_Material_getTexture extends BasicScriptNode{

@input()
sceneObject: APJS.SceneObject;

@input('int')
renderQueue: number = -1;

@output()
output: string;

execute() {
const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
if (this.renderQueue >= 0)
material.renderQueue = this.renderQueue;
this.output = `renderQueue: ${material.renderQueue}`;
}
}
TypeNameInterface Description
Functionsclone(): Material

Material Clone

Example

const newMaterial = srcMaterial.clone();

Use Case

@customNode()
export class Use Case_Material_clone extends BasicScriptNode{

@input()
source: APJS.SceneObject;

@input()
target: APJS.SceneObject;

execute() {
const srcRenderer = this.source.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!srcRenderer)
return;
const srcMaterial = srcRenderer.mainMaterial;
if (!srcMaterial)
return;

const tarRenderer = this.target.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!tarRenderer)
return;

tarRenderer.mainMaterial = srcMaterial.clone();
}
}
TypeNameInterface Description
FunctionssetFloat(name: string, value: number): void

Set the Float property of the material.

Currently, the name of uniform can only be obtained through third-party software such as BlenderLender.

setfloat example

Example

material.setFloat('_Custom_Float', 0.1);

Use Case

@customNode()
export class Use Case_Material_setFloat extends BasicScriptNode{

@input()
sceneObject: APJS.SceneObject;

@input()
propertyFloatValue: number;

execute() {
const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
material.setFloat('_Custom_Float', this.propertyFloatValue);
}
}
TypeNameInterface Description
FunctionssetVector(name:string, value: Vector2|Vector3|Vector4): void

Set the Vector property of the material

Example

material.setVector('_Custom_Vec2', new APJS.Vector2f(1.0, 1.0));

Use Case

@customNode()
export class Use Case_Material_setVector extends BasicScriptNode{

@input()
sceneObject: APJS.SceneObject;

@input()
propertyVector2f: APJS.Vector2f;

execute() {
const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
material.setVector('_Custom_Vec2', this.propertyVector2f);
}
}
TypeNameInterface Description
FunctionssetColor(name:string, value: Color): void

Set the Color property of the material

Example

material.setColor('_Custom_Color', new APJS.Color(1.0, 0.0, 0.0, 1.0));

Use Case

@customNode()
export class Use Case_Material_setColor extends BasicScriptNode{

@input()
sceneObject: APJS.SceneObject;

@input()
propertyColor: APJS.Color;

execute() {
const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
material.setColor('_Custom_Color', this.propertyColor);
}
}
TypeNameInterface Description
FunctionssetMatrix(name:string, value:Matrix4x4): void

Set the Color property of the material

Example

const mat = new APJS.Matrix4x4f();
material.setMatrix('_Custom_Mat4', mat);

Use Case

@customNode()
export class Use Case_Material_setMatrix extends BasicScriptNode{

readonly Deg2Rad:number = Math.PI / 180.0;

@input()
sceneObject: APJS.SceneObject;

@input()
position: APJS.Vector3f;
@input()
eulerAngles: APJS.Vector3f;
@input()
scale: APJS.Vector3f;

execute() {
const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
const mat = new APJS.Matrix4x4f();
const radEulerAngles = this.eulerAngles.clone().multiplyScalar(Math.PI / 180.0);
mat.compose(
this.position,
APJS.Quaternionf.makeFromEulerAngles(radEulerAngles),
this.scale);
material.setMatrix('_Custom_Mat4', mat);
}
}
TypeNameInterface Description
FunctionssetTexture(name:string, texture:Texture):void

Set the Texture property of the material

Example

material.setTexture('_Custom_Sampler2D', tex);

Use Case

@customNode()
export class Use Case_Material_setTexture extends BasicScriptNode{

@input()
sceneObject: APJS.SceneObject;

@input()
propertyTextures: APJS.Texture[];

@input('int')
index: number;

execute() {
const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
material.setTexture('_Custom_Sampler2D', this.propertyTextures[
Math.abs(Math.floor(this.index)) % this.propertyTextures.length]);
}
}
TypeNameInterface Description
FunctionsgetFloat(name:string):number | undefined

Get the Float property of the material

Example

const value = material.getFloat('_Custom_Float');

Use Case

@customNode()
export class Use Case_Material_getFloat extends BasicScriptNode{

@input()
sceneObject: APJS.SceneObject;

@output()
result: string;

execute() {
const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
const value = material.getFloat('_Custom_Float');
this.result = `Float: ${value}`;
}
}
TypeNameInterface Description
FunctionsgetVector(name:string):Vector2|Vector3|Vector4|undefined

Get the Vector property of the material

Example

const value = material.getVector('_Custom_Vec2');

Use Case

@customNode()
export class Use Case_Material_getVector extends BasicScriptNode{

@input()
sceneObject: APJS.SceneObject;

@output()
result: string;

execute() {
const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
const value = material.getVector('_Custom_Vec2');
this.result = `${value}`;
}
}
TypeNameInterface Description
FunctionsgetMatrix(name:string):Matrix4x4 | undefined

Get the Matrix property of the material

Example

const eulerAngles = rotation.toEulerAngles();

Use Case

@customNode()
export class Use Case_Material_getMatrix extends BasicScriptNode{

readonly Rad2Deg:number = 180.0 / Math.PI;

@input()
sceneObject: APJS.SceneObject;

@output()
result: string;

execute() {
const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
const value = material.getMatrix('_Custom_Mat4');

const position = new APJS.Vector3f();
const rotation = new APJS.Quaternionf();
const scale = new APJS.Vector3f();
value?.getDecompose(position, rotation, scale);

const eulerAngles = rotation.toEulerAngles();
this.result = `Position: ${position}
Euler: ${eulerAngles.multiplyScalar(this.Rad2Deg)}
Scale: ${scale}`;
}
}
TypeNameInterface Description
FunctionsgetColor(name: string): Color | undefined

Get the Color property of the material

Example

const value = material.getColor('_Custom_Color');

Use Case

@customNode()
export class Use Case_Material_getColor extends BasicScriptNode{

@input()
sceneObject: APJS.SceneObject;

@output()
result: string;

execute() {
const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
const value = material.getColor('_Custom_Color');
this.result = `${value}`;
}
}
TypeNameInterface Description
FunctionsgetTexture(name:string):Texture | undefined

Get the Texture property of the material

Example

const tex = material.getTexture('_Custom_Sampler2D') as APJS.Texture;

Use Case

@customNode()
export class Use Case_Material_getTexture extends BasicScriptNode{

@input()
sceneObject: APJS.SceneObject;

@output()
output: APJS.Texture;

execute() {
const renderer = this.sceneObject.getComponent('MeshRenderer') as APJS.MeshRenderer;
if (!renderer)
return;
const material = renderer.mainMaterial;
if (!material)
return;
const tex = material.getTexture('_Custom_Sampler2D') as APJS.Texture;
console.log(`Tex: ${tex.getWidth()}`);
this.output = tex;
}
}
Copyright © 2025 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalCookies