XeNTaX Forum Index
Forum MultiEx Commander Tools Tools Home
It is currently Fri Nov 24, 2017 1:20 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: MaxScript snippets
PostPosted: Mon Sep 02, 2013 9:53 pm 
Offline
ultra-veteran
ultra-veteran
User avatar

Joined: Mon Sep 26, 2011 12:51 pm
Posts: 354
Has thanked: 13 times
Have thanks: 120 times

Hi guys, I was looking on these forums to find some maxscripting topic that would have some interesting scripting but I didn't find anything.
So if there is one, please move this topic to there, if not, I would like people that have max knowledge, interesting snippits, questions and so on about importing models into max using maxscript to drop them in this forum topic.

Thnx
T.

You can make the ads go away by registering


_________________
My Game Dev Blog
My Starcraft II Mod files and scripts


Top
 Profile  
 
 Post subject: MaxScript snippets
PostPosted: Mon Sep 02, 2013 9:58 pm 
Offline
ultra-veteran
ultra-veteran
User avatar

Joined: Mon Sep 26, 2011 12:51 pm
Posts: 354
Has thanked: 13 times
Have thanks: 120 times
To start out, I would like to post one script that is breaking my ass for quite some time now

So some games store their uv's in half float precision points, but Max can only deal with float precision points,
this is used in games like TheSettlers 7, Castlevania - Lords of Shadows and so on
So here is a script that converts this half float to a float, it may not be the best script, but it did keep me up for 2 days straight!

Code:
fn Half2Float u=
(

   sign = bit.and ( bit.shift u -15 ) 0x00000001
   exponent = bit.and ( bit.shift u -10 ) 0x0000001F
   mantis = bit.and u 0x000003FF

   if (exponent == 0) then
   (
      if(mantis == 0) then
      (
         return bit.shift sign 31
      )
      else
      (
                        tmp = bit.and mantis 0x00000400
         while ( tmp !=0  ) do
         (
            mantis = bit.shift mantis 1
            exponent -=1
         )
         exponent = exponent +1   
         mantis = bit.and mantis 0x00000400 --> should be ~0x00000400
      )
   )
   if(exponent == 31) then
   (
      if( mantis ==0) then
         return bit.or (bit.shift sign 31) 0x7F800000
      else
         return bit.or (bit.or (bit.shift sign 31) 0x7F800000 ) (bit.shift mantis 13)
   )   
   
   exponent = exponent + (127-15)
   mantis = bit.shift mantis 13
   
   val = bit.or ( bit.or (bit.shift sign 31) ( bit.shift exponent 23) ) (mantis)
   
   fOut = fopen "test.bin" "wb"
   writelong fOut val
   fflush fOut
   fclose fOut

   fIn = fopen "test.bin" "rb"
   var = readfloat fIn
   fclose fIn
   
   return var
)


Enjoy

T.

_________________
My Game Dev Blog
My Starcraft II Mod files and scripts


Top
 Profile  
 
 Post subject: Re: MaxScript snippets # processing multiple model files #
PostPosted: Sun Sep 27, 2015 5:16 pm 
Offline
M-M-M-Monster veteran
M-M-M-Monster veteran
User avatar

Joined: Fri Apr 20, 2012 9:24 am
Posts: 2154
Location: Nexus, searching for Jim Kirk
Has thanked: 426 times
Have thanks: 1100 times
hah, two years later! :D

that's a good idea, TM :) but poor people in this poor forum (me included) aren't smart enough to support such good ideas...

I'd like to show how to process multiple files with a maxscript (I'm not too familiar with ms so don't blame me).
Dunno if I ever will code the 2nd part but here's the first (modified from http://www.rsart.co.uk/2011/07/07/maxsc ... -handling/):

after some beautifying you get a function which gets you the names of the model files:

Code:
fn process_models modelfolder= (

  model_files = #()
  model_type = ".m3g"

  -- Get all the m3g files   
  diff_files = modelFolder  + model_type 
  thefiles = getfiles diff_files
   
  for f in thefiles do   
  (
    append model_files ((getfilenamefile f) + model_type)
  )

  model_files -- return this
)   

ClearListener()
process_models "K:\\Programme\\Autodesk\\3ds Max 2013\\scripts\\RR3\\*"
print model_files

resulting listener output:

#("2013_hyundai_wrc_a.m3g", "2013_hyundai_wrc_b.m3g", "2013_hyundai_wrc_c.m3g", "2013_hyundai_wrc_d.m3g", "2013_mclaren_mp412c_e.m3g", "2013_mclaren_mp412c_g.m3g", "2013_mclaren_mp412c_h.m3g", "tyre_standard1_tyres.m3g")
"2013_hyundai_wrc_a.m3g"
"2013_hyundai_wrc_b.m3g"
"2013_hyundai_wrc_c.m3g"
"2013_hyundai_wrc_d.m3g"
"2013_mclaren_mp412c_e.m3g"
"2013_mclaren_mp412c_g.m3g"
"2013_mclaren_mp412c_h.m3g"
"tyre_standard1_tyres.m3g"

Now you've to erase the getOpenFileName dialogue line from your maxscript,
make a function of the whole script and process all files in the model_files list
in a for loop that calls that function.

That's how I would do it. (Didn't check it but should work.)

btw. "diff" in the original code was meant for "diffuse" now it's just "different"...

_________________
"you can't always get things served on a silver tray"
extracting simple models: http://forum.xentax.com/viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip

"We are Microsoft. You will be assimilated. Resistance is Futile."


Top
 Profile  
 
 Post subject: Re: MaxScript snippets
PostPosted: Thu Feb 04, 2016 4:15 pm 
Offline
ultra-n00b

Joined: Thu Feb 04, 2016 4:11 pm
Posts: 1
Has thanked: 0 time
Have thanks: 2 times
Quite useful snippet, sometimes it is necessary to split smoothing groups into elements:
Code:
/*!--------------------------------------------------------------------------------------------------------------------
* @file split smoothing groups into elements
* @details File contains split smoothing groups to elements function realisation.
* @author Aviator777 / Tank
* @copyright
* @version 1.0
* @date 28.08.2015
*---------------------------------------------------------------------------------------------------------------------
*/

/*
Notes:
Use Editable Poly mode, before applying this script, apply to model autosmooth, or use appropriate smooth groups !
*/

global groupIDsUsed = #()

fn processSelection tmesh =
(
   try
   (
      local faceCount = tmesh.getNumFaces()
      for f = 1 to faceCount  do
      (
         local groupID  = (polyop.getFaceSmoothGroup tmesh f)
         appendIfUnique groupIDsUsed groupID
      )

      for g = 1 to groupIDsUsed.count do
      (
         local faceGroup = #()
         for i = 1 to faceCount do
         (
            local polygonGroupID  = (polyop.getFaceSmoothGroup tmesh i) as integer
            if polygonGroupID == (groupIDsUsed[g] as integer) do
            (
               append faceGroup i
            )
         )
         polyop.detachFaces tmesh faceGroup asNode:false
      )
      messageBox "Done !" title:"Information"
   )
   catch
   (
      print "Could not split smoothing groups into elements."
   )
)
rollout spl "Split tool" width:176 height:104
(
   button 'btn1' "Split Groups Into Elements" pos:[22,24] width:140 height:58 align:#left tooltip:"Split Polygon Smoothing Groups Into Elements"
   on btn1 pressed do
   (
      clearListener()
      sl = $selection
      if sl.count > 0 do
      (
         processSelection sl[1]
      )
      
   )
)
createDialog spl


If anyone needs any help with maxscript, or any tips, I will be happy to help, have been writing scripts for maxscript for quite a while now.



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group