Advertisement
metalx1000

Convert image to Blender Python Code

Jan 28th, 2024
1,452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.67 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2024  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation version 3 of the License.
  9.  
  10. #This program is distributed in the hope that it will be useful,
  11. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #GNU General Public License for more details.
  14.  
  15. #You should have received a copy of the GNU General Public License
  16. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. ######################################################################
  18.  
  19. [[ $1 ]] || exit
  20. [[ -f "$1" ]] || exit
  21.  
  22. convert "$1" text:- |grep -v '^#'|awk '{print $1,$4}'|sed 's/: srgba(/,/g'|tr -d ')'|while read line
  23. do
  24.   line="$(echo $line|sed 's/: black/,0,0,0,1/g')"
  25.   pos="$(echo $line|cut -d\, -f1,2)"
  26.   if [[ "$line" != *"none"* ]]
  27.   then
  28.   r="$(echo $line|cut -d\, -f3)"
  29.   r="$(echo "scale=6; $r/255"| bc -l)"
  30.   g="$(echo $line|cut -d\, -f4)"
  31.   g="$(echo "scale=6; $g/255"| bc -l)"
  32.   b="$(echo $line|cut -d\, -f5)"
  33.   b="$(echo "scale=6; $b/255"| bc -l)"
  34.   color="$r,$g,$b"
  35.   name="Material.$RANDOM.$RANDOM"
  36.     echo "
  37. bpy.ops.mesh.primitive_cube_add(enter_editmode=False, align='WORLD', location=($pos, 0), scale=(.5, .5, .5))
  38. mat = bpy.data.materials.new('$name')
  39. mat.use_nodes = True
  40. bpy.data.materials['$name'].node_tree.nodes['Principled BSDF'].inputs[0].default_value = ($color, 1)
  41. bpy.context.object.active_material = mat"
  42.  
  43.   fi
  44.  
  45. done
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement