Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

[Maxscript] Creating Objects on Relative Position

polycounter lvl 4
Offline / Send Message
silver_hoodlum polycounter lvl 4
Hi guys,

I just started learning Maxscript and some of you might find my problems quite dummy.

What I'm trying to achieve is to get the boxes I create (purple) snapped to the faces of an existing object (green one). I guess there is various ways of doing this.

Snap_Face_to_Face_Problem.jpg

Snap_Face_to_Face_Problem_2.jpg
I created a script which sets up the pivot points and moves it at the end of the existing object position, but is a very ineffective way of doing it.

I've seen online people suggest using rayintersect or coordsys.

Any recommendations to get this?

Thanks in advance

Replies

  • monster
    Offline / Send Message
    monster polycounter
    You should post the code that is not working, with a comment on where you think there is a problem.

    Also, how is this different from Object Painter in the Ribbon? Or maybe Normal Align?
  • Joost
    Offline / Send Message
    Joost polycount sponsor
  • silver_hoodlum
    Offline / Send Message
    silver_hoodlum polycounter lvl 4
    @monster you can see down my current code. This tool works perfectly but I want this to snapped to a face of an existing box. I know how to script the pivot point but dont know how can place it exactly snaped with a face :( at the moment. Any idea?

    @joost ill check if it can be used

    rollout Boxtool "Box Creator"
    (
    spinner count "Number:" type:#integer range: [1,100,10]
    spinner size "Box Size:" range: [1,100,8]
    spinner distance "Distance Inbetween:" range: [1,200,25]
    button create "Create Boxes"

    on create pressed do
    for i in 1 to count.value do
    box length: (10) width: (size.value) height: (10) position:[i*distance.value,0,0]
    )

    MainFloater = NewRolloutFloater "Box Creator" 250 150
    addRollout Boxtool MainFloater
  • monster
    Offline / Send Message
    monster polycounter
    The tool needs to be much more complex to handle what you want to do. Here's a quick example below.
    1. (
    2. rollout Boxtool "Box Creator"
    3. (
    4. spinner count "Number:" type:#integer range: [1,100,10]
    5. spinner size "Box Size:" range: [1,100,8]
    6. spinner distance "Distance Inbetween:" range: [1,200,25]
    7. pickbutton create "Create Boxes" width:120
    8. --GET AN OBJECT TO CREATE OTHER OBJECTS ON
    9. on create picked obj do
    10. (
    11. if isValidNode obj do
    12. (
    13. --GET THE MOUSE RAY FROM THE USER CLICK
    14. intRay = intersectRay obj (mapScreenToWorldRay mouse.pos)
    15. --CREATE A TRANSFORM FROM THE RAY INTERSECT WITH SURFACE
    16. creationTransform = matrixFromNormal intRay.dir * transMatrix intRay.pos
    17. --CREATE BOXES IN THE NEW TRANSFORM
    18. in coordsys creationTransform
    19. (
    20. for i in 1 to count.value do
    21. (
    22. b = box length: (10) width: (size.value) height: (10)
    23. --ROTATE AND PLACE THE BOX
    24. b.transform = creationTransform
    25. b.pos = [(i-1)*distance.value,0,0]
    26. )
    27. )
    28. )
    29. )
    30.  
    31. )
    32.  
    33. MainFloater = NewRolloutFloater "Box Creator" 250 150
    34. addRollout Boxtool MainFloater
    35. )
  • silver_hoodlum
    Offline / Send Message
    silver_hoodlum polycounter lvl 4
    @monster thanks for this monster, i will analyse it and get back. This is definitely the kind of stuff pushed me into learning scripting and technical stuff. Is such a pity there are only a few basic tutorials of maxscript online, find it hard sometimes to get a starting point.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    @monster thanks for this monster, i will analyse it and get back. This is definitely the kind of stuff pushed me into learning scripting and technical stuff. Is such a pity there are only a few basic tutorials of maxscript online, find it hard sometimes to get a starting point.

    CgSociety, Maxscript documentation and analyzing other peoples scripts is pretty much the way I learned Maxscript. Though thats also how I learn other languages so might be different per person.
Sign In or Register to comment.