Notifications
Clear all

[Closed] Passing old Material values to new Material

Hey guys. I was researching on how to pass user set tiling values set in a Checker material. Basically I am writing a script for a specific render pass, however it requires materials to be turning into a Shellac, however in testing we need some of the ‘old’ Material vaules passed on to the new Material, this is what I came up with…


if (classof meditMaterials[i]) == Standardmaterial then
(
  -- Grab a reference to the current material
  local mOld = meditMaterials[i]
  --lets grab diffuse tiling 1st
  local texTilingU = mOld.coords.U_Tiling
  local texTilingV = mOld.coords.V_Tiling
  local sName = mOld.name
  -- Create our new material
  local mNew = (Shellac name:sName)
  local iSufix = (substring sName 6 sName.count) as integer
  if iSufix != undefined and iSufix < 999 then
  (
	 local F = iSufix/1.0 --grabbing suffix for use of color ID
	 IDcolor = (color 0 0 F) --setting color ID
	 mNew.shellacColorBlend = 100
	 mNew.shellacMtl1 = Standardmaterial () --setting up the added layer
	 mNew.shellacMtl2 = Standardmaterial () --setting up the added layer
	 mNew.shellacMtl2.Diffuse = IDcolor
	 mNew.shellacMtl2.ambient = IDcolor
	 mNew.shellacMtl1.coords.U_Tiling = texTilingU
	 mNew.shellacMtl2.coords.V_Tiling = texTilingV
	 replaceInstances mOld mNew
  )
)

However, while this doesn’t work, I already see a problem. I am going through a bunch of materials, how do I store values for each of those and pass them consecutively? I assume I can figure out how to pass vaules for say material[1], but material[i], the entire array of materials. I could place a if query in there, say if tiling is greater than 1 store it, otherwise ignore.

8 Replies

so I decided to see if I could start at a simpler step,


for i = 1 to MeditMaterials.count do
(
	if classof MeditMaterials[1] == (Standard) then
	(
	texTilingU = meditMaterials[1].coords.U_Tiling
		
	print texTilingU
	)

)

I was hoping to at least print the value, but even that I am doing wrong

Ok Bixel I am willing to help you, but you will have to do some stuff if you want my help. This should help you to understand how to use maxscript and get the information you need from the maxscript help.

  1. Answer and Do what I ask you to do, if I feel the response is incomplete or you didn’t do what I asked then I will stop helping you.
  2. No one else gives you the answers to your problems or my questions. You won’t learn anything if someone is giving you the answers.

First Question:
Why is you code in a for loop when you are not calling the variable (in your code i) inside the loop?

Second Question:
Search the Maxscript Help and tell me every page that uses “coords”. Now look at your code. Why is it not working?

-Eric

 JHN

*edit
I see pixelmonkey is on this.

-Johan

pulls up a chair

Looking forward to learning along side you Bixel

OK! Why am I using a for i in such and such? Becuase later I am going to search through all the materials by name (all these scripts I have to do require this -not my idea), search all material properties by type, if certain type grab some of their user settings (ie. coords) store them, and pass it on IF I have to destroy and make a new material. So the i will not be used immediatly but further down the line of code.

However I followed your advice and I have learned some stuff.
this is very helpful >>>> showProperties (Standard())

this line, texTilingU = meditMaterials[1].coords.U_Tiling

needs to be

texTilingU = meditMaterials[1].diffusemap.coords.U_Tiling

so now that the above was printing, I tried to take the code the next step forward


texTilingU = meditMaterials[1].diffusemap.coords.U_Tiling
texTilingV = meditMaterials[1].diffusemap.coords.V_Tiling
mOld = meditMaterials[1]
mNew = (Shellac())
setup = 0
if setup == 0 then
(
mNew.shellacMtl1 = Standardmaterial () --setting up the added layer
mNew.shellacMtl2 = Standardmaterial () --setting up the added layer
mNew.shellacMtl1.diffusemap.coords.U_Tiling = texTilingU
mNew.shellacMtl1.diffusemap.coords.V_Tiling = texTilingV
replaceInstances mOld mNew
setup = 1
)

however, its finding coords as undefined, but the MacroRecorder sees it

meditMaterials[1].shellacMtl1[#Maps][#Diffuse_Color__Map__2__add0010_png].coords.U_Tiling
when I am manually changing values.
btw why does MacroRecorder show this stuff .shellacMtl1[#Maps][#Diffuse_Colo…]
and not this .shellacMtl1.diffuseMap.coords…?

ok, I figured it out. I had to at least assign it a diffuseMap before altering its properties. This works perfectly.


 texTilingU = meditMaterials[1].diffusemap.coords.U_Tiling
 texTilingV = meditMaterials[1].diffusemap.coords.V_Tiling
 mOld = meditMaterials[1]
 mNew = (Shellac())
 setup = 0
 if setup == 0 then
 (
 mNew.shellacColorBlend = 100
 mNew.shellacMtl1 = Standardmaterial () --setting up the added layer
 mNew.shellacMtl2 = Standardmaterial () --setting up the added layer
 mNew.shellacMtl1.diffuseMap = Bitmaptexture fileName:"E:\3dsmax9\maps\35-DarkWood.jpg"
 mNew.shellacMtl1.diffusemap.coords.U_Tiling = texTilingU
 mNew.shellacMtl1.diffusemap.coords.V_Tiling = texTilingV
 replaceInstances mOld mNew
 setup = 1
 )
 

now I just have to figure out how to pass info along several Materials, not just meditmaterials[1] but meditmaterials[i]

1 Reply
(@pixel_monkey)
Joined: 11 months ago

Posts: 0

Well think about it. If what you are looking for is not there, then how would you be able to get its properties?

-Eric

Check the Maxscript Reference for “StandardMaterial” and look for the .maps property. What you are seeing is the properties as “Name Values”, look for that in the Maxscript reference. That is just another way to access the same information.

-Eric