Advertisement
Lucas_3D

QuickCompleteBake.ms

May 16th, 2020
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. --macroscript QuickCompleteBake category:"LM Tools"
  2. (
  3. --capture selectect objects selection and filter for geometry only
  4. SelectedObjectsAll = deepcopy (selection as array)
  5. SelectedObjects =#()
  6. for a in SelectedObjectsAll do
  7. (
  8. if (superclassof a == GeometryClass) then (append SelectedObjects a)
  9. )
  10. --clear up the BTT list
  11. BakeToTexture.deleteAllMaps()
  12. BakeMaps = #()
  13. --get the project folder and set the destination folder for the Maps
  14. BakeToTexture.outputPath = pathConfig.getCurrentProjectFolder() + "\\sceneassets\\images"
  15. --Adds a compete map in 2048 x 2048 for all my selected objects and set it to map channel 2
  16. for a in SelectedObjects do
  17. (
  18. --if there is no UV channed 2, create one
  19. if (meshop.getMapSupport a.mesh 2) != true then
  20. (
  21. select a
  22. max modify mode
  23. NewModifier = Unwrap_UVW()
  24. addmodifier a NewModifier
  25. a.modifiers[1].setMapChannel 2
  26. a.modifiers[1].setApplyToWholeObject true
  27. a.modifiers[1].flattenMapNoParams()
  28. a.modifiers[1].pack 2 0.001 true true true
  29. subObjectLevel = 0
  30. deselect a
  31. )
  32. TheNewMap = BakeToTexture.addMap a #CompleteMap
  33. TheNewMap.imageWidth = 1024
  34. TheNewMap.imageHeight = 1024
  35. append BakeMaps TheNewMap
  36. )
  37. --Bakes the maps
  38. BakeToTexture.bake()
  39. -- moves the UVs from channel 2 to channel 1 so that the objects can use the complete map on channel 1
  40. for a in BakeMaps do
  41. (
  42. ChannelInfo.CopyChannel a.sceneObject 3 2
  43. ChannelInfo.PasteChannel a.sceneObject 3 1
  44.  
  45. a.sceneObject.material = Physical_Material()
  46. a.sceneObject.material.base_color_map = bitmaptexture()
  47. a.sceneObject.material.base_color_map.filename = (BakeToTexture.outputPath + "\\" + a.filename + "." + a.fileType) --fill in the gaps here
  48. -- Put the rendered images in the diffuse slot of all my materials
  49. )
  50. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement