Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Proxy mesh creation feedback and scripting questions about that.

Discussion in 'Pixyz' started by bjornsyse, Jul 6, 2023.

  1. bjornsyse

    bjornsyse

    Joined:
    Mar 28, 2017
    Posts:
    92
    Hi

    I'm trying to setup a script that can create a proxy mesh for me. I find the builtin versions too simplistic and lack some organisation features that make them hard to use in any type of semi automated scenario.

    Main problems being:

    • When using Optimize Mesh > Proxy Mesh the new mesh ends up at the root with a scramled name. This is not very helpful. I'd like som options to create it as a sibling with the same name using a custom suffix like _Proxy at least.
    upload_2023-7-6_9-0-50.png

    • If I use Proxy mesh + Bake, the setting for resolution are inverted so a higher value is more detail where as in Proxy mesh alone it's the mm size of the voxel grid. Confusing. Furthermore, the new occuerence does not only get a scrambled name, it is also assigned with a new material named "Baked" using these texture names:

    upload_2023-7-6_9-4-46.png PiXYZStudio_udzArbXOlE.png


    Imagine doing that on 15 different occurences and trying to figure out what goes to what when exporting.

    Therefore, I figured I'd venture into lining this process up in a script to achieve the following:

    I've stumbled upon some roadbumps while scripting though, mainly around these tasks where i find the API documentation is not very helpful. Thankful if someone could shine some light on these matters:

    Material creation. How to go about creating a material and assigning it to the newly created occurence?
    Rename. I haven't found a way to rename an occurence, which surprises me. I had to place it as a child to another occurence I created from scratch with a custom name,
    Name of textures. How can I make sure baked textures get certain names?
    Polycount. Is there any way programmatically to get the triangle count of an occurrence?
    Texture baking. How can I assure textures are named in a logical fashion, or rename them after creation?

    Here is my script so far btw:

    Code (csharp):
    1. from pxz import *
    2.  
    3. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    4. # [USER PARAMETER]
    5. PROXY_SUFFIX = '_Proxy'
    6. PROXY_QUALITY = 40
    7.  
    8. # Get selected occurrences
    9. occurrences = scene.getSelectedOccurrences()
    10.  
    11. # Ensure that there is at least one occurrence
    12. if len(occurrences) > 0:
    13.  
    14.     # Get the name of the occurrence
    15.     occurrence_name = scene.getNodeName(occurrences[0]) + PROXY_SUFFIX
    16.  
    17.     # Create new occurrence with correct name and prefix.
    18.     _proxyMeshParent = scene.createOccurrence(occurrence_name, scene.getParent(occurrences[0]))
    19.    
    20.     print("New occurrence created: ", scene.getNodeName(_proxyMeshParent))
    21.  
    22.     # Create a proxy from meshes (your existing code)
    23.     _proxyMesh = algo.proxyMesh(occurrences, PROXY_QUALITY, 0, 0, False)
    24.    
    25.     # Move it to the named parent
    26.     scene.moveOccurrences([_proxyMesh], _proxyMeshParent)
    27.  
    28.     # TODO: Print difference in polycount from original to new proxy
    29.    
    30.     # TODO: Create material
    31.     #    _material = malgo.createMaterialFromDefinition([ occurrence_name, [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0]])
    32.     #    _material = algo.createMaterial("Test", "Test")
    33.    
    34.     # Assign it to the proxy.
    35.     #    scene.setOccurrenceMaterial(_proxyMesh, _material)
    36.  
    37.     # UV map proxy mesh
    38.     # algo.automaticUVMapping([_proxyMesh], 0, 0.500000000000, -1, True, True)
    39.    
    40.     # Bake diffuse texture from the old mesh to the proxy mesh. Make sure texture is named properly.
    41.     _ret_ = algo.bakeMaps([_proxyMesh], [occurrences[0]], [pxz.algo.BakeMap(0, [])], 0, 2048, 1, True, "_diffuse", [], -1, 0, 0.100000000000, False, 0.000000000000, [])
    42.    
    43.     # Assign the textures to the material.
    44.  
    45.     # Export all texture maps?
     
  2. laurent-milon

    laurent-milon

    Unity Technologies

    Joined:
    Nov 30, 2022
    Posts:
    14
    Hello @bjornsyse good to see you here :)
    Did you had a look at the Pixyz Studio "Sample scripts" folder? upload_2023-7-7_11-1-47.png

    I think couple scripts could help you figure the answers to some of your current blockers.
    Especially those two: upload_2023-7-7_11-1-16.png

    Keep us posted and hopefully someone with better dev skills than me will visit your thread!
     
  3. bjornsyse

    bjornsyse

    Joined:
    Mar 28, 2017
    Posts:
    92
    HI Laurent! Yes, figured I inaugerate the new forum :)

    Thanks, great idea with the sample scripts, I'll have a look at them!

    EDIT: Managed to find the rename using this command:

    core.setProperty(occurrence, "Name", occurrence_name)


    .. and material creation was also covered in the first example you provided. Still looking for texture naming though.
     
    Last edited: Jul 7, 2023
  4. bjornsyse

    bjornsyse

    Joined:
    Mar 28, 2017
    Posts:
    92
    Hi again, Managed to get a decent script going, thanks for your input.

    What I'm still looking for is a way to get a different naming of the textures created by algo.bakeMaps. With the current implementation every occurrence I create a proxy for will get the exact same name of it's respective set of textures. Diffuse, Normal etc which makes it close to useless.
     
  5. bjornsyse

    bjornsyse

    Joined:
    Mar 28, 2017
    Posts:
    92
    Can now report the following:

    If I use the parameter
    mapSuffix
    in algo.bakeMaps, my textures are named with the full name of the occurrence + the suffix. all of them except one called ObjectSpace. Like this:

    upload_2023-7-10_10-5-19.png

    This seems like a bug perhaps, because if I omit the mapSuffix, they are just named genericly Diffuse, Normal etc. without using the occurence name too. I can work with by just submitting an empty string mapSuffix parameter.

    Best regards

    - Björn
     
  6. bjornsyse

    bjornsyse

    Joined:
    Mar 28, 2017
    Posts:
    92
    ...Also managed to get a nicer lineup using replaceMap=True as paramter for algo.convertNormalMap.

    upload_2023-7-10_10-33-24.png

    All good now!
     
    laurent-milon likes this.