[x3d-public] Adding LineSets in SAI, X_ITE

John Carlson yottzumm at gmail.com
Sun Mar 30 22:24:30 PDT 2025


I'm trying to add a LineSet in X_ITE with JavaScript, but it's not
showing up:

const addLinkTransform = function(link, sourceNode, targetNode) {
        const shape = Browser.currentScene.createNode('Shape');
        const appearance = Browser.currentScene.createNode('Appearance');
        const material = Browser.currentScene.createNode('Material');
        const linkTransform =
Browser.currentScene.createNode('Transform');
            Browser.currentScene.addNamedNode('trans'+link, linkTransform);

        material.diffuseColor = new SFColor(0.0, 0.0, 1.0);
        material.emissiveColor = new SFColor(0.0, 0.0, 1.0);
        appearance.material = material;
        const lineSet = Browser.currentScene.createNode('LineSet');
        const coordinate = Browser.currentScene.createNode('Coordinate');
        if (coordinate && typeof sourceNode.x !== 'undefined') {
                coordinate.point = new MFVec3f(
                        new SFVec3f(sourceNode.x, sourceNode.y,
sourceNode.z),
                        new SFVec3f(targetNode.x, targetNode.y,
targetNode.z));
        }
        lineSet.vertexCount = 2;
        Browser.currentScene.addNamedNode('point'+link, coordinate);
        lineSet.coord = coordinate;
        shape.appearance = appearance;
        shape.geometry = lineSet;
        addChild(linkTransform, shape);
        return linkTransform;
}

const addChild = function(node, value) {
        node.children.push(value);
}

Then my main code:


                const sourceNode = nodes.find(n => n.id === command[3]);
                const targetNode = nodes.find(n => n.id === command[4]);
                let sql = command[2];
                let link = command[3]+command[4];
                if (sourceNode && targetNode) {
                  let linkGroup =
Browser.currentScene.getNamedNode('linkGroup');
                  let linkTransform = null;
                  try {
                        linkTransform =
Browser.currentScene.getNamedNode('trans'+link);
                  } catch (e) {
                  }
                  if (linkTransform === null) {
                        linkTransform = addLinkTransform(link, sourceNode,
targetNode);
                        if (linkTransform !== null &&
!linksShapes[`${sourceNode.id}-${targetNode.id}-${link}`]) {

linksShapes[`${sourceNode.id}-${targetNode.id}-${link}`] = linkTransform;
                                  if (linkGroup !== null) {
                                        addChild(linkGroup, linkTransform);
                                        LOG("SUCCESSFUL LINK", link,
sourceNode.id, targetNode.id);
                                  } else {
                                        LOG("FATAL LINK", link);
                                  }
                        }
                  }
                  if (sql === 'UPDATE') {
                          let coordinate =
Browser.currentScene.getNamedNode('point'+link);
                          if (coordinate) {
                                  if (typeof sourceNode.x !== 'undefined') {
                                        coordinate.point = new MFVec3f(
                                                        new
SFVec3f(sourceNode.x, sourceNode.y, sourceNode.z),
                                                        new
SFVec3f(targetNode.x, targetNode.y, targetNode.z));
                                        // LOG("SUCCESSFUL COORDINATE",
link, coordinate.point);
                                  } else {
                                        LOG("FATAL COORDINATE", link,
`${sourceNode.id} ${sourceNode.x} ${sourceNode.y} ${sourceNode.z},
${targetNode.id} ${targetNode.x} ${targetNode.y} ${targetNode.z}`);
                                  }

                          } else {
                                LOG("COULDN'T FIND COORDINATE", link)
                          }

                  }


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20250331/7ff5fd43/attachment.html>


More information about the x3d-public mailing list