Notifications
Clear all

[Closed] BIG material convert problem

hi,

I have a very bad problem with a script I’m writing to convert vray materials into standard materials.

the function is

fn convertMaterial mat = ()

and it converts materials like this:


  convMat = Standard name:mat.name showInViewport:true
  convMat.Diffuse = mat.diffuse
  

that’s not the problem. but the problem starts with:

mat = convMat

problem:
the material is created and I can show it in the material editor,
but it is not replaced by the converted material!

do I have to note something special??
THX

11 Replies

I guess you should pass the material to the function by reference. So the function declaration should be:

fn convertMaterial &mat = ( -- convertion code goes here )

and them you call the function:

convertMaterial &mEditMaterials[1]

So the material in the slot #1 should be replaced with the new material.

Greets.

big THX,
never heard of the reference thing before and checked it out… but it didn’t work

perhaps the problem is somewhere else, so I decided to post my code.


convertMaterial &currentMaterial

fn convertMaterial &mat =
(
case classof mat of
	(
		-- check the class of the material
		blend: (convertMaterial &mat.map1; convertMaterial &mat.map2)
		compositematerial: (for thisMat in mat.materiallist where thisMat!=undefined do convertMaterial &thisMat)
		multimaterial: (for thisMat in mat.materiallist where thisMat!=undefined do convertMaterial &thisMat)
		VRayMtl:
		(
			-- convert Vray materials only
			convMat = Standard name:mat.name showInViewport:true
			convMat.Diffuse = mat.diffuse
			-- convert diffuse texture
			if mat.texmap_diffuse != undefined then
			(
			convMat.diffuseMap = mat.texmap_diffuse
			  convMat.diffuseMapAmount = mat.texmap_diffuse_multiplier
			  convMat.diffuseMapEnable = mat.texmap_diffuse_on
			)	  
			-- replace vray material by converted material
			mat = convMat
		)
	)
)

I hope it helps YOU to find MY mistake, a solution for my problem respectively

Ok, I guess currentMaterial is a variable defined by you?.

I’ve done something like this:

currentMaterial = &mEditMaterials[1]

So now currentMaterial is a ValueRef variable, that is, it is a memory address pointing to the material slot #1.

Then I’ve called the conversion function like this:

convertMaterial currentMaterial

The & symbol is not needed anymore because currentMaterial is already a reference.

And it worked right!.

does not work… mhhh… I’m sitting at this script for days now and don’t find answers…
thanks for your help so far, anyway!

– 1 put ur old material to meditmaterial list , i think this will make u see what happened:
– and this material maybe the vray material or others, eg:
meditmaterials[1] = <urobject>.material

– 2 set a standard material at other meditmaterials list : what u like :
– eg:
meditmaterials[2] = standardMaterial ()
meditmaterials[2].diffuse = … – meditmaterials[1].diffuse or other .
meditmaterials[2].opacity = …
meditmaterials[2].xxxx = …

–3 change the material of ur objects or ur varable etc to the meditmaterials[2],
–eg:
<urobject>.material = meditmaterials[2]
myMaterialVariable = meditmaterials[2]


– i think this will make it clear for u .
– a material is something a variables value , "to change the value of the variable" and "to change the objs material value which using the variable ” is not the same thing .

objs material <<< material variable <<<< instance of material class

ok, thanks. I will try it.
If I understand u, it would be great if there was an “xxx as material” syntax…?
would be nice

try

I don’t get it… :shrug:
I can’t do it like u said because of the objects mostly having multimaterials and so it’s not possible to tell the object to take the material.

my (recursive) function loops through the whole material tree (of a blend or multimaterial) and should turn the vray materials into standard materials.
therefore I’m not able to set the newly converted material as the objects material because it is a sub-material.

the wall I’m standing in front is getting bigger and bigger 😮
and I can’t :bounce: over this wall grrrr

Ok, I didn’t test Multimaterials nor Composite materials.

Now should work for all the materials classes. At least it works for me!..

fn vRayMtlToStandard &mat =
(
	case classof mat of
	(
		-- check the class of the material
		blend:
		(
			vRayMtlToStandard &mat.map1
			vRayMtlToStandard &mat.map2
		)
		compositematerial:
		(
			for i = 1 to mat.materialList.count do
				if mat.materialList[i] != undefined do
					vRayMtlToStandard &mat.materialList[i]
		)
		multimaterial:
		(
			for i = 1 to mat.materialList.count do
				if mat.materialList[i] != undefined do
					vRayMtlToStandard &mat.materialList[i]
		)
		VRayMtl:
		(
			-- convert Vray materials only
			convMat = Standard name:mat.name showInViewport:true
			convMat.Diffuse = mat.diffuse
			-- convert diffuse texture
			if mat.texmap_diffuse != undefined then
			(
				convMat.diffuseMap = mat.texmap_diffuse
				convMat.diffuseMapAmount = mat.texmap_diffuse_multiplier
				convMat.diffuseMapEnable = mat.texmap_diffuse_on
			)	  
			-- replace vray material by converted material
			mat = convMat
		)
	)
)

The problem is that you can’t modify the iterator (thisMat in this case) used to traverse an array:

for thisMat in mat.materiallist where thisMat != undefined do
	convertMaterial &thisMat

So the solution is to access to the array with an index:

for i = 1 to mat.materialList.count do
	if mat.materialList[i] != undefined do
		vRayMtlToStandard &mat.materialList[i]

Hope it works now.

oh MAN!!!
THANK YOU!!!

when I started to script this little tool, I could not presage how difficult this is.
it works, great!! :buttrock::applause:

this community rules! above all: YOU
saved my life

Page 1 / 2