Skip to content

3Ds Max script for Exact and Efficient Intersection Resolution #1

Description

@jiayaozhang

Thanks for open-source the code for Exact and Efficient Intersection Resolution for Mesh Arrangements

I find it very interesting and write a 3ds Max script for it and hope can make your paper more useful and make a big impact for more people.

Generally save the below code as Self_Intersect.ms and then run this script in 3Ds Max and would look like this

Image

-- Self_Intersect.ms
-- Jiayao Zhang 2025 March 11th
-- 3Ds Max script for solving self intersect mesh models
-- Processing with mesh self intersection tool

try(
destroyDialog selfIntersectRoller
)catch()

rollout selfIntersectRoller "Self-intersection tools" width:300 height:150
(
    button btnProcess "Process Selected Objects" width:200 height:30 pos:[50,30]
    progressBar progBar width:200 pos:[50,80] color:blue value:0
    label lblStatus "Ready" align:#center width:200 pos:[50,110]
    
    fn processSelectedObject = (
        if selection.count == 0 then (
            messageBox "Please select an object first!" title:"Error"
            return false
        )
        if selection.count > 1 then (
            messageBox "Please select only one object!" title:"Error"
            return false
        )
        
        local obj = selection[1]
        local tempFile = (getFilenamePath (getThisScriptFilename())) + "self_intersect.obj"
        -- Update status
        lblStatus.text = "Exporting objects..."
        progBar.value = 25
        
        -- Export selected objects as OBJ
        try(
            select obj
            exportFile tempFile #noPrompt selectedOnly:true using:OBJExp
        )catch(
            messageBox ("Export failed " + (getCurrentException())) title:"Error"
            return false
        )
        
        -- Update processing status
        lblStatus.text = "Processing model..."
        progBar.value = 50
        
        -- Execute external program
        local scriptDir = getFilenamePath (getThisScriptFilename())
        local command = scriptDir + "Intersection\\OpenMeshCraft-Arrangements.exe " + 
        tempFile + " -v -p=16 -r --tree_leaf=50 --tree_adaptive=0.1"
        
        lblStatus.text = "Executing command: " + command
        
        -- Record original file size
        local originalFileSize = getFileSize tempFile
        
        try(
            -- Execute command and wait
            DOSCommand command
        )catch(
            messageBox ("Processing failed: " + (getCurrentException())) title:"Error"
            return false
        )

        -- Update import status
        lblStatus.text = "Importing processed model..."
        progBar.value = 75
        
        -- Wait for file write completion
        sleep 0.5
        
        -- Verify file existence
        if not doesFileExist tempFile then (
            messageBox "Processed file not found!" title:"Error"
            return false
        )
        
        -- Check file size changes
        local newFileSize = getFileSize tempFile
        if newFileSize <= originalFileSize then (
            messageBox ("File processing may have failed. Original size: " + originalFileSize as string + " bytes, New size: " + newFileSize as string + " bytes") title:"Warning"
        )
        
        -- Import processed model
        try(
            importFile tempFile #noPrompt using:OBJImp
        )catch(
            messageBox ("Import failed: " + (getCurrentException())) title:"Error"
            return false
        )
        
        -- Complete processing
        lblStatus.text = "Processing complete"
        progBar.value = 100
        
        true
    )
    
    -- Button click handler
    on btnProcess pressed do
    (
        progBar.value = 0
        lblStatus.text = "Starting process..."
        
        if not (processSelectedObject()) then
        (
            lblStatus.text = "Processing failed"
            progBar.value = 0
        )
    )
)

-- Create dialog
createdialog [selfIntersectRoller](url)

Best regards!
👍

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions