Comments (2)
Could be tricky. Those lists are hard to access. I'll see what I can do.
from blendernormalgroups.
Recently I took this script and modified it for my personal needs and with it I added the UV preservation. Keep in mind I am not an expert programmer and I made it so it uses my GroupNode I have in the .blend files already created just so it doesn't create a new one. That GroupNode is basically what you have but instead of having a UV node in itself, it take it from Group Input. I made it few days back so I don't even remember what exactly I added or removed in the script but I think I modified mainly the get_custom and set_custom. Anyway I am just gonna paste here the whole Operator Class in case you might want to get inspired by it or something.
class GOT_OT_OptimizedNormalMaps(Operator):
bl_idname = 'got.optimizednormalmaps'
bl_label = "Normal Map nodes to Custom"
bl_options = {'UNDO'}
bl_description = "Switch normal map nodes to a faster custom node"
@classmethod
def poll(self, context):
return (bpy.data.materials or bpy.data.node_groups)
def execute(self, context):
def mirror(new, old):
# Copy attributes of the old node to the new node
new.parent = old.parent
new.label = old.label
new.mute = old.mute
new.hide = old.hide
new.select = old.select
new.location = old.location
# Inputs
for (name, point) in old.inputs.items():
input = new.inputs.get(name)
if input:
input.default_value = point.default_value
for link in point.links:
new.id_data.links.new(link.from_socket, input)
# Outputs
for (name, point) in old.outputs.items():
output = new.outputs.get(name)
if output:
output.default_value = point.default_value
for link in point.links:
new.id_data.links.new(output, link.to_socket)
def get_custom():
name = 'Normal Map Optimized'
group = bpy.data.node_groups.get(name)
return group
def set_custom(nodes):
group = get_custom()
if not group:
return
for node in nodes:
new = None
toGroup = False
if self.custom:# Setting up the GROUP NormalMap GroupNode
if isinstance(node, bpy.types.ShaderNodeNormalMap):
toGroup = True
new = nodes.new(type='ShaderNodeGroup')
new.node_tree = group
else:# Setting up the NORMAL NormalMap Node
if isinstance(node, bpy.types.ShaderNodeGroup):
if node.node_tree == group:
new = nodes.new(type='ShaderNodeNormalMap')
if new:
name = node.name
mirror(new, node)
if toGroup:# Setting up the GROUP NormalMap GroupNode
uvNode = nodes.new('ShaderNodeUVMap')
uvNode.uv_map = node.uv_map
uvNode.name = node.name+" -UV-"
uvNode.label = ''
uvNode.parent = new.parent
uvNode.label = node.label+" -UV-"
uvNode.mute = new.mute
uvNode.hide = new.hide
uvNode.select = new.select
uvNode.color = Color((0.6079999804496765, 0.6079999804496765, 0.6079999804496765))
uvNode.location = Vector((new.location.x-216.0011, new.location.y-9.06744))
uvNode.id_data.links.new(uvNode.outputs['UV'], new.inputs[0])
else:# Setting up the NORMAL NormalMap Node
uvNode = nodes[node.name+" -UV-"]
new.uv_map = uvNode.uv_map
nodes.remove(uvNode)
nodes.remove(node)
new.name = name
for mat in bpy.data.materials:
set_custom(getattr(mat.node_tree, 'nodes', []))
for group in bpy.data.node_groups:
set_custom(group.nodes)
# Finish
return {'FINISHED'}
custom: bpy.props.BoolProperty(
name="To Custom",
description="Set all normals to custom group, or revert back to normal",
default=True,
)
from blendernormalgroups.
Related Issues (16)
- Not Compatible with Blender 2.83
- Can we create a backport branch of this for 2.79x? HOT 2
- Not working for Blender 2.93 HOT 1
- Install Not Working HOT 3
- Custom normal map node can't be made correctly on blender 3.2 HOT 3
- This is not an issue but you should read this!
- Hey man I made a tutorial about your awesome add-on!!!!
- I'm talking with the makers of 2 major blender addons about using your normal maps in their code is this possible .... HOT 2
- ... you talked about shouting out your friends and you if I add the code to my add on
- think I figured out a way to thank you guys for letting me use your code in my add on preferences Can you look this over
- downloaded the addon but can't see it on the addon list and its not in the shading tab? HOT 1
- Blender 4.0 compatibility HOT 2
- Thank you so much for updating this to 4.0 HOT 3
- 3.6 errors HOT 5
- Using Blender 4.1 click custom and get error with your 4.0 and after release HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blendernormalgroups.