Maxscript editor tip/tutorial

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

REPLY TO THREAD
 
Thread Tools Search this Thread Display Modes
Old 01 January 2009   #16
some dotnet one that I often use


 /* .NET */
  
 dcol=(dotnetclass "system.drawing.color").fromargb 0 0 0
 dstr=(dotnetobject "system.string" "")
 darr=(dotnetclass "system.array")
 darrr=(dotnetobject "system.array[]" 1)
 dpt=dotnetobject "system.drawing.point" 0 0
 dsize=dotnetobject "system.drawing.size" 0 0
 dpad=dotnetobject "system.windows.forms.padding" 0 0 0 0
 dpen=(dotnetobject "system.drawing.pen" (dotnetobject "system.drawing.solidbrush"((dotnetclass "system.drawing.color").fromargb 0 0 0)) 1)
 dbrush=(dotnetobject "system.drawing.solidbrush" ((dotnetclass "system.drawing.color").fromargb 0 0 0))
 stcp=(dotnetobject "system.windows.forms.columnstyle" (dotnetclass "system.windows.forms.sizetype").percent 50)
 stca=(dotnetobject "system.windows.forms.columnstyle" (dotnetclass "system.windows.forms.sizetype").absolute 20)
 strp=(dotnetobject "system.windows.forms.rowstyle" (dotnetclass "system.windows.forms.sizetype").percent 50)
 stra=(dotnetobject "system.windows.forms.rowstyle" (dotnetclass "system.windows.forms.sizetype").absolute 20)

 
 
Old 01 January 2009   #17
This thread is so usefull Thx to all involved
Should be stickied !!!
 
Old 01 January 2009   #18
Ha Johan you've really hit upon a common note < :

FWIW I qwish we could open multiple script windows as well but i don't think it is possible.


J.
__________________
www.joshuanewman.net
 
Old 05 May 2009   #19
wooow!this thread very useful for me!thanks a lot!
 
Old 08 August 2009   #20
Thanks for the tip. Indeed they are some interesting features in this editor compared to the old one (especially the multiple undo )

Nevertheless I still prefer using Notepad++, this for 3 reasons:
  • when a word is selected, all the other occurences of it are highlighted. This seems light, but I just become addicted!
  • It is easy to open a document twice, to work at 2 different places at the same time (vertically unfortunately)
  • There is a good and smart compare feature
Beside I developed a small tool to easily manage and launch external files. All in all I am pretty happy with that.
__________________
www.werwackfx.com - Ideas and Tools for Graphic Applications
 
Old 11 November 2009   #21
Custom color scheme

Hi everyone,

Triggered by another post, I decided to make a custom color scheme for mxs editor.
The tools>MXS_Userproperties are there to overwrite the default properties of the scintilla editor. With that in mind you can copy/paste the following in that file.


 #~ Default font settings
 font.base=font:DejaVu Sans Mono,size:10
 font.comment=font:DejaVu Sans Mono,size:10
 colour.code.comment.box=fore:#09C009,italics
 colour.code.comment.line=fore:#09C009,italics
 
 #~ Sets the color used for the caret (cursor).
 caret.fore=#f92672
 caret.line.back=#ff8800
 caret.line.back.alpha=50
 
 # Default
 style.MAXScript.32=$(font.base),fore:#f92672,back:  #272822
 # White space
 style.MAXScript.0=fore:#808080
 # Comment: /* */.
 style.MAXScript.1=$(colour.code.comment.box),$(fon  t.code.comment.box)
 # Line Comment: --.
 style.MAXScript.2=$(colour.code.comment.line),$(fo  nt.code.comment.line),eolfilled
 # Number
 style.MAXScript.3=fore:#ae81ff
 # String
 style.MAXScript.4=fore:#e6db74
 # Verbatim strings
 style.MAXScript.5=fore:#007F00,$(font.monospace),b  ack:#8AFB8A,eolfilled
 # End of line where string is not closed
 style.MAXScript.6=fore:#000000,$(font.monospace),b  ack:#E0C0E0,eolfilled
 # Identifiers
 style.MAXScript.7=fore:#ffffff
 # Operators
 style.MAXScript.8=fore:#f92672,bold
 # Keyword arg name
 style.MAXScript.9=fore:#a6e22e
 # Name value
 style.MAXScript.10=fore:#e6db74
 # Pathname
 style.MAXScript.11=fore:#3F7F3F,$(font.monospace),  back:#E0F0FF
 # Keywords1 - Keywords
 style.MAXScript.12=fore:#f92672,bold
 # Keywords2 - Rollout controls
 style.MAXScript.13=fore:#faaa3c,bold
 # Keywords3 - Functions
 style.MAXScript.14=fore:#0080ff
 # Keywords4 - MXS Classes	--Dotnet controls
 style.MAXScript.15=fore:#ff8800
 # Keywords5 - MAXClasses	-- Node transform monitor
 style.MAXScript.16=fore:#ff00ff
 # Keywords6 - MAXSuperClasses  modifier helper etc
 style.MAXScript.17=fore:#ff0000
 # Keywords7 - Core interfaces
 style.MAXScript.18=fore:#00ff00,italics
 # Keywords8 - Object sets
 style.MAXScript.19=fore:#D0B080,italics
 # Keywords9 - StructDefs
 style.MAXScript.20=fore:#804020,italics
 # Keywords10 - Const reserved globals true false undefined etc
 style.MAXScript.21=fore:#4488ff,italics
 # Keywords11 - Reserved globals
 style.MAXScript.22=fore:#B00040
 # Keywords12 - User defined
 style.MAXScript.23=fore:#FF0000,bold,italics
 


This makes a dark color scheme based on the Monokai theme from notepad++. Which I use for my not mxs related coding.

Hope this helps some people. Oh and as a positive side effect the particle flow editor is much better readable!

Cheers,
-Johan

*some funky linebeaking going on, manually check the lines and discard the extra whitespaces or use the attached clean txt file.
Attached Files
File Type: txt MXS_EditorUser.properties.txt (2.0 KB, 63 views)
__________________
Online: LinkedIn

Last edited by JHN : 11 November 2009 at 01:31 PM.
 
Old 12 December 2009   #22
Thanks for sharing!
 
Old 12 December 2009   #23
Just in case anyone missed this tip from the helpfile.

You can use a vertical line character '|' to position the caret after expanding the abbreviation.

here's a very simple example where I found this quite useful:
tc=try(|)catch()

The caret/cursor will be conveniently placed inside the TRY block.
 
Old 12 December 2009   #24
Originally Posted by galagast:
tc=try(|)catch()

The caret/cursor will be conveniently placed inside the TRY block.


That's a great tip!! Thanks!
-Johan
__________________
Online: LinkedIn
 
Old 06 June 2010   #25
Exclamation

it seems all of u guys know what maxscript is all about!

wish i could be like one of u someday...Amen

iam an undergraduate student and i have my project involving maxscript

i tried fulfilling some tasks in maxscript ,some were made well and many were only to waste my time...my project needs simulation of "people walking in street randomly"

i tried watching some tutorials to handle this simulation using "crowd-bipes"
however..i didnt get many tips besides not finding what i want exactly

i have tried to handle crowd of delegates before, and i thought that "crowd of delegates" script may only need some changes to fit crowd of bipes ,but i couldn't figure out these changes!

i only started learning maxscript since 2 months....so do u think u can help me?

this is the script of "delegates following some leader"..hope u can turn it to "bipes walking randomly".

animationRange = interval animationRange.start 150f
(
local switcher = off
local theRolloutFloater
local Test
local Custom_Leader
local TheFrame
local TheSurface
local Arr_Obstacles
local Arr_Delegates
local TheTarget
local C
local Leader
local Sur
local Distribution_Object
local Del
local Obstacles
local Simulation
local Leader_Proxy
local Environment_Setup
local assin_01
local assin_02
local assin_03
local team_01
----Functions -----
Fn TicksToFrames TheFrame =
(
--This Function Changes Ticks to frames NO matter what Frame rate is Pal , NTSC , Film ....etc
(TheFrame as integer/TicksPerFrame)
)


/*
this function creates the Crowd helper , the behaviors and the teams
*/
Fn MakeTheCrowd Num_Of_Delegates Frames =
(
Try( Delete $Delegate* ; Delete $First_Crowd* ; )Catch()

delegate width:6 depth:9 height:6 xyconstraint:false WireColor:Red
-- Constructing the Crowd Helper !
C = crowd name:"First_Crowd" pos:[320,150,0] IconSize:50 SolveEnd:Frames
C.scatter.positionspace = 3
C.scatter.positionobject = $TheSphere
C.scatter.cloneobject = $delegate01
C.scatter.numclones = Num_Of_Delegates - 1
C.scatter.clonetype=0
crowds.genclones C
crowds.genlocations C
Arr_Delegates = $Delegate* as array
C.deleteKeys = true

--surface follow behavior
TheSurfaceFollow_Behavior = Surface_Follow_Behavior name:"SurfaceFollow"
Append TheSurfaceFollow_Behavior.Surfaces TheSurface
append C.Behaviors TheSurfaceFollow_Behavior
--seek behavior
TheSeekTarget_Behavior = Seek_Behavior name:"Seek_Target"
Append TheSeekTarget_Behavior.targets TheTarget
append C.Behaviors TheSeekTarget_Behavior
--avoid behavior
TheAvoid_Behavior = Avoid_Behavior name:"Avoid_Delegates&Obstacles"
for i in Arr_Delegates do (Append TheAvoid_Behavior.Obstacles i)
if Arr_Obstacles != undefined do for i in Arr_Obstacles do (Append TheAvoid_Behavior.Obstacles i)
TheAvoid_Behavior.HardRadius = 0.4
TheAvoid_Behavior.LookAhead = 40
append C.behaviors TheAvoid_Behavior

team_01 =CrowdTeam()
team_01.name = "All_Delegate"
team_01.members = Arr_Delegates
append C.teams team_01

assin_01 = crowdassignment team:team_01 behavior:TheSeekTarget_Behavior active:true
append C.assignments assin_01
assin_02 = crowdassignment team:team_01 behavior:TheSurfaceFollow_Behavior active:true
append C.assignments assin_02
assin_03 = crowdassignment team:team_01 behavior:TheAvoid_Behavior active:true
append C.assignments assin_03
)
/*
--this function creates a plane adds a noise and bend modifier and collapse the stack
--then it selects an edge and extract a path
--a leader is generated and assigned the path as path constraint
--then it generates and aligns obstacles according to the number of obstacles
--if an obstacle is not aligned properly by intersectray it gets deleted
*/

fn autoEnvironment numobstacles theColor switcher = (
try(
SuspendEditing()
resetMaxFile #noPrompt -- due to scope limitation a max reset was decided !
ResumeEditing()

)catch()
P = converttopoly(Plane width:250 length:500 lengthsegs:40 widthsegs:40)
N = NoiseModifier()
N.Fractal = true
addModifier P N
N.Strength.z = 50
B = Bend()
addmodifier P B
B.angle = -180 ; B.BendAxis = 0
B2 = Bend Angle: -90 BendAxis:1 ; addmodifier P B2
collapsestack p
polyop.setEdgeSelection P 160
P.EditablePoly.SelectEdgeLoop ()
P.EditablePoly.createShape "thePath" on P
if switcher == off then S = sphere radius:10 wirecolor:theColor else s = Box length:10 width:10 height:10 wirecolor:theColor
pc = path_constraint()
S.pos.Controller = pc
pc.path = $thePath
for i = 1 to numobstacles do (
theBox = box length:(random 5 10) width:(random 5 10) height:(random 5 10) Name:(uniquename "Obstacle_01"); CenterPivot theBox
theBox.wirecolor = (random white gray)
theBox.pos = [(random P.min.x P.max.x) , (random P.min.y P.max.y) , (random P.min.z P.max.z)]
in coordsys local (theBox.rotation.x = random 1 180 ; theBox.rotation.y = random 1 180; theBox.rotation.z = random 1 180)
theRay = ray theBox.pivot [theBox.pos.X,theBox.pos.Y,-50000]
theintersection = intersectray P theRay ; print theintersection
if theintersection != undefined then theBox.pos = theintersection.pos else delete theBox
redrawviews()
)

)


-- UI Configurateion
--these are set of rollouts and their event handlers made separatly and then added to a rollout floater
--if the user chooses to AutoEnvironment an additional rollout is created to give the options

--simple rollout to choose auto or manual creation of the environment
rollout Mode "Environment Mode"
(
Group "Mode"
(
radioButtons rdo1 "" labels:#("Manual","Auto_Environment ") default:1 columns:1 Align:#Center
)

on rdo1 changed item do
(
if item == 1 then
(
for i in theRolloutFloater.Rollouts do if i != Mode do removerollout i theRolloutFloater
addrollout Leader theRolloutFloater
addrollout Sur theRolloutFloater
addrollout Distribution_Object theRolloutFloater
addrollout Del theRolloutFloater
addrollout Obstacles theRolloutFloater
addrollout Simulation theRolloutFloater
)
else
(
for i in theRolloutFloater.Rollouts do if i != Mode do removerollout i theRolloutFloater
--addrollout Leader_Proxy theRolloutFloater
addrollout Environment_Setup theRolloutFloater
addrollout Leader theRolloutFloater
addrollout Sur theRolloutFloater
addrollout Distribution_Object theRolloutFloater
addrollout Del theRolloutFloater
addrollout Obstacles theRolloutFloater
addrollout Simulation theRolloutFloater
)
)
)
--environment options
rollout Environment_Setup "Environment_Setup"
(
Group "Obstacles"

(
Spinner No_Obstacles "Up To" type:#integer range:[1,1000000,40] Align:#Center
)

Group "Leader"
(
dropDownList ddl1 width:100 height:40 items:#("Sphere", "Box") align:#left across:2
colorPicker cp1 "" width:20 height:20 color:(color 255 0 0) align:#right across:2
)
Button Btn_Env "Generate Envoronment" ali:#center

on ddl1 selected item do
(

if item == 2 then switcher = on else switcher = off
)
on Btn_Env pressed do autoEnvironment NO_Obstacles.value cp1.color switcher

)
-- the leader rollout .. this rollout provides a button to choose the leader
rollout Leader "Leader"
(
Group "Leader"
(
PickButton PB_Leader "Pick The Leader !" Align:#Center AutoDisplay:true
)

on PB_Leader Picked obj do
(
if obj != undefined do TheTarget = obj
)

)

--the surface rollout .. this rollout provides a button to choose the Surface
rollout Sur "Surface"
(
Group "Surface"
(
Pickbutton PB_Surface "Pick The Surface !" Align:#Center AutoDisplay:true
)

on PB_Surface Picked obj do
(
if obj != undefined do TheSurface = obj
)
)
--distribution rollout ... proper values for autoEnvironment is x = - 130 and y = -240
rollout Distribution_Object "Distribution Object"
(
Group "Distribution Object"
(
Button Btn_Help "?" Across:2 align:#left
Button Btn_SphereDistribution "Create The Object" Across:2 align:#Right
Spinner Spin_Radius "Radius" type:#Float range:[0.001,1000000,40] Align:#Center enabled:false
Spinner Spin_Xpos "Position X" type:#Float range:[-1000000,1000000,0] Align:#Center enabled:false
Spinner Spin_Ypos "Position Y" type:#Float range:[-1000000,1000000,0] Align:#Center enabled:false
Spinner Spin_Zpos "Position Z" type:#Float range:[-1000000,1000000,0] Align:#Center enabled:false
)

on Btn_Help pressed do
(
MessageBox "This is a Distribution Sphere meant to Distribute the Delegates initially \n ControlThe Radius and Position for best Sim Environment "
)
on Btn_SphereDistribution pressed do
(
Try(Delete $TheSphere*)Catch()
Sphere name:"TheSphere" pos:[0,0,0] segments:40 radius:40
Spin_Radius.enabled = true
Spin_Xpos.enabled = true
Spin_Ypos.enabled = true
Spin_Zpos.enabled = true
)

on Spin_Radius changed val do ($TheSphere.Radius = Spin_Radius.Value)
on Spin_Xpos Changed val do ($TheSphere.Position.X = Spin_Xpos.Value)
on Spin_Ypos Changed val do ($TheSphere.Position.Y = Spin_Ypos.Value)
on Spin_Zpos Changed val do ($TheSphere.Position.Z = Spin_Zpos.Value)

)


--number of delegates to follow the leader
rollout Del "Delegates"
(
Group "Delegates"
(
Spinner Spin_NumDelegates "No. Delegates" type:#integer range:[1,50000000,10] align:#center
)
)
--this rollout provides a method to choose the obstacles
rollout Obstacles "Obstacles"
(
Group "Obstacles"
(
Button Btn_PickObstacles ">> Select Obstacles <<" width:(Obstacles.width - 20) Align:#Center
Label lab_01 "No. Obstacles = 0"
)

on Btn_PickObstacles Pressed do
(
max tool hlist
if (Selection.Count == 0 ) then (lab_01.text = "No Obstacles Assigned ")
else (
Arr_Obstacles = Selection as array
lab_01.text = "No. Obstacles = " + Selection.count as string
)
)
on Btn_Help pressed do
(
MessageBox "This is a Distribution Sphere meant to Distribute the Delegates initially \n ControlThe Radius and Position for best Sim Environment "
)
)
--Simulation rollout ... self explanatory
rollout Simulation "Simulation"
(
Group "Simulation"
(
Spinner Spin_Frames "Frames" type:#integer range:[1,TicksToFrames AnimationRange.End,TicksToFrames AnimationRange.End] align:#center
Button Btn_Solve "Solve" Width:(Simulation.width - 40) Height:30
)

on Btn_Solve pressed do
(
if (TheSurface !=undefined and TheTarget !=undefined and $TheSphere != undefinde) Then
(
MakeTheCrowd Del.Spin_NumDelegates.Value Spin_Frames.Value
Crowds.Solve C
)
else (MessageBox "Please Fill The Parameters First ")
)
)

theRolloutFloater= newrolloutfloater "Crowd_Solver" 180 200
addrollout Mode theRolloutFloater
addrollout Leader theRolloutFloater
addrollout Sur theRolloutFloater
addrollout Distribution_Object theRolloutFloater
addrollout Del theRolloutFloater
addrollout Obstacles theRolloutFloater
addrollout Simulation theRolloutFloater

)
 
Old 06 June 2010   #26
epic1511, I think you are better of starting a new thread and cleaning this post, it's off topic for this thread, also have a look at the code # button in the editor it does a better job on the formatting and readability.

But maxscript is really cool, and like with anything if you do it a lot, you'll get good at it, or at least proficient
Cheers,
-Johan
__________________
Online: LinkedIn
 
Old 06 June 2010   #27
thanks johan

i will consider # button next time

but do u think u can help me with my script...i really need it and dont know what to do??

i have spent more than 6 days trying to figure out something but its all useless!

c# is much much better....however my constructor insists on learning maxscript
 
Old 03 March 2011   #28
I know this can be done but I just can't remember how - anyone know how I can change the colour of my current set of ( and ) - at present the opposite one to my cursor position goes a slightly lighter blue but I want to make this a bit more obvious...
__________________
Matt Rennie
Sr. Character Rigger
Rockstar North
 
Old 04 April 2011   #29
thanks a lot .

hi JHN:
many thanks for ur maxscript.api file .
Im using Vim writing maxscript . this api file is very clean , and I just rename it to maxscript.dict . running very good in vim .

coz ur thread about " maxscript autocomplete " has been closed . so I come here to say :
ur maxscript.api file is really a greatjob .

many thanks !
__________________
-- to be better every day --
google talk : haibo.lan@gmail.com
msn: ehblan@hotmail.com
-- add me to ur IM buddy list as u wish.

Last edited by hblan : 04 April 2011 at 01:38 PM.
 
Old 07 July 2011   #30
Hello, well first of all I want say thanks for this good tutorial, and well maybe you can help me with 1 script, because I'm new and can't make it work, when try import a file into max it say me that.



if (heapSize < 20000000) then
	heapSize = 200000000 -- allow ~ 40 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"

fname = GetOpenFileName caption:"Open 7 Souls Model File" types:"7 Souls Model File(*.msh)|*.msh"
f = fopen fname "rb"   --open file in read only format
base = getFilenamePath fname
basefile = getFilenameFile fname -- returns: "myImage.jpg"
basefile = substring basefile 3 (basefile.count - 2)
ss = substring base 1 (base.count - 5) -- returns "rof"
print basefile
print ss
DiffuseTex = (ss + "texture\diffuse\4" + basefile + ".dds")

print DiffuseTex
fn ReadFixedString bstream fixedLen =
(
	local str = ""
	for i = 1 to fixedLen do
	(
		str += bit.intAsChar (ReadByte bstream #unsigned)
	)
	str
)

struct weight_data
(
	boneids,weights
)

Vert_array = #()
Normal_array = #()
UV_array = #()
Face_Array = #()
Weight_array = #()
VertID_array = #()

idstring2 = ReadFixedString  f 4
if idstring2 != "MESH" do (
BoneFile = readlong f
Skelleton = (ss + "bind\g" + (BoneFile as string) + ".bnd")
print Skelleton
print ("BoneFile" + "_" + (BoneFile as string))
Mesh_Name_Size = readlong f
Mesh_Name = ReadFixedString  f Mesh_Name_Size
vertcount = readlong f
facecount = readlong f
weightcount = readlong f
weightcount2 = readlong f
for i = 1 to vertcount do (
vx = readfloat f 	 --read xyz coordinates
vy = readfloat f 
vz = readfloat f
nx = readfloat f
ny = readfloat f
nz = readfloat f
tu = readfloat f
tv = readfloat f * -1	
append Vert_array [vx,vy,vz] --save verts to Vert_array
append UV_array [tu,tv,0]
append Normal_array [nx,ny,nz]
)
facedirection = 1
for i = 1 to facecount  do (
f1 = readlong f + 1
f2 = readlong f + 1
f3 = readlong f + 1
append Face_array [f1,f2,f3]
)
for i = 1 to weightcount do (
boneids = ((readlong f) + 1)
VertID = ((readlong f) + 1)
weights = readfloat f
v2 = readlong f
w2 = readfloat f
v3 = readlong f
w3 = readfloat f
v4 = readlong f
w4 = readfloat f
append Weight_array (weight_data boneids:boneids weights:weights)
append VertID_array VertID
)
for i = 1 to weightcount2 do (
bone1 = readlong f
VertID = ((readlong f) + 1)
weight1 = readfloat f
w = (weight_data boneids:#() weights:#())
			w1 = weight1 as float
			append w.boneids (bone1+1)
			append w.weights (w1)
v2 = readlong f
w2 = readfloat f
v3 = readlong f
w3 = readfloat f
v4 = readlong f
w4 = readfloat f
append Weight_array w
append VertID_array VertID
)
print (ftell f)
msh = mesh vertices:Vert_array faces:Face_array   --build mesh
msh.numTVerts = UV_array.count
buildTVFaces msh
meditMaterials[1] = Standardmaterial ()
msh.material = meditMaterials[1]
meditMaterials[1].diffuseMap = Bitmaptexture fileName:DiffuseTex
meditMaterials[1].opacityMap = Bitmaptexture fileName:DiffuseTex
meditMaterials[1].opacityMap.monoOutput = 1
msh.name = Mesh_Name
for j = 1 to UV_array.count do setTVert msh j UV_array[j]
for j = 1 to Face_array.count do setTVFace msh j Face_array[j]
for j = 1 to Normal_array.count do setNormal msh j Normal_array[j]
)
print (ftell f)
usedbones_array = #()
if idstring2 == "MESH" do (
mcount = readlong f
mid = readlong f
BoneFile = readlong f
Skelleton = (ss + "bind\g" + (BoneFile as string) + ".bnd")
print Skelleton
print ("BoneFile" + "_" + (BoneFile as string))
Mesh_Name_Size = readlong f
Mesh_Name = ReadFixedString  f Mesh_Name_Size
vertcount = readlong f
facecount = readlong f
for i = 1 to vertcount do (

vx = readfloat f 	 --read xyz coordinates
vy = readfloat f 
vz = readfloat f
nx = readfloat f
ny = readfloat f
nz = readfloat f
tu = readfloat f
tv = readfloat f * -1
if mcount == 2 Do (
fseek f 0x10#seek_cur
)
Bone1 = readbyte f#unsigned
Bone2 = readbyte f#unsigned
Bone3 = readbyte f#unsigned
Bone4 = readbyte f#unsigned
weight1 = readfloat f
weight2 = readfloat f
weight3 = readfloat f
weight4 = readfloat f

w = (weight_data boneids:#() weights:#())
maxweight = 0
if(Bone1 != 0) then
	maxweight = maxweight + weight1
if(Bone2 != 0) then
	maxweight = maxweight + weight2
if(Bone3 != 0) then
	maxweight = maxweight + weight3
if(Bone4 != 0) then
	maxweight = maxweight + weight4

if(maxweight != 0) then (
		if(weight1 != 0) then (
			w1 = weight1 as float
			append w.boneids (bone1 + 1)
			append w.weights w1
		)
		if(weight1 != 0) then (
			w2 = weight2 as float
			append w.boneids (bone2 + 1)
			append w.weights w2
		)
		if(weight1 != 0) then (
			w3 = weight3 as float
			append w.boneids (bone3 + 1)
			append w.weights w3
		)
		if(weight1 != 0) then (
			w4 = weight4 as float
			append w.boneids (bone4 + 1)
			append w.weights w4
		)		
	)
append Weight_array w
append Vert_array [vx,vy,vz] --save verts to Vert_array
append UV_array [tu,tv,0]
append Normal_array [nx,ny,nz]
)
if mcount == 2 Do (
usedbones = readbyte f#unsigned
for a = 1 to usedbones do (
bid = readbyte f#unsigned + 1
append usedbones_array bid
)
)
facedirection = 1
if mcount == 2 Do (
for i = 1 to facecount  do (
f1 = readshort f + 1
f2 = readshort f + 1
f3 = readshort f + 1
append Face_array [f1,f2,f3]
)
)
if mcount == 1 Do (
for i = 1 to facecount  do (
f1 = readlong f + 1
f2 = readlong f + 1
f3 = readlong f + 1
append Face_array [f1,f2,f3]
)
)
print (ftell f)
msh = mesh vertices:Vert_array faces:Face_array   --build mesh
msh.numTVerts = UV_array.count
buildTVFaces msh
meditMaterials[1] = Standardmaterial ()
msh.material = meditMaterials[1]
meditMaterials[1].diffuseMap = Bitmaptexture fileName:DiffuseTex
meditMaterials[1].opacityMap = Bitmaptexture fileName:DiffuseTex
meditMaterials[1].opacityMap.monoOutput = 1
msh.name = Mesh_Name
for j = 1 to UV_array.count do setTVert msh j UV_array[j]
for j = 1 to Face_array.count do setTVFace msh j Face_array[j]
for j = 1 to Normal_array.count do setNormal msh j Normal_array[j]
)
actionMan.executeAction 0 "63508"

fclose f
f = fopen Skelleton "rb"
idstring = ReadFixedString f 4
BNArr = #()
if idstring != "BIND" Do (
nsize = readlong f
skelname = ReadFixedString f nsize
bonecount = readlong f
for a = 1 to bonecount Do (
boneid = readlong f + 1
boneparent = readlong f + 1
f1 = readfloat f
f2 = readfloat f
f3 = readfloat f
f4 = readfloat f
f5 = readfloat f
f6 = readfloat f
f7 = readfloat f
tfm = (quat f4 f5 f6 (f7 * -1)) as matrix3
tfm.row4 = [f1,f2,f3]
if isvalidnode (getNodeByName (a as string)) != true then (
if (boneparent != boneid) do (
tfm = tfm * BNArr[boneparent].objecttransform
 )	
newBone = bonesys.createbone	\
				  tfm.row4	\
				  (tfm.row4 + 0.01 * (normalize tfm.row1)) \
				  (normalize tfm.row3)
			newBone.name = (a as string)
			newBone.width  = 0.01
			newBone.height = 0.01
			newBone.transform = tfm
			newBone.setBoneEnable false 0
			newBone.wirecolor = yellow
			newbone.showlinks = true
			newBone.pos.controller	  = TCB_position ()
			newBone.rotation.controller = TCB_rotation ()
 if (boneparent != 0) then
 newBone.parent = BNArr[boneparent]
append BNArr newBone
)
)
)

if idstring == "BIND" Do (
fseek f 0x8#seek_cur
nsize = readlong f
skelname = ReadFixedString f nsize
bcount1 = readbyte f#unsigned
bcount2 = readbyte f#unsigned
bonecount  = (bcount1 + bcount2)
for a = 1 to bonecount Do (
boneid = readlong f + 1
boneparent = readlong f + 1
f1 = readfloat f
f2 = readfloat f
f3 = readfloat f
f4 = readfloat f
f5 = readfloat f
f6 = readfloat f
f7 = readfloat f
null = readbyte f#unsigned
tfm = (quat f4 f5 f6 (f7 * -1)) as matrix3
tfm.row4 = [f1,f2,f3]
if isvalidnode (getNodeByName (a as string)) != true then (
if (boneparent != boneid) do (
tfm = tfm * BNArr[boneparent].objecttransform
 )	
newBone = bonesys.createbone	\
				  tfm.row4	\
				  (tfm.row4 + 0.01 * (normalize tfm.row1)) \
				  (normalize tfm.row3)
			newBone.name = (a as string)
			newBone.width  = 0.01
			newBone.height = 0.01
			newBone.transform = tfm
			newBone.setBoneEnable false 0
			newBone.wirecolor = yellow
			newbone.showlinks = true
			newBone.pos.controller	  = TCB_position ()
			newBone.rotation.controller = TCB_rotation ()
 if (boneparent != 0) then
 newBone.parent = BNArr[boneparent]
append BNArr newBone
)
)
)
max modify mode
print idstring
if idstring2 != "MESH" do (

select msh
skinMod = skin ()
addModifier msh skinMod
for i = 1 to BNArr.count do
(
	maxbone = getnodebyname BNArr[i].name
	if i != BNArr.count then
		skinOps.addBone skinMod maxbone 0
	else
		skinOps.addBone skinMod maxbone 1
)
modPanel.setCurrentObject skinMod
for i = 1 to Weight_array.count do
(
	skinOps.SetVertexWeights skinMod VertID_array[i] Weight_array[i].boneids Weight_array[i].weights
)
)

if idstring2 == "MESH" do (
if mcount == 2 Do (
BNArr = #()
for a = 1 to usedbones_array.count do (
append BNArr (getnodebyname (usedbones_array[a] as string))
)
)
select msh
skinMod = skin ()
addModifier msh skinMod
for i = 1 to BNArr.count do
(
	maxbone = getnodebyname BNArr[i].name
	if i != BNArr.count then
		skinOps.addBone skinMod maxbone 0
	else
		skinOps.addBone skinMod maxbone 1
)
modPanel.setCurrentObject skinMod
for i = 1 to Weight_array.count do
(
	w = Weight_array[i]
	bi = #()
	wv = #()
	for j = 1 to w.boneids.count do
	(
		boneid = w.boneids[j]
		weight = w.weights[j]
		append bi boneid
		append wv weight
	)	
	skinOps.ReplaceVertexWeights skinMod i bi wv
)
)

max create mode
max zoomext sel all
fclose f
 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:23 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.