Notifications
Clear all

[Closed] generate a bitmap and assign it to an object as diffuse

I’m trying to generate a UVW snapshot of a new mesh, save it as a png,
then assign it to that mesh as a diffuse texture.

the problem is I want to avoid overwriting any meditmaterial slots already in use.

fn assignUvwAsDiffuse obj textureFilePath= 
(
	UV_map=Unwrap_UVW()
	addModifier obj UV_map
	UV_map.renderuv_width = 256
	UV_map.renderuv_height = 256
	UV_map.unwrap5.renderUV filePath
	format "	created: %" textureFilePath

	--create a bitmap texure to hold it
	uvwBitmap = bitmaptexture filename:envObjects.shadowTextureFilePath
	meditMaterials[24].diffuseMap=uvwBitmap
	obj.material=meditMaterials[24]
)



I chose meditMaterials[24] arbitrarily, so as not to mess up any pre-existing scene materials.
But there’s no guarantee that meditMaterials[24] is free for this operation. How can I avoid overwriting meditMaterials that alreayd exist in scene?

7 Replies

[color=Silver]Use this as reference of how to assign a material to an object without affecting the Material Editor

[/color]

selection[1].material = standardMaterial  diffuseMap:(Bitmaptexture fileName:usersimage) showInViewport:true

thanks.

the code you provided works, but I need the artists will want to access the material in the material editor after this process. So it seems I’m back at square one.

They can access the material in Scene Materials in the Material Editor.

thanks again. I did not see that in the compact material editor…

perhaps you can help with this:

I’d like to store a material (or a reference to a material) as a variable so I can assign it to many objects, but I’m new to this end of MAx script.

myMaterial = standardMaterial  name:myMaterial showInViewport:true

-- Unable to convert: undefined to type: String

Edit: duh, for got to put qoutes around my string

myMaterial = standardMaterial  name: "myMaterial" showInViewport:true
--myMaterial:Standard


Open the Material Editor and press the Get Material button. Then you will find Scene Materials in the new window that will shows up.

local myMaterial = standardMaterial  name: "myMaterial" showInViewport:true
  -- assign the material to selected objects
  for o in selection do o.material = myMaterial 
  -- or to objects in array
  objArr = #($Box01, $Teapot01, $Sphere01)
  for o in objArr do o.material = myMaterial
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

   -- assign the material to selected objects
   selection.material = myMaterial 
   -- or to objects in array
    #($Box01, $Teapot01, $Sphere01).material = myMaterial

thanks again!