本文整理汇总了Python中MT.createNode方法的典型用法代码示例。如果您正苦于以下问题:Python MT.createNode方法的具体用法?Python MT.createNode怎么用?Python MT.createNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MT
的用法示例。
在下文中一共展示了MT.createNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testStringCache
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testStringCache():
value1 = "!1+"
value2 = "+2+"
value3 = "+3!"
add = MT.createNode("Math.Add")
valuenode = MT.createNode("Values.String Value")
valuenode2 = MT.createNode("Values.String Value")
valuenode.insockets[0].value = value1
valuenode2.insockets[0].value = value2
print("setting the input of valuenode to %s" % value1)
MT.project.root.addNode(add)
MT.project.root.addNode(valuenode)
MT.project.root.addNode(valuenode2)
pos = valuenode.pos
valuenode.pos = (pos[0] - 150, pos[1] - 50)
valuenode2.pos = (pos[0] - 150, pos[1] + 50)
add.insockets[0].connected = valuenode.outsockets[0]
add.insockets[1].connected = valuenode2.outsockets[0]
add.insockets[2].value = value3
cache = MT.cache.DataCache(add.outsockets[0])
print("resulting value: %s" % cache.getOutput())
print("expected value: %s" % value1 + value2 + value3)
return (value1 + value2 + value3) == cache.getOutput()
示例2: __init__
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def __init__(self, node, raw=False):
super().__init__(node, raw)
if raw:
return
data = MT.createNode(self.datanode)
obj = MT.createNode("Objects.Object")
node.graph.addNode(data)
node.graph.addNode(obj)
obj.insockets[0].connected = node.graph[0].outsockets[-1]
obj.insockets[1].connected = node.graph[0].outsockets[-1]
obj.insockets[2].connected = data.outsockets[0]
obj.insockets[3].connected = node.graph[0].outsockets[-1]
for s in data.insockets:
default = s.value
s.connected = node.graph[0].outsockets[-1]
node.insockets[-1].value = default
node.graph[1].insockets[0].connected = obj.outsockets[0]
node.graph[2].pos = (-70, 80)
node.graph[3].pos = (70, 80)
node.graph[1].pos = (70, 160)
示例3: testSimulation
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testSimulation():
simNode = MT.createNode("General.Simulation")
add = MT.createNode("Math.Add")
startValue = MT.createNode("Values.Int Value")
MT.project.root.addNode(simNode)
MT.project.root.addNode(startValue)
simNode.graph.addNode(add)
innode = simNode.graph[1]
outnode = simNode.graph[2]
test = TestCase()
test.equal(len(simNode.graph[2].insockets), 0, "Amount of outputs before connection")
add.insockets[0].connected = innode.outsockets[0]
test.equal(len(simNode.graph[2].insockets), 1, "Amount of outputs after connection")
simNode.insockets[1].connected = startValue.outsockets[0]
add.insockets[1].value = 1
startValue.insockets[0].value = 0
outnode.insockets[0].connected = add.outsockets[0]
test.equal(simNode.insockets[1].type, "INTEGER")
test.equal(innode.outsockets[0].type, "INTEGER")
test.equal(add.insockets[0].type, "INTEGER")
test.equal(add.outsockets[0].type, "INTEGER")
test.equal(outnode.insockets[0].type, "INTEGER", "outnode")
test.equal(simNode.outsockets[0].type, "INTEGER", "simnode output")
simNode.insockets[0].value = 1
cache = MT.cache.DataCache(simNode.outsockets[0])
test.equal(cache.getOutput(), 1, "Simulation Step: 1")
simNode.insockets[0].value = 2
MT.cache.DataCache.invalidate(simNode)
cache = MT.cache.DataCache(simNode.outsockets[0])
test.equal(cache.getOutput(), 2, "Simulation Step: 2")
simNode.insockets[0].value = 3
MT.cache.DataCache.invalidate(simNode)
cache = MT.cache.DataCache(simNode.outsockets[0])
test.equal(cache.getOutput(), 3, "Simulation Step: 3")
simNode.insockets[0].value = 4
MT.cache.DataCache.invalidate(simNode)
cache = MT.cache.DataCache(simNode.outsockets[0])
test.equal(cache.getOutput(), 4, "Simulation Step: 4")
simNode.insockets[0].value = 5
MT.cache.DataCache.invalidate(simNode)
cache = MT.cache.DataCache(simNode.outsockets[0])
test.equal(cache.getOutput(), 5, "Simulation Step: 5")
return test.exit()
示例4: testInheritSocketTypeMath
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testInheritSocketTypeMath():
add = MT.createNode("Math.Add")
flnode = MT.createNode("Values.Float Value")
add.insockets[0].connected = flnode.outsockets[0]
test = TestCase()
test.equal(add.insockets[0].type, flnode.outsockets[0].type, "connected")
test.equal(add.insockets[0].type, add.outsockets[0].type, "in to out")
return test.exit()
示例5: testNewProject
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testNewProject():
node = MT.createNode("Math.Add")
node1 = MT.createNode("Values.Float Value")
node2 = MT.createNode("Values.Int Value")
MT.project.root.addNode(node)
MT.project.root.addNode(node1)
MT.project.root.addNode(node2)
MT.newProject()
return len(MT.project.root) == 0
示例6: testSwitchNode
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testSwitchNode():
value1 = MT.createNode("Values.Float Value")
value2 = MT.createNode("Values.Float Value")
value3 = MT.createNode("Values.Float Value")
value1.insockets[0].value = 1
value2.insockets[0].value = 3
value3.insockets[0].value = 6
switch = MT.createNode("General.Switch")
MT.project.root.addNode(value1)
MT.project.root.addNode(value2)
MT.project.root.addNode(value3)
MT.project.root.addNode(switch)
# find array converter ... this is still kinda ugly
array = None
for child in switch.insockets[1].childNodes:
if child.name == "ArrayNode":
array = child
break
print(array.type)
print(dir(array))
array.insockets[0].connected = value1.outsockets[0]
array.insockets[1].connected = value2.outsockets[0]
array.insockets[2].connected = value3.outsockets[0]
switch.insockets[1].connected = array.outsockets[0]
test = TestCase()
print("Test1:")
switch.insockets[0].value = 0
cache = MT.cache.DataCache(switch.outsockets[0])
test.equal(cache.getOutput(), value1.insockets[0].value)
print("Test2:")
switch.insockets[0].value = 1
MT.cache.DataCache.invalidate(switch)
cache = MT.cache.DataCache(switch.outsockets[0])
test.equal(cache.getOutput(), value2.insockets[0].value)
print("Test3:")
switch.insockets[0].value = 2
MT.cache.DataCache.invalidate(switch)
cache = MT.cache.DataCache(switch.outsockets[0])
test.equal(cache.getOutput(), value3.insockets[0].value)
return test.exit()
示例7: testConnectSockets
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testConnectSockets():
add = MT.createNode("Math.Add")
add2 = MT.createNode("Math.Add")
MT.project.root.addNode(add)
MT.project.root.addNode(add2)
add.insockets[0].connected = add2.outsockets[0]
test = TestCase()
test.equal(add.insockets[0].connected.ptr, add2.outsockets[0].ptr)
return test.exit();
示例8: testSaveProject
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testSaveProject():
node = MT.createNode("Math.Add")
node1 = MT.createNode("Values.Float Value")
node2 = MT.createNode("Values.Int Value")
MT.project.root.addNode(node)
MT.project.root.addNode(node1)
MT.project.root.addNode(node2)
now = datetime.datetime.now()
MT.project.filename = "projectTest" + now.strftime("%d%m%y%H%M%S") + ".mt"
MT.project.save()
return os.path.exists(MT.project.filename)
示例9: testTimeline
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testTimeline():
timelinenode = MT.createNode("Values.Frame")
floatnode = MT.createNode("Values.Float Value")
floatnode.insockets[0].connected = timelinenode.outsockets[0]
cache = MT.cache.DataCache(floatnode.outsockets[0])
print("initial frame value as {}: {}".format(cache.type, cache.getOutput()))
MT.timeline.setFrame(44)
MT.cache.DataCache.invalidate(timelinenode)
cache = MT.cache.DataCache(floatnode.outsockets[0])
print("new cached frame value as %s: %d" % (cache.type, cache.getOutput()))
print("new frame value: %d" % (MT.timeline.frame()))
return int(cache.getOutput()) == 44
示例10: testInheritSocketTypeContainer
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testInheritSocketTypeContainer():
test = TestCase()
container = MT.createNode("General.Container")
floatValue = MT.createNode("Values.Float Value")
intValue = MT.createNode("Values.Int Value")
MT.project.root.addNode(container)
container.graph.addNode(floatValue)
container.graph[1].insockets[0].connected = floatValue.outsockets[0]
intValue.insockets[0].connected = container.graph[0].outsockets[0]
test.equal(container.graph[1].insockets[0].type, "FLOAT")
test.equal(container.outsockets[0].type, "FLOAT")
test.equal(container.graph[0].outsockets[0].type, "INTEGER", "input sockets of container graph")
test.equal(container.insockets[0].type, "INTEGER", "input of container itself")
return test.exit()
示例11: testForLoopCache
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testForLoopCache():
test = TestCase()
loop = MT.createNode("General.For")
MT.project.root.addNode(loop)
loop.insockets[0].value = 0
loop.insockets[1].value = 10
loop.insockets[2].value = 1
add = MT.createNode("Math.Add")
loop.graph.addNode(add)
test.equal(len(loop.graph[2].insockets), 0, "outsockets of loop container before (direct) connection")
test.equal(len(loop.graph[1].outsockets), 1, "looped insockets node has too many sockets")
loopsocket = loop.graph[1].outsockets[0]
add.insockets[0].connected = loopsocket
test.equal(len(loop.graph[2].insockets), 1, "outsockets of loop container before (indirect) connection")
add.insockets[1].value = 1
loop.graph[2].insockets[0].connected = add.outsockets[0]
loop.insockets[3].value = 1
test.equal(add.outsockets[0].type, "INTEGER", "output of Add")
test.equal(add.insockets[0].type, "INTEGER", "1st input of Add")
test.equal(add.insockets[1].type, "INTEGER", "2nd input of Add")
test.equal(loop.outsockets[0].type, "INTEGER", "output of ForNode")
test.equal(loop.insockets[3].type, "INTEGER", "input of startvalue into ForLoop")
test.equal(loop.graph[1].outsockets[0].type, "INTEGER", "input of ForLoop Container")
test.equal(loop.graph[2].insockets[0].type, "INTEGER", "output of ForLoop Container")
test.equal(len(loop.graph), 4, "nodes inside loop container")
test.equal(len(loop.graph[0].outsockets), 4, "static loop inputs")
test.equal(len(loop.graph[1].outsockets), 2, "looped inputs")
if not test.equal(len(loop.graph[2].insockets), 1, "loop outputs"):
print("the sockets on this node: {}".format([s.name for s in loop.graph[2].insockets]))
test.equal(len(loop.outsockets), 1, "number of outsockes on forloop node")
test.equal(len(loop.insockets), 4, "number of insockets on forloop node")
cache = MT.cache.DataCache(loop.outsockets[0])
expected_result = 11
test.equal(cache.getOutput(), expected_result, "Loop Result")
return test.exit()
示例12: dropEvent
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def dropEvent(self, event):
nodeLabel = str(event.mimeData().text())
event.mimeData().setText("")
self.drop = False
if nodeLabel == "":
return
_node = MT.createNode(nodeLabel)
if _node is not None:
self.scene().space.addNode(_node)
scenePos = self.mapToScene(event.pos())
nw = NodeDesigner.width
nh = NodeDesigner.height
_node.pos = (scenePos.x() - nw/2, scenePos.y() - nh/2)
#link it
#find sockets this corresponds to
insocket = None
for socket in self.start.data.insockets:
if (socket.connected is not None
and socket.connected.node.ptr == self.end.data.ptr):
insocket = socket
break
out = insocket.connected
#find new matching insocket and link
insockets = MT.getCompatibleSockets(out, node_)
if len(insockets) == 1:
insockets[0].connected = out
else:
menu = QMenu()
for socket in insockets:
action = menu.addAction(socket.name)
def connect():
socket.connected = out
action.triggered.connect(connect)
menu.exec_(event.screenPos())
outsockets = list(filter(lambda o: MT.isCompatible(insocket, o), _node.outsockets))
if len(outsockets) == 1:
insocket.connected = outsockets[0]
else:
menu = QMenu()
for socket in outsockets:
action = menu.addAction(socket.name)
def connect():
insocket.connected = socket
action.triggered.connect(connect)
menu.exec_(event.screenPos())
示例13: testFloatCache
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testFloatCache():
"""Creating two add nodes, connecting them and trying to get a value from it"""
add = MT.createNode("Math.Add")
valuenode = MT.createNode("Values.Float Value")
valuenode2 = MT.createNode("Values.Float Value")
add.insockets[0].name = "add.in01"
valuenode.insockets[0].name = "valuenode.in01"
valuenode.insockets[0].value = 5.0
valuenode2.insockets[0].name = "valuenode2.in01"
valuenode2.insockets[0].value = 8.0
MT.project.root.addNode(add)
MT.project.root.addNode(valuenode)
MT.project.root.addNode(valuenode2)
pos = valuenode.pos
valuenode.pos = (pos[0] - 150, pos[1] - 50)
valuenode2.pos = (pos[0] - 150, pos[1] + 50)
add.insockets[0].connected = valuenode.outsockets[0]
add.insockets[1].connected = valuenode2.outsockets[0]
add.insockets[2].value = 12.0
cache = MT.cache.DataCache(add.outsockets[0])
test = TestCase()
test.equal(len(MT.project.root), 3, "root space size")
test.equal(len(MT.project.root[0].outsockets), 1, "add outsockets")
test.equal(len(MT.project.root[0].insockets), 3, "add insockets")
test.equal(len(MT.project.root[1].outsockets), 1, "float value 1 outsockets")
test.equal(len(MT.project.root[1].insockets), 1, "float value 1 insockets")
test.equal(len(MT.project.root[2].outsockets), 1, "float value 2 outsockets")
test.equal(len(MT.project.root[2].insockets), 1, "float value 2 insockets")
test.equal(MT.project.root[1].insockets[0].value, 5.0, "float value 1")
test.equal(MT.project.root[2].insockets[0].value, 8.0, "float value 2")
test.equal(MT.project.root[0].insockets[2].value, 12.0, "add input value")
print("resulting value: %d" % cache.getOutput())
print("expected value: %d" % (12 + 5 + 8))
test.equal((12 + 5 + 8), cache.getOutput(), "cache output")
return test.exit()
示例14: testForeachLoopCache
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testForeachLoopCache():
loop = MT.createNode("General.Foreach")
listNode = MT.createNode("General.Create List")
add = MT.createNode("Math.Add")
value = MT.createNode("Values.Int Value")
listNode.insockets[0].value = 12.5
listNode.insockets[1].value = 10
value.insockets[0].value = 2
loop.insockets[0].connected = listNode.outsockets[0]
test = TestCase()
loopInputNode = loop.graph[1]
test.equal(listNode.insockets[0].type, "FLOAT")
test.equal(listNode.outsockets[0].type, "LIST:FLOAT")
test.equal(len(loopInputNode.outsockets), 1, "inputs to the foreach node")
add.insockets[0].connected = loopInputNode.outsockets[0]
add.insockets[1].connected = value.outsockets[0]
loop.graph[2].insockets[0].connected = add.outsockets[0]
MT.project.root.addNode(loop)
MT.project.root.addNode(listNode)
loop.graph.addNode(add)
loop.graph.addNode(value)
cache = MT.cache.DataCache(loop.outsockets[0])
output = cache.getOutput()
test.equal(add.insockets[0].type, "FLOAT")
test.equal(add.insockets[1].type, "INTEGER")
test.equal(loop.graph[1].outsockets[0].type, "FLOAT")
test.equal(len(output), 10)
test.equal(cache.getOutput(), [14.5] * 10)
return test.exit()
示例15: testSocketProperties
# 需要导入模块: import MT [as 别名]
# 或者: from MT import createNode [as 别名]
def testSocketProperties():
value = MT.createNode("Values.Float Value")
value.insockets[0].value = 2.5
cache = MT.cache.DataCache(value.outsockets[0])
success = cache.getData(0) == 2.5
value = MT.createNode("Values.Int Value")
value.insockets[0].value = 2
cache = MT.cache.DataCache(value.outsockets[0])
success = success and cache.getData(0) == 2
value = MT.createNode("Values.Color Value")
value.insockets[0].value = (1, 0, 0, 1)
cache = MT.cache.DataCache(value.outsockets[0])
success = success and cache.getData(0) == (1, 0, 0, 1)
value = MT.createNode("Values.String Value")
value.insockets[0].value = "bla bla HUBSGHDJ"
cache = MT.cache.DataCache(value.outsockets[0])
success = success and cache.getData(0) == "bla bla HUBSGHDJ"
return success