[Closed] CgTalk Maxscript Challenge 013: "BACK TO BASICS: Scene graph"
CgTalk Maxscript Challenge 013: “BACK TO BASICS: Scene graph”
DESCRIPTION: Create a tool that builds a 3d graph of information about the scene. This can be polycount per object, material sizes, rendertime per light setting, whatever you like. Try to come up with graphs and information that would be considered useful.
(Thanks for the suggestion Xlars)
DEADLINE: 23/11/2006
RULES:
[ul]
[li]NEW RULE: Do NOT post your code until the deadline![/li][li]Code from scratch. Try not to use pre-exisitng functions or plugins.[/li][li]Show your script references, if any (eg. Looking at another script to assist you).[/li][li]You are encouraged to ask for help where needed, but try to do it on your own. The maxscript reference is an invaluable resource.[/li][li]Post your final script inside [/li]“`
tags (located on your posting toolbar).
[li]Post all code into THIS thread.[/li][li]Post the max version you coded in, plus any maxscript extensions you used. (Thanks galagast!)[/li][li]Try to finish the challenge in a week. There is no definite time limit.[/li][/ul]NOTES: After some feedback, i’ve added a new rule of no code posting until the deadline. This way people will be more motivated to work on their solutions. This one is very simple, but can be made far more interesting to code with a little thinking.
could be interesting. i just need to find spare time now
oh! and and i need to take a look to the schematic editor with active x thing in the reference. it might help
Soo much to learn and so little time
I am not sure I understand what to do. Do you mean for instance have a 3d object (like a pie chart)represent scene data ?
Precisely! Or a bar graph, radar, histogram, bell curve… any way to visually represent data in the scene.
Just a reminder there are only a couple of days left before you can start posting!
bah I know this is supposed to be simple but i have only been at this for a short while so dunno if i am gonna have it done although I will probably post somthing I think these challenges are great for learning.
–Baker
Anything and everything is good BakerCo! The whole point of the challenges is to learn by doing and discuss the results. We usually all have a different way of tackling things.
I hope you don’t mind I thought I should post it today as I might not be around a computer tomorrow.
Tested in max7
this is what the result looks like
[img] http://img146.imageshack.us/img146/5338/pielygonwm7.jpg [/img]
all suggestions and crits of course are welcome
Finally i have mine! woo first challenge
since its the 23 here ill post my code before going to sleep
Very basic and not idiot proof ;D hey i just pass 2 night on it (around 5 hour) and i think it my first “complete” script all from scrathc
Reference : max script reference and my 3ds max 8 maxscript essential book
[b]What it does: [/b]you select the category (light/mesh/camera/shape) and it show how many of this object class are in the scene. You have to hit the Button Refresh first and check-uncheck the update button . Cumbersome i know. lemme time to learn :D
. I didnt pushit enough the way i want ,mainly because the deadline. i start working on it yesterday night
[b]What i wanted: [/b]Maybe somthing in viewport. a bit like polycounter. or a utility with only a list that update automatically or manually
anyways that was a fun challenge. i liked the experience . there good chance ièll be in for the next one.
So here the meat
-- SceneInfo.ms
-- Version: 0.01
-- Created On:21 nov 2006
-- Created By: David "Daedalus" Bordeleau
-- Tested using Max 8 sp3
--BUG: Light info dont see Mental Ray Light
-- mesh Doesnt see Extended mesh
if ((SceneInfo != undefined ) and (SceneInfo.isdisplayed)) do
(destroydialog SceneInfo )
rollout SceneInfo "Scene Info "
(
label sceneInfotext "Scene Info Script"
label sceneinfotext2 "by David Bordeleau"
-----------------------------------------------light count section
group "Light Info"
(
button selectlight "Refresh"
checkbutton LightOBjCount " Light"
)
on SelectLight pressed do
(
max select all
coll = (for i in $ where hasproperty i "multiplier" collect i)
max select none
)
on LightOBjCount changed state do
(
if state == on
then LightOBjCount.text = (coll.count as string)
else LightOBjCount.text = "Update Light"
)
----------------------------------------------mesh Count section
group "mesh Info"
(
button Selectmesh "Refresh"
checkbutton meshOBjCount "Mesh"
)
on Selectmesh pressed do
(
max select all
meshColl = (for i in $ where hasproperty i "realWorldMapSize" collect i)
max select none
)
on meshOBjCount changed state do
(
if state == on
then meshOBjCount.text = (meshcoll.count as string)
else meshOBjCount.text = "Update Mesh"
)
-----------------------------------------------Shape Count section
group "Shape Info"
(
button Selectshape "Refresh"
checkbutton ShapeOBjCount "Shape"
)
on Selectshape pressed do
(
max select all
ShapeColl = (for i in $ where hasproperty i "render_thickness" collect i)
max select none
)
on ShapeOBjCount changed state do
(
if state == on
then ShapeOBjCount.text = (ShapeColl.count as string )
else ShapeOBjCount.text = "Update Shape"
)
-----------------------------------------------CAmera Count section
group "Camera Info"
(
button SelectCam "Refresh"
checkbutton CamOBjCount "Camera"
)
on SelectCam pressed do
(
max select all
CamColl = (for i in $ where hasproperty i "mpassEnabled" collect i)
max select none
)
on CamOBjCount changed state do
(
if state == on
then CamOBjCount.text = (CamColl.count as string )
else CamOBjCount.text = "Update Camera"
)
)
createdialog SceneInfo 100 400
Like always if you have suggestion or crit go ahead. i just want to be better.
just be prepare. i'm sure there a LOT of thing that could be done better :D
here what it suppose to look like ( below)
Hello:
My entry displays a bar chart.
[ul]
[li]The percentage of red, green, blue and gray objects are show in percentage.[/li][li]The script creates a material with the wirecolor of the object if no material is assigned. this is totaly useless as I could take the color form .wirecolor :)[/li][li]The script renders a 64×64 image of diffusemaps to get the average color.[/li][/ul]References:
[ul]
[li]Maxscript Help[/li][li]Cgtalk Maxscript forum[/li][/ul]Problems discovered:
1: I still dont know how to get if…then…elseif conditions. I tried the case statement to but it didn’t work … As the script cant react on colors like (255, 255, 0) and says it is red,
I tried some thing like this:
case theColor of (
(theColor[1] == theColor[2]: ...
(theColor[2] == theColor[3]: ....
....
default: ...
)
but it always returned default …
2: I dont know how to use LayerManager.nodes to get all Nodes in a Layer …
I first tried to create a new Layer for my statistic representation and render an image of this layer, but as I did not know how to get all nodes on my layer I skipped it …
Stuff learned:
1: It is very important to organise your code – even for ‘small’ projects like this.
Usually I organise my scripts in structs, but I thought this to be a quick’n’dirty hack … but it took longer as expected. If I had used my working struct-frame work some problems could habe been avoided.
2: It is very important to make a scribbele of your project and do something like a feature freeze before starting to code. That way you can concentrate on your goal and won’t be distracted by cool features poping up on the way …
here is the code:
macroScript rdgSceneStatsColor
category:"rdg::preset"
toolTip:"displays statistics about the dispersion of color among objects"
buttonText:"rdgStatistics"
(
global rdgSceneStats
try(destroyDialog rdgSceneStats)catch()
fn checkRenderer = (
if classof renderers.current == "Default_Scanline_Renderer" then (
return false
)else(
return true
)
)
fn createMaterial theObj = (
tempMat = standard()
tempMat.name = theObj.name
tempMat.diffuse = theObj.wirecolor
theObj.material = tempMat
)
theObjects = geometry as array
if checkRenderer() == true and theObjects.count > 0 then (
-- array to store count of objects per color
theColors = #(0,0,0,0)
for i = 1 to theObjects.count do (
-- temp bitmap for textureMaps
tempMap = undefined
-- temp color as array
theColor = #(0,0,0)
-- check for materials
if theObjects[i].material == undefined then (
createMaterial theObjects[i]
)
-- check for bitmap/texturemaps in diffuse
if theObjects[i].material.diffuseMap != undefined then (
tempMap = bitmap 64 64
renderMap theObjects[i].material.diffuseMap into:tempMap filter:on
)
case (classof tempMap) of (
BitMap: (
for y = 0 to tempMap.height - 1 do (
theRow = getPixels tempMap [0, y] tempMap.width
for x = 1 to theRow.count do (
theColor[1] = theColor[1] + theRow[x].r
theColor[2] = theColor[2] + theRow[x].g
theColor[3] = theColor[3] + theRow[x].b
)
)
for i = 1 to theColor.count do (
theColor[i] = (theColor[i] / (tempMap.width * tempMap.height)) as integer
)
)
UndefinedClass:(
tempColor = theObjects[i].material.diffuse
theColor[1] = tempColor.r as integer
theColor[2] = tempColor.g as integer
theColor[3] = tempColor.b as integer
)
)
-- print (theColors as string)
if theColor[1] == theColor[2] and theColor[1] == theColor[3] and theColor[2] == theColor[3]then (
theColors[4] = theColors[4] + 1
)else(
theMainPart = (findItem theColor (amax theColor))
theColors[theMainPart] = theColors[theMainPart] + 1
)
)
theBitmap = bitmap (4 * 64) 100 color:white
theDisplayColors = #(color 255 0 0, color 0 255 0, color 0 0 255, color 128 128 128)
for i = 1 to theColors.count do (
-- calc percentage
thePerc = (100 / theObjects.count) * theColors[i]
theRow = #()
for j = 1 to 64 do (
append theRow theDisplayColors[i]
)
if thePerc != 0 then (
for y = (100 - thePerc) to 100 do (
setPixels theBitmap [(i-1) * 64, y] theRow
)
)
-- some orientation
theRow = #()
for j = 1 to (4 * 64) do (
append theRow (color 153 153 153)
)
for y = 25 to 100 by 25 do (
setPixels theBitmap [0, y] theRow
)
)
rci = rolloutCreator "rdgSceneStats" "rdgSceneStat::color"
rci.begin()
rci.addControl #bitmap "theBitmap_bmp" "bla" paramStr:"width:(4*64) height:100"
acrosStr = " across:4"
for i = 1 to 4 do (
val = theColors[i]
rci.addControl #edittext ("descr_" + i as string) "" paramStr:("width:64 pos:["+ (64 * (i - 1) + 3) as string +", 110] readOnly:true text:\"" + (val as string) + "\"" + acrosStr)
acrosStr = ""
)
theRollout = rci.end()
createDialog rdgSceneStats width:((4 * 64)+10) height:140
rdgSceneStats.theBitmap_bmp.bitmap = theBitmap
)else(
messagebox "Unsupported Renderer or no objects in scene ..."
)
)
Georg