Skip to content

Commit

Permalink
fixing materials issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nortikin committed Apr 24, 2018
1 parent d80ca65 commit 31317be
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 58 deletions.
119 changes: 75 additions & 44 deletions json_examples/ParametricModelling/insolation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"export_version": "0.072",
"framed_nodes": {
"Circle": "Frame.003",
"Frame.002": "Frame.003",
"Frame.004": "Frame.003",
"List Match": "Frame.003",
"Note": "Frame.003",
"Object ID Insolation": "Frame.004",
"Objects in mk3": "Frame.001",
"Objects in mk3.001": "Frame.001",
"Reroute": "Frame.002",
"Reroute.002": "Frame.002",
"Reroute.008": "Frame.002",
Expand All @@ -12,7 +18,8 @@
"Vector X/Y/Z": "Frame.003",
"Vector X/Y/Z.001": "Frame.003",
"Vector in": "Frame.003",
"Viewer Draw": "Frame.003"
"Viewer Draw": "Frame.003",
"Viewer Index": "Frame.003"
},
"groups": {},
"nodes": {
Expand Down Expand Up @@ -57,37 +64,61 @@
"use_custom_color": true,
"width": 800.0
},
"Frame.001": {
"bl_idname": "NodeFrame",
"height": 694.6670532226562,
"hide": false,
"label": "from scene",
"location": [
109.05883026123047,
66.97383880615234
],
"params": {},
"width": 203.75582885742188
},
"Frame.002": {
"bl_idname": "NodeFrame",
"height": 186.91839599609375,
"height": 212.9017333984375,
"hide": false,
"label": "data to insol",
"location": [
289.2660217285156,
647.1701049804688
79.26565551757812,
476.146728515625
],
"params": {},
"width": 140.32843017578125
"width": 77.29409790039062
},
"Frame.003": {
"bl_idname": "NodeFrame",
"height": 400.14434814453125,
"height": 595.2105712890625,
"hide": false,
"label": "rays",
"location": [
407.508056640625,
-619.734375
],
"params": {},
"width": 896.2562255859375
"width": 1077.5419921875
},
"Frame.004": {
"bl_idname": "NodeFrame",
"height": 192.54067993164062,
"hide": false,
"label": "insolation",
"location": [
1.4534912109375,
77.4736328125
],
"params": {},
"width": 200.35296630859375
},
"List Match": {
"bl_idname": "ListMatchNode",
"height": 100.0,
"hide": true,
"label": "",
"location": [
461.21144104003906,
461.21142578125,
-474.6988220214844
],
"params": {
Expand All @@ -106,12 +137,12 @@
"hide": false,
"label": "",
"location": [
-122.04351806640625,
198.80079650878906
-88.3455810546875,
-89.8482666015625
],
"params": {
"show_text": 0,
"text": "Nikitron 2018 - insolation test"
"text": "Nikitron 2018 - insolation test. victim's every polygon calculates. predator is simply shape"
},
"use_custom_color": true,
"width": 400.0
Expand All @@ -132,12 +163,12 @@
"hide": false,
"label": "",
"location": [
834.3430786132812,
40.188499450683594
594.4342651367188,
-132.51815795898438
],
"params": {
"mode": 0,
"sort_critical": 2
"sort_critical": 8
},
"width": 140.0
},
Expand All @@ -150,10 +181,10 @@
],
"height": 100.0,
"hide": false,
"label": "",
"label": "victim",
"location": [
247.8347625732422,
24.671173095703125
-345.22498321533203,
-424.64835357666016
],
"object_names": [
"victim"
Expand All @@ -171,10 +202,10 @@
],
"height": 100.0,
"hide": false,
"label": "",
"label": "predator",
"location": [
449.2581787109375,
197.5847930908203
-348.62784576416016,
-99.45061492919922
],
"object_names": [
"predator"
Expand All @@ -189,8 +220,8 @@
"hide": false,
"label": "predator",
"location": [
718.5639038085938,
-2.692626953125
508.56353759765625,
-173.71600341796875
],
"params": {},
"width": 16.0
Expand All @@ -201,8 +232,8 @@
"hide": false,
"label": "sun rays",
"location": [
718.5639038085938,
-79.7427978515625
508.56353759765625,
-250.76617431640625
],
"params": {},
"width": 16.0
Expand All @@ -218,8 +249,8 @@
"hide": false,
"label": "victim",
"location": [
718.5639038085938,
-39.425048828125
508.56353759765625,
-210.44842529296875
],
"params": {},
"use_custom_color": true,
Expand All @@ -245,7 +276,7 @@
"hide": false,
"label": "",
"location": [
282.40882110595703,
282.4088134765625,
-306.5486145019531
],
"params": {
Expand All @@ -259,7 +290,7 @@
"hide": true,
"label": "",
"location": [
459.2382049560547,
459.23822021484375,
-531.6445922851562
],
"params": {
Expand Down Expand Up @@ -305,7 +336,7 @@
"hide": false,
"label": "",
"location": [
300.18038177490234,
300.1803894042969,
-485.6902160644531
],
"params": {},
Expand All @@ -322,7 +353,7 @@
"hide": false,
"label": "",
"location": [
587.5731658935547,
587.5731811523438,
-306.4921875
],
"params": {
Expand Down Expand Up @@ -358,8 +389,8 @@
"hide": false,
"label": "",
"location": [
838.7593994140625,
-114.1307373046875
768.8589477539062,
-131.31939697265625
],
"params": {
"activate": 1,
Expand Down Expand Up @@ -407,6 +438,18 @@
"Reroute.002",
"Input"
],
[
"Rotation.001",
0,
"List Match",
0
],
[
"Vector in",
0,
"List Match",
1
],
[
"Objects in mk3",
"Object",
Expand Down Expand Up @@ -449,18 +492,6 @@
"Viewer Index",
4
],
[
"Rotation.001",
0,
"List Match",
0
],
[
"Vector in",
0,
"List Match",
1
],
[
"List Match",
0,
Expand Down
38 changes: 24 additions & 14 deletions nodes/analyzer/object_insolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,29 @@ def colset(rec,OutS_):
colors[co].color = OutS[0][i]
colset(rec,OutS_)
def matset(rec):
if len(rec.material_slots):
trem = rec.material_slots[0].material.node_tree
matnodes = trem.nodes
if not 'Attribute' in matnodes:
att = matnodes.new('ShaderNodeAttribute')
else:
att = matnodes['Attribute']
if not 'Diffuse BSDF' in matnodes:
dif = matnodes.new('ShaderNodeBsdfDiffuse')
else:
dif = matnodes['Diffuse BSDF']
att.attribute_name = 'SvInsol'
trem.links.new(dif.inputs[0],att.outputs[0])
# add new material with nodes
ms = rec.material_slots
if not 'svmat' in bpy.data.materials:
manew = bpy.data.materials.new('svmat')
manew.use_nodes = True
if not len(ms):
# append if no slots
rec.data.materials.append(manew)
if not ms[-1].material:
# assign if no material in slot
ms[-1].material = manew
trem = ms[-1].material.node_tree
matnodes = trem.nodes
if not 'Attribute' in matnodes:
att = matnodes.new('ShaderNodeAttribute')
else:
att = matnodes['Attribute']
if not 'Diffuse BSDF' in matnodes:
dif = matnodes.new('ShaderNodeBsdfDiffuse')
else:
dif = matnodes['Diffuse BSDF']
att.attribute_name = 'SvInsol'
trem.links.new(dif.inputs[0],att.outputs[0])
matset(rec)
if H.is_linked:
OutH = []
Expand Down Expand Up @@ -207,4 +217,4 @@ def unregister():
bpy.utils.unregister_class(SvOBJInsolationNode)

if __name__ == '__main__':
register()
register()

0 comments on commit 31317be

Please sign in to comment.