PDA

View Full Version : How to get preview of a slot in material editor in my interface ?


BebeteLANUITE
02-13-2006, 04:15 PM
Hello guys. ;)

I make an interface about material searching. I want to have a preview of the selected material (like in material editor) in my own interface.

Somebody have an idea to do it ? :)

Thanks a lot for your help guys ;)

MrSparkle
02-13-2006, 06:42 PM
Hi,

Bobo's TreeMatoGraph can render some previews of the materials. You can find the script here: http://www.highend3d.com/3dsmax/downloads/scripts/texturing/2326.html

Maybe you find out, how it's been done... ;)

Chris

pindercarl
02-13-2006, 07:27 PM
My recollection of that script is that a sphere is created in the scene, rendered, and then deleted. It's certainly the easiest way to acheive the effect.

Bobo
02-13-2006, 08:32 PM
My recollection of that script is that a sphere is created in the scene, rendered, and then deleted. It's certainly the easiest way to acheive the effect.

You are correct. Of course, TMG supported box, cylinder and teapot as alterantive geometry.
All other visible scene geometry is enumerated and hidden, then the sample object, a camera and one or two lights are created. Once the rendering is done, the object, camera and lights are deleted and the previously visible objects are unhidden. This does not require a redraw of the viewports, so hiding/unhiding is relatively fast.

For maps, I used renderMap(), of course.

BebeteLANUITE
02-13-2006, 10:33 PM
Thanks a lot for your lights.

But how you can get a small scene with only a sphere to render it in "slot" of my interface ?
I understand the principle but i don't know how to do it. :(

Could you help me?

Bobo
02-14-2006, 03:47 AM
Thanks a lot for your lights.

But how you can get a small scene with only a sphere to render it in "slot" of my interface ?
I understand the principle but i don't know how to do it. :(

Could you help me?


Here is an example partially based on the TMG code.
It creates a UI containing 6 sample slots and a button.
Press the button to update the samples with the first 6 slots (both materials or maps) from the Material Editor.



(
global TestMapSamples
try(destroyDialog TestMapSamples )catch()
local lights_state = #()
local lights_array = #()

fn collectLightsState =
(
lights_state = #()
lights_array = for l in Lights where classof l != TargetObject collect l
for l in lights_array do
(
try
(
append lights_state l.on
l.on = false
)
catch(append lights_state false)
)
)

fn restoreLightsState =
(
for l = 1 to lights_array.count do
try(lights_array[l].on = lights_state[l])catch()
)

fn renderMaterial mat size_x size_y=
(
if superclassof mat == Material then
(
disablesceneredraw()
with undo off
(
local old_selection = selection as array
local visibleObjects = for o in objects where not o.isHidden collect o
hide objects
collectLightsState()
om1 = omniLight pos:[99900.0,99900.0,100300.0] multiplier:1.5
om2 = omniLight pos:[100100.0,100000.0,99900.0] multiplier:2.0
s = sphere pos:[100000.0,100000.0,100000.0] mapcoords:true segs:24
uvw_mod = uvwmap Channel:1
uvw_mod.mapType=2
addmodifier s uvw_mod
s.material = mat
t_o = targetObject pos:[100000.0,100000.0,100000.0]
c = TargetCamera target:t_o
c.pos = [100000.0,100000.0-65,100030.0]
map_sample = render camera:c outputsize:[size_x,size_y] vfb:false
delete #(c,s,om1,om2)
unhide visibleObjects
select old_selection
restoreLightsState()
)
enablesceneredraw()
)
else
map_sample = renderMap mat size:[size_x,size_y] scale:200
map_sample
)

rollout TestMapSamples "Test Map Samples"
(
bitmap bmp_slot1 width:64 height:64 across:6
bitmap bmp_slot2 width:64 height:64
bitmap bmp_slot3 width:64 height:64
bitmap bmp_slot4 width:64 height:64
bitmap bmp_slot5 width:64 height:64
bitmap bmp_slot6 width:64 height:64

button btn_updateSlots "Update Slots"
on btn_updateSlots pressed do
(
suspendEditing()
bmp_slot1.bitmap = renderMaterial meditMaterials[1] 64 64
bmp_slot2.bitmap = renderMaterial meditMaterials[2] 64 64
bmp_slot3.bitmap = renderMaterial meditMaterials[3] 64 64
bmp_slot4.bitmap = renderMaterial meditMaterials[4] 64 64
bmp_slot5.bitmap = renderMaterial meditMaterials[5] 64 64
bmp_slot6.bitmap = renderMaterial meditMaterials[6] 64 64
resumeEditing()
)
)--end rollout
createDialog TestMapSamples 420 100
)

BebeteLANUITE
02-14-2006, 09:23 AM
Thank you for your help bobo :thumbsup:.
I understand more what you want to say.

great piece of code. ;)

I have an other question.

In fact. I work on a tool to find material by bitmap files they use.
This tool is useful when you have a missing map file and you want to launch a network render. This tool list all bitmap files in the scene in a combobox.
And if you click on a bitmap filename all material use this bitmap appears in a listbox.
And if you select one of the material you can see his preview, and you can bring it to material editor for modifying.

This my interface.

rollout RollA "About"
(
group ""
(
label cop01 "Copyright In-Visible, 2006"
label cop02 "All rights reserved"
--label cop03 "www.in-visible.lu"
hyperlink invi "www.invisible.lu" address:"http://www.in-visible.lu" align:#center color:blue hovercolor:white visited:black
label espcop " " height:2
)--end group
)--end Rollout

Rollout Prog "By Map Name"
(
button Allmap "Find maps" width:230
progressbar GatherBar color:blue
combobox maplist "Finding Bitmaps:" height:15
edittext pathdisp ""
listbox matlist "Corresponding Materials:" width:140
bitmap matprev "preview:" color:[0,0,0] height:60 width:60 pos:[165,322]
dropdownlist slotnum "Slot:" height:25 width:50 pos:[170,390] items:(for i in 1 to 24 collect i as string)
button sendslot "Send" width:60 pos:[165,438]
button selobjects "Display Objects" width:140 pos:[13,465]


on Allmap pressed do
(

fn addmap mapfile =
(
local mapfileN = mapfile as name
local index = finditem mapfiles mapfileN
if index == 0 do append mapfiles mapfileN
)--end fn

global mapfiles = #()
global SceneMapAdr = enumeratefiles addmap
global SceneMaps = for mapfile in mapfiles collect filenamefrompath (mapfile as string) --print (mapfile as string)
Sort SceneMaps
maplist.items = SceneMaps
)--end on Allmap

on maplist selected item do
(
for mappath in SceneMapAdr where maplist.selected = filenamefrompath (mappath as string) do
(
pathdisp.text = mappath as string --don't work
)--end for mappath

--materiallist = for

)--end on maplist

on slotnum selected slot do
(
mateditor.open()
medit.SetActiveMtlSlot slot true
)--end on slotnum


)--end Rollout
Newf = newrolloutfloater "Find Material" 250 550
addrollout prog newf
addrollout RollA Newf rolledup:true


I find a line to get the filename of a texture, in the diffuse, used by an object in the scene: filenamefrompath ($.material.diffusemap.filename).

I don't know if i must scan all maps in the scene each time i click on a filename in the combobox to find the path and the material use it, or i can store all path, filename and material in variables an call them when i need.

Do you have and idea for this problem ?

Thank you again :bowdown: :)

CGTalk Moderation
02-14-2006, 09:23 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.