update
This commit is contained in:
BIN
material_params/Bundled/tex1.png
Normal file
BIN
material_params/Bundled/tex1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
BIN
material_params/Bundled/tex2.png
Normal file
BIN
material_params/Bundled/tex2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
9
material_params/README.md
Normal file
9
material_params/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
Shows how to control material nodes at run-time.
|
||||
Press 1, 2, 3 to change parameters.
|
||||
|
||||
- Enable `Parameter` property in `Logic Node Editor - Properties - Leenkx Material Node`
|
||||
- RGB, Value and Image Texture nodes are supported
|
||||
- See `MyTrait` script to set material parameters using Haxe
|
||||
- See `NodeTree` to set material parameters using logic nodes
|
||||
|
||||
https://github.com/leenkx3d/leenkx/wiki/materials#material-parameters
|
||||
53
material_params/Sources/lnx/MyTrait.hx
Normal file
53
material_params/Sources/lnx/MyTrait.hx
Normal file
@ -0,0 +1,53 @@
|
||||
package lnx;
|
||||
|
||||
import iron.math.Vec4;
|
||||
import iron.object.Object;
|
||||
import iron.object.Uniforms;
|
||||
import iron.data.Data;
|
||||
import iron.data.MaterialData;
|
||||
import iron.system.Time;
|
||||
|
||||
class MyTrait extends iron.Trait {
|
||||
|
||||
var tex1:kha.Image = null;
|
||||
var tex2:kha.Image = null;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
notifyOnInit(() -> {
|
||||
// Register link callbacks
|
||||
Uniforms.externalVec3Links.push(vec3Link);
|
||||
Uniforms.externalFloatLinks.push(floatLink);
|
||||
Uniforms.externalTextureLinks.push(textureLink);
|
||||
});
|
||||
Data.getImage("tex1.png", img -> tex1 = img );
|
||||
Data.getImage("tex2.png", img -> tex2 = img );
|
||||
}
|
||||
|
||||
function vec3Link(object:Object, mat:MaterialData, link:String):Vec4 {
|
||||
// object - currently bound object
|
||||
// mat - currently bound material
|
||||
// link - material node name
|
||||
if (link == "RGB") {
|
||||
var t = Time.time();
|
||||
return new Vec4(Math.sin(t) * 0.5 + 0.5, Math.cos(t) * 0.5 + 0.5, Math.sin(t + 0.5) * 0.5 + 0.5);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function floatLink(object:Object, mat:MaterialData, link:String):Null<kha.FastFloat> {
|
||||
if (link == "Value") {
|
||||
var t = Time.time();
|
||||
return Math.floor(t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function textureLink(object:Object, mat:MaterialData, link:String):kha.Image {
|
||||
if (link == "Image Texture") {
|
||||
var t = Time.time();
|
||||
return Math.sin(t) > 0 ? tex1 : tex2;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
BIN
material_params/material_params.blend
Normal file
BIN
material_params/material_params.blend
Normal file
Binary file not shown.
Reference in New Issue
Block a user