<div dir="ltr"><div dir="ltr"><div dir="ltr">I'm trying to add a LineSet in X_ITE with JavaScript, but it's not showing up:<div><br></div><div>const addLinkTransform = function(link, sourceNode, targetNode) {<br> const shape = Browser.currentScene.createNode('Shape');<br> const appearance = Browser.currentScene.createNode('Appearance');<br> const material = Browser.currentScene.createNode('Material');<br> const linkTransform = Browser.currentScene.createNode('Transform'); Browser.currentScene.addNamedNode('trans'+link, linkTransform);<br><br> material.diffuseColor = new SFColor(0.0, 0.0, 1.0);<br> material.emissiveColor = new SFColor(0.0, 0.0, 1.0);<br> appearance.material = material;<br> const lineSet = Browser.currentScene.createNode('LineSet');<br> const coordinate = Browser.currentScene.createNode('Coordinate');<br> if (coordinate && typeof sourceNode.x !== 'undefined') {<br> coordinate.point = new MFVec3f(<br> new SFVec3f(sourceNode.x, sourceNode.y, sourceNode.z),<br> new SFVec3f(targetNode.x, targetNode.y, targetNode.z));<br> }<br> lineSet.vertexCount = 2;<br> Browser.currentScene.addNamedNode('point'+link, coordinate);<br> lineSet.coord = coordinate;<br> shape.appearance = appearance;<br> shape.geometry = lineSet;<br> addChild(linkTransform, shape);<br> return linkTransform;<br>}<br><br>const addChild = function(node, value) {<br> node.children.push(value);<br>}</div><div><br></div><div>Then my main code:</div><div><br></div><div><br></div><div> const sourceNode = nodes.find(n => <a href="http://n.id" target="_blank">n.id</a> === command[3]);<br> const targetNode = nodes.find(n => <a href="http://n.id" target="_blank">n.id</a> === command[4]);<br> let sql = command[2];<br> let link = command[3]+command[4];<br> if (sourceNode && targetNode) {<br> let linkGroup = Browser.currentScene.getNamedNode('linkGroup');<br> let linkTransform = null;<br> try {<br> linkTransform = Browser.currentScene.getNamedNode('trans'+link);<br> } catch (e) {<br> }<br> if (linkTransform === null) {<br> linkTransform = addLinkTransform(link, sourceNode, targetNode);<br> if (linkTransform !== null && !linksShapes[`${sourceNode.id}-${targetNode.id}-${link}`]) {<br> linksShapes[`${sourceNode.id}-${targetNode.id}-${link}`] = linkTransform;<br> if (linkGroup !== null) {<br> addChild(linkGroup, linkTransform);<br> LOG("SUCCESSFUL LINK", link, sourceNode.id, targetNode.id);<br> } else {<br> LOG("FATAL LINK", link);<br> }<br> }<br> }<br> if (sql === 'UPDATE') {<br> let coordinate = Browser.currentScene.getNamedNode('point'+link);<br> if (coordinate) {<br> if (typeof sourceNode.x !== 'undefined') {<br> coordinate.point = new MFVec3f(<br> new SFVec3f(sourceNode.x, sourceNode.y, sourceNode.z),<br> new SFVec3f(targetNode.x, targetNode.y, targetNode.z));<br> // LOG("SUCCESSFUL COORDINATE", link, coordinate.point);<br> } else {<br> LOG("FATAL COORDINATE", link, `${sourceNode.id} ${sourceNode.x} ${sourceNode.y} ${sourceNode.z}, ${targetNode.id} ${targetNode.x} ${targetNode.y} ${targetNode.z}`);<br> }<br><br> } else {<br> LOG("COULDN'T FIND COORDINATE", link)<br> }<br><br> }</div><div><br></div><div><br></div><div>Note that the JavaScript is referenced from a Script node in a ProtoBody,and the linkGroup node is there as well. What I'll probably do is create a very simple example soon.</div></div>
</div>
</div>