Notifications
Clear all

[Closed] Can this be optimized?

Hey Guys,
Im messing around with generating a “point cloud” in max.
This is the code I have written. Is there a fater way to generate this data, as it can get very slow when i have spacing between the points of about 10cm(using a 10mx10mx10meter object for example)

global mSpacing = 100 – in cmeters
global mSphereRadius = 0.1
global mSphereSegments = 4

    mSelection = selection as array
    
    -- get max and min of selection to create bounding box.
    mMin = mSelection[1].min
    mMax = mSelection[1].max
    for obj in mSelection do
    (
        if obj.min.x < mMin.x do
            mMin.x = obj.min.x
        if obj.min.y < mMin.y do
            mMin.y = obj.min.y
        if obj.min.z < mMin.z do
            mMin.z = obj.min.z                
            
            
        if obj.max.x > mMax.x do
            mMax.x = obj.max.x
        if obj.max.y > mMax.y do
            mMax.y = obj.max.y
        if obj.max.z > mMax.z do
            mMax.z = obj.max.z                
    )
    
    
    -- bbox padding/round off
    mMin -= mSpacing
    mMax += mSpacing
    

    mMin.x = fnRoundToIncrement mMin.x mSpacing
    mMin.y = fnRoundToIncrement mMin.y mSpacing
    mMin.z = fnRoundToIncrement mMin.z mSpacing
    
    mMax.x = fnRoundToIncrement mMax.x mSpacing
    mMax.y = fnRoundToIncrement mMax.y mSpacing
    mMax.z = fnRoundToIncrement mMax.z mSpacing


    mSpawnMesh = sphere radius:mSphereRadius segs:mSphereSegments
    convertToMesh mSpawnMesh
    mCollection = #()
    
    -- Do this in reverse order from the above code so its in the correct order...
    -- make first row

    for z = mMin.z to mMax.z by mSpacing do
    (
        mCopy = copy mSpawnMesh
        mCopy.pos = [mMin.x,mMin.y,z]    
        append mCollection mCopy                
    )
    
    -- collapse first row
    delete mSpawnMesh
    mRow = fnCollapse mCollection 
    
    mCollection = #()
    append mCollection mRow
    
    
    
    -- the 2nd row
    for y = mMin.y to mMax.y by mSpacing do
    (        
        mCopy = copy mRow
        mCopy.pos.y = y
        append mCollection mCopy            
    )
    
    
    -- collapse 2nd row
    mRow = fnCollapse mCollection 
    mCollection = #()
    append mCollection mRow        
    
    
    
    
    -- the 3rd row
    for x = mMin.x to mMax.x by mSpacing do
    (        
        mCopy = copy mRow
        mCopy.pos.x = x
        append mCollection mCopy            
    )        
    
    -- collapse 3rd row
    mPointCloudMesh = fnCollapse mCollection
    mPointcloudMesh.name = uniquename "PC_PointCloud_01"
    select mPointCloudMesh
1 Reply

Ok thinking about this, would it be quicker to generate my tri-meshdata in maxscript then just dump it all into a visible mesh? I would assume it would be?