Archiv der Kategorie: 3D

Erst mal nur 3Ds Max…

Maxscript: Keyframes mit Versatz verschieben

Wenn man sich wiederholende Objekte animieren möchte, kann es hilfreich sein dass über Script zu lösen.

Szenario: Man möchte Pflastersteine animiert auslegen lassen. Dazu animiert man die Bewegung eines Pflastersteines dupliziert den Stein anschließend mit dem Array Tool und mit einem Script tut man nun die Keyframes einzeln verschieben:

1
2
3
4
5
6
7
8
9
10
11
12
(
num = 0
timeDisplace = 10
fn compObjNames name1 name2 = stricmp name1.name name2.name
selArray = selection as array
qSort selArray compObjNames
        
for i = 1 to selArray.count do (
    if i > 1 do num += timeDisplace
    moveKeys selArray[i].transform.controller num
    )
)

Ergebnis:

Maxscript: Random Transform

Lohnt nicht für github, daher kommt das Script hierher.

Es lassen sich damit eine Anzahl Objekt per Zufall transformieren.

RandomTransform

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
rollout RandomTransform "Random Transform" width:210 height:290 (
    local sel = selection
    
    groupBox grpTrans "Moving" pos:[5,5] width:200 height:80
        spinner spnTransMinX "Min X: " pos:[25,25] width:75 height:16 range:[-1000000.00,1000000.00,0.00] type:#worldunits
        spinner spnTransMinY "Min Y: " pos:[25,45] width:75 height:16 range:[-1000000.00,1000000.00,0.00] type:#worldunits
        spinner spnTransMinZ "Min Z: " pos:[25,65] width:75 height:16 range:[-1000000.00,1000000.00,0.00] type:#worldunits
    
        spinner spnTransMaxX "Max X: " pos:[125,25] width:75 height:16 range:[-1000000.00,1000000.00,0.00] type:#worldunits
        spinner spnTransMaxY "Max Y: " pos:[125,45] width:75 height:16 range:[-1000000.00,1000000.00,0.00] type:#worldunits
        spinner spnTransMaxZ "Max Z: " pos:[125,65] width:75 height:16 range:[-1000000.00,1000000.00,0.00] type:#worldunits
    
    groupBox grpRot "Rotating" pos:[5,90] width:200 height:80
        spinner spnRotMinX "Min X: " pos:[25,110] width:75 height:16 range:[-360.00,360.00,0.00]
        spinner spnRotMinY "Min Y: " pos:[25,130] width:75 height:16 range:[-360.00,360.00,0.00]
        spinner spnRotMinZ "Min Z: " pos:[25,150] width:75 height:16 range:[-360.00,360.00,0.00]
    
        spinner spnRotMaxX "Max X: " pos:[125,110] width:75 height:16 range:[-360.00,360.00,0.00]
        spinner spnRotMaxY "Max Y: " pos:[125,130] width:75 height:16 range:[-360.00,360.00,0.00]
        spinner spnRotMaxZ "Max Z: " pos:[125,150] width:75 height:16 range:[-360.00,360.00,0.00]
        
    groupBox grpScale "Scaling" pos:[5,175] width:200 height:80
        spinner spnScminX "Min X: " pos:[25,195] width:75 height:16 range:[0.00,10000.00,100]
        spinner spnScminY "Min Y: " pos:[25,215] width:75 height:16 range:[0.00,10000.00,100]
        spinner spnScminZ "Min Z: " pos:[25,235] width:75 height:16 range:[0.00,10000.00,100]
        
        spinner spnScmaxX "Max X: " pos:[125,195] width:75 height:16 range:[0.00,10000.00,100]
        spinner spnScmaxY "Max Y: " pos:[125,215] width:75 height:16 range:[0.00,10000.00,100]
        spinner spnScmaxZ "Max Z: " pos:[125,235] width:75 height:16 range:[0.00,10000.00,100]
    
    
    button btnTrans "Random Transform" pos:[5,265] width:200 height:20
 
    on btnTrans pressed do (
        if sel.count == 0 then (
            MessageBox ("Please select Objects first!") title:"Random Transform"
            ) else (
            undo "Random Transform" on (
                for i = 1 to sel.count do (
                    randx = random spnTransMinX.value spnTransMaxX.value
                    randy = random spnTransMinY.value spnTransMaxY.value
                    randz = random spnTransMinZ.value spnTransMaxZ.value
                    sel[i].pos = [randx + sel[i].pos.x, randy + sel[i].pos.y, randz + sel[i].pos.z]
                    randRotx = random spnRotMinX.value spnRotMaxX.value
                    randRoty = random spnRotMinY.value spnRotMaxY.value
                    randRotz = random spnRotMinZ.value spnRotMaxZ.value
                    rotate sel[i] (eulerangles randRotx randRoty randRotz)
                    randScaleX = random (spnScminX.value/100) (spnScmaxX.value/100)
                    randScaleY = random (spnScminY.value/100) (spnScmaxY.value/100)
                    randScaleZ = random (spnScminZ.value/100) (spnScmaxZ.value/100)
                    scale sel[i] [randScaleX, randScaleY, randScaleZ]
                    )
                )
            )
    )
    
)
try ( destroyDialog RandomTransform ) catch ()
 
createDialog RandomTransform style:#(#style_toolwindow, #style_border, #style_sysmenu)

Download: RandomTransform

Maxscript: automatisch Objecte mit Materialien und Texturen erstellen

Ein Beispiel wie man ein Haufen Objekte mit Materialien, Maps und Texturen erstellen lassen kann.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
tex = #(\
"D:\\tmp\\tex_001.jpg", \
"D:\\tmp\\tex_002.jpg", \
"D:\\tmp\\tex_003.jpg", \
"D:\\tmp\\tex_004.jpg", \
"D:\\tmp\\tex_005.jpg", \
"D:\\tmp\\tex_006.jpg", \
"D:\\tmp\\tex_007.jpg", \
"D:\\tmp\\tex_008.jpg", \
"D:\\tmp\\tex_009.jpg", \
"D:\\tmp\\tex_010.jpg", \
"D:\\tmp\\tex_011.jpg", \
"D:\\tmp\\tex_012.jpg", \
"D:\\tmp\\tex_013.jpg", \
"D:\\tmp\\tex_014.jpg", \
"D:\\tmp\\tex_015.jpg", \
"D:\\tmp\\tex_016.jpg", \
"D:\\tmp\\tex_017.jpg", \
"D:\\tmp\\tex_018.jpg", \
"D:\\tmp\\tex_019.jpg", \
"D:\\tmp\\tex_020.jpg", \
"D:\\tmp\\tex_021.jpg", \
"D:\\tmp\\tex_022.jpg", \
"D:\\tmp\\tex_023.jpg", \
"D:\\tmp\\tex_024.jpg", \
"D:\\tmp\\tex_025.jpg", \
"D:\\tmp\\tex_026.jpg", \
"D:\\tmp\\tex_027.jpg", \
"D:\\tmp\\tex_028.jpg", \
"D:\\tmp\\tex_029.jpg", \
"D:\\tmp\\tex_030.jpg" \    
)
 
for i = 1 to 500 do (
Box length:(random 1 50) width:(random 1 50) height:(random 1 50) pos:[(random -500 500),(random -500 500),(random -500 500)] isSelected:on
 
str = "000" + (i as string)
if str.count == 5 then (
    sub= substring str 2 -1
    ) else if str.count == 6 then (
        sub= substring str 3 -1
        ) else if str.count == 7 then (
            sub= substring str 4 -1
            ) else sub = str
            
newmat = Arch___Design__mi()
newmat.name = ("MAT_" + sub)
newmat.diff_color_map = falloff ()
newmat.diff_color_map.name = ("falloff_" + sub)
newmat.diff_color_map.MAP1 = bitmaptexture filename:tex[random 1 30]
 
selection[1].material = newmat
)

Maxscript: Texturename ab bestimmter länge umbenennen und neu verlinken

Hier ein kleiner Code Schnippel. Damit werden die Szene Materialien nach Texturen durchsucht. Sind die Texturnamen länger als 8 Zeichen, werden sie umbenannt in einen neuen Ordner gespeichert und in Max neu verlinkt.

Das Script ist nicht sonderlich ausgefeilt, daher werden nur Materialien ohne Unternamterialien (wie z.B. das Multi Material) unterstützt.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
mapArray = #()
for i = 1 to scenematerials.count do (
    for a = 1 to (getNumSubTexmaps scenematerials[i] ) do (
        if ( ( getSubTexmap scenematerials[i] a ) != undefined ) do (
            mapName = ( getSubTexmap scenematerials[i] a )
            join mapArray #( mapName )
            )
        )
    )
    
    for map in mapArray do (
        mapPath = getFilenamePath map.filename + "shortnames\\"
        mapFile = getFilenameFile map.filename
        mapExt = getFilenameType map.filename
        if mapFile.count > 8 do (
            newName = substring mapFile 3 8
            renameFile map.filename ( mapPath + newName + mapExt )
            map.filename = ( mapPath + newName + mapExt )
            )
        )

Maxscript: Search Material And Maps

Habe ein älteres Script noch mal überarbeitet. Es basiert jetzt zum Teil auf dotnet, wodurch es Farbcodierungen zulässt, auch sind nun einige Befehle über ein rechts-klick-Menü erreichbar. Auch werden jetzt alle Maps aufgelistet, was gerade die Suche nach nicht render- fähigen Shadern vereinfacht, wenn man z.B. die Szene von VRay nach Mental Ray konvertiert hat.

SearchMatsAndMaps

 

Zusätzlich kann man nun das Fenster auch andocken:

SearchMatsAndMapsDock

 

Download: https://github.com/jb-alvarado/SearchMaterialAndMaps

Maxscript: List Scripts In Folder

Hier ein kleines Script mit welchem alle Scripte aus einem bestimmten Ordner aufgelistet werden.

ListScripts

Mit doppelklick lassen sich die Scripte ausführen. Mit Rechtsklick lässt sich auswählen ob man das Script starten möchte, es editieren möchte, ein neues Script anlegen will, die Liste aktualisiert werden soll, oder ob der Ordnerpfad im Explorer geöffnet werden soll.

ListScriptsRightClick

 

Das Script lässt sich auch das die 3Ds Max Oberfläche andocken:

 

ListScriptsDock

Download: https://github.com/jb-alvarado/ListScriptsInFolder

Damit die Scripte gefunden werden, muss der Ordnerpfad angepasst werden. Script im Editor öffnen und Zeile:

global start_dir = "\\\\path\\to\\scripts\\"

anpassen.