I'm using setvalue function to change material matrix3 parameter components, because they won't change in usual way.
Here's the code that explains why I've tried to use referencing:
plugin Material TestMtl ClassID:#(1954676047, 1613573786) (
parameters Params (
Data type:#matrix3 Default:(Matrix3 [0, 0, 0] [0, 0, 0] [0, 0, 0] [0, 0, 0])
on Data set NewVal do
Format "<Material event> Data set %\n" NewVal
)
rollout ui "ui" (
)
)
fn CreateMaterial = (
Format "Create new material\n"
Mtl = (TestMtl())
)
fn CheckData Mtl =(
Format "Data check: %\n\n"(
if Mtl.Data[1][1] == 666 then
"Success!"
else
"FAIL!"
)
)
(
ClearListener()
local Mtl
Mtl = (CreateMaterial())
Format "Trying to set directly\n"
Mtl.Data[1][1] = 666
CheckData Mtl
Mtl = (CreateMaterial())
Format "Trying to update 1st matrix row\n"
Mtl.Data[1] = [666, Mtl.Data[1].y, Mtl.Data[1].z]
CheckData Mtl
Mtl = (CreateMaterial())
Format "Trying to set Mtl.Data using new Matrix3\n"
Mtl.Data = (Matrix3 [666, Mtl.Data[1].y, Mtl.Data[1].z] Mtl.Data[2] Mtl.Data[3] Mtl.Data[4]) --works, but loks like sh*t and very hard t write and read
CheckData Mtl
OK
)
In fact, I've already rewritten my code...I can't use smth like (&Mtl.BlaBlaData) because parameter names can vary in SomeDataChanger function:
plugin Material TestMtl ClassID:#(1954676047, 1613573786) (
parameters Params (
Data type:#matrix3 Default:(Matrix3 [0, 0, 0] [0, 0, 0] [0, 0, 0] [0, 0, 0])
)
rollout ui "ui" (
)
)
fn UpdateMatrix Mtx Coords Data = (
local UpdatePointer = (IsKindOf Mtx ValueRef),
UpdateCoord = (IsKindOf Coords Point2),
TargetMtx = (
if UpdatePointer then
(*Mtx)
else
Mtx
),
ElementID = (
if UpdateCoord then
Coords.x
else
Coords
),
Element
if UpdateCoord then (
Element = TargetMtx[ElementID]
Element[Coords.y] = Data
) else
Element = Data
TargetMtx[ElementID] = Element
if UpdatePointer then
*Mtx = TargetMtx
OK
)
fn SomeDataChanger = (
local PropertyName = #Data,
Mtl = (TestMtl())
Print #AfterCreate --test
Print Mtl.Data --test
Print #AfterSet --test
local Mtx = (GetProperty Mtl PropertyName)
UpdateMatrix Mtx [2, 2] 666 --can use (&Mtl) too
SetProperty Mtl PropertyName Mtx
Print Mtl.Data --test
OK
)
ClearListener()
SomeDataChanger()
I'm clearly sure that the line with GetProperty generates new Matrix3 value, consuming extra memory. Am I right?
Just a little test:
fn getref ref = (
Print ref
)
fn checkrefs = (
local Mtl = (standard()),
ShaderType = (&Mtl.ShaderType)
getref (&Mtl.ShaderType)
getref ShaderType
OK
)
ClearListener()
checkrefs()
Listener output:
&(prop shaderType Local:mtl)
(prop shaderType Local:mtl)
Passed ShaderType variable appears to point on the local variable after passing into another function, not the material property...
It all still looks like a workaround, not like a clean code must be.