loadSubtreeFromScsFile

When you load a model recursively with loadSubtreeFromScsFile, the view will always default to the first loaded model. Is there any way to load the model and base the view on the entire model

Hi,

the simplest way to achieve this would be to call fitWorld() after all models have been loaded:

await hwv.model.loadSubtreeFromScsFile(hwv.model.getRootNode(), "microengine.scs");
await hwv.model.loadSubtreeFromScsFile(hwv.model.getRootNode(), "arboleda.scs");
hwv.view.fitWorld();

However, this will cause the camera to jump from its initial position (centered on microengine in this case).

If you know the extends of the complete model in advance you can also set the camera (view.setCamera()) to an appropriate position before you load the models.

If you don’t know the extends of the complete model and want to still avoid the camera jump you can also suspend rendering until both models have been loaded:

 hwv.pauseRendering();
 await hwv.model.loadSubtreeFromScsFile(hwv.model.getRootNode(), "microengine.scs");
 await hwv.model.loadSubtreeFromScsFile(hwv.model.getRootNode(), "arboleda.scs");
 hwv.view.fitWorld();
 hwv.resumeRendering();

I hope this helps,
Guido

1 Like

Is it okay to load the recursive data as an xmlBuffer ?

1 Like

If the XML file contains bounding boxes for the individual models referenced, it should calculate the correct camera as the model is loaded. Does that not work for you? Can you provide an example?

1 Like

The back end sent me this JSON

{
  "ChildNodes": [
    {
      "BoundBoxMax": "85.17806683098136489 57.345001220703125 0",
      "BoundBoxMin": "-1.149999618530312517 -0.3449999988079071045 -90.31000083096411402",
      "ChildNodes": [
        {
          "BoundBoxMax": "21.95900726318359375 57.845001220703125 0.3099986016750335693",
          "BoundBoxMin": "-21.95900726318359375 0.1550000011920928955 -71",
          "ConvertFile": "housing .CATPart.scs",
          "Name": "HOUSING(HOUSING.1)",
          "NodeType": "NodePart",
          "SCNodeId": 2,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "1 0 -0 0 -0 1 0 0 0 0 1 0 21.5 -0.5 -0.3100000000000022737 1"
        },
        {
          "BoundBoxMax": "10.99954128265380859 3.469446951953614189e-15 10.99954128265380859",
          "BoundBoxMin": "-10.99954128265380859 -37 -10.99954128265380859",
          "ConvertFile": "cylinder liner.CATPart.scs",
          "Name": "CYLINDER LINER(CYLINDER LINER.1)",
          "NodeType": "NodePart",
          "SCNodeId": 3,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "1 3.673819061467132761e-16 -3.673819061467131775e-16 0 -3.673819061467131775e-16 6.123031769111885058e-17 -1 0 -3.673819061467132761e-16 1 6.123031769111898617e-17 0 21.49999999999995737 28.49999999999998579 -71.31000000000001648 1"
        },
        {
          "BoundBoxMax": "20 22.64999961853027344 22.64999961853027344",
          "BoundBoxMin": "-8.309640975312504452e-07 -22.64999961853027344 -22.64999961853027344",
          "ConvertFile": "housing top.CATPart.scs",
          "Name": "HOUSING TOP(HOUSING TOP.1)",
          "NodeType": "NodePart",
          "SCNodeId": 4,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "3.673819061467131775e-16 0 1 0 0 1 -0 0 -1 0 3.673819061467131775e-16 0 21.49999999999995381 28.49999999999998579 -90.31000000000001648 1"
        },
        {
          "BoundBoxMax": "109.7928009033204262 17.67969013306297654 43.92094570010613097",
          "BoundBoxMin": "37.19280090320562948 -11.81988407227195204 -2.135232031893236737",
          "ChildNodes": [
            {
              "BoundBoxMax": "2.5 6 6",
              "BoundBoxMin": "-2.5 -6 -34.5",
              "ConvertFile": "push rod.CATPart.scs",
              "Name": "PUSH ROD(PUSH ROD.1)",
              "NodeType": "NodePart",
              "SCNodeId": 20,
              "Unit": 0.0,
              "hasBoundBox": true,
              "hasExternalModel": true,
              "hasTransform": true,
              "transformation": "1 0 -0 0 -0 1 0 0 0 0 1 0 100.7928009033203125 2.896131133096254473 37.92094570010613097 1"
            },
            {
              "BoundBoxMax": "3.999833583831787109 2.5 3.999833583831787109",
              "BoundBoxMin": "-3.999833583831787109 -2.5 -3.999833583831787109",
              "ConvertFile": "bearing_pr_dw.CATPart.scs",
              "Name": "BEARING PR DW(BEARING PR DW.1)",
              "NodeType": "NodePart",
              "SCNodeId": 21,
              "Unit": 0.0,
              "hasBoundBox": true,
              "hasExternalModel": true,
              "hasTransform": true,
              "transformation": "1.224606353822377505e-16 -1 6.123031769111883826e-17 0 1 1.224606353822377505e-16 -6.123031769111888756e-17 0 6.123031769111887524e-17 6.123031769111885058e-17 1 0 100.7928009033203125 2.896131133096255361 37.92094570010613097 1"
            },
            {
              "BoundBoxMax": "2.999875068664550781 2.5 2.999875068664550781",
              "BoundBoxMin": "-2.999875068664550781 -2.5 -2.999875068664550781",
              "ConvertFile": "bearing_pr_up.CATPart.scs",
              "Name": "BEARING PR UP(BEARING PR UP.1)",
              "NodeType": "NodePart",
              "SCNodeId": 22,
              "Unit": 0.0,
              "hasBoundBox": true,
              "hasExternalModel": true,
              "hasTransform": true,
              "transformation": "1.224606353822377505e-16 -1 6.123031769111883826e-17 0 1 1.224606353822377505e-16 -6.123031769111888756e-17 0 6.123031769111887524e-17 6.123031769111885058e-17 1 0 100.7928009033203125 2.896131133096254473 7.920945700106130971 1"
            },
            {
              "BoundBoxMax": "2.249906301498413086 1.667991699622062285e-12 2.249906301498413086",
              "BoundBoxMin": "-2.249906301498413086 -17 -2.249906301498413086",
              "ConvertFile": "axe.CATPart.scs",
              "Name": "AXE(AXE.1)",
              "NodeType": "NodePart",
              "SCNodeId": 23,
              "Unit": 0.0,
              "hasBoundBox": true,
              "hasExternalModel": true,
              "hasTransform": true,
              "transformation": "1.224606353822377505e-16 -1 6.123031769111883826e-17 0 1 1.224606353822377505e-16 -6.123031769111888756e-17 0 6.123031769111887524e-17 6.123031769111885058e-17 1 0 109.2928009033203125 2.896131133096255361 7.920945700106129195 1"
            },
            {
              "BoundBoxMax": "9 10 9",
              "BoundBoxMin": "-9 -8 -9",
              "ConvertFile": "piston.CATPart.scs",
              "Name": "PISTON(PISTON.1)",
              "NodeType": "NodePart",
              "SCNodeId": 24,
              "Unit": 0.0,
              "hasBoundBox": true,
              "hasExternalModel": true,
              "hasTransform": true,
              "transformation": "1 1.228910067044771419e-16 -4.334177741936825138e-19 0 4.334177741935313283e-19 -0.007053606195465945972 -0.9999751230103869348 0 -1.228910067044770926e-16 0.9999751230103869348 -0.007053606195465945972 0 100.7928009033204262 2.89613113309626069 7.920945700106130971 1"
            },
            {
              "BoundBoxMax": "14.74938583374023438 1.146877731672546474e-10 14.74938583374023438",
              "BoundBoxMin": "-14.74938583374023438 -67.100006103515625 -14.74938583374023438",
              "ConvertFile": "crankshaft.CATPart.scs",
              "Name": "CRANKSHAFT(CRANKSHAFT.1)",
              "NodeType": "NodePart",
              "SCNodeId": 25,
              "Unit": 0.0,
              "hasBoundBox": true,
              "hasExternalModel": true,
              "hasTransform": true,
              "transformation": "6.145964927183175349e-17 -0.003752433033251414106 0.9999929595983818587 0 -1 -4.310860276468987055e-22 6.146008035785950414e-17 0 -2.301937527684902586e-19 -0.9999929595983818587 -0.003752433033251414106 0 37.19280090332031818 2.929903030395513142 28.92100906372069957 1"
            },
            {
              "BoundBoxMax": "7.999667167663574219 3.469446951953614189e-15 7.999667167663574219",
              "BoundBoxMin": "-7.999667167663574219 -44.79999923706054688 -8",
              "ConvertFile": "bearing CS.CATPart.scs",
              "Name": "BEARING CS(BEARING CS.1)",
              "NodeType": "NodePart",
              "SCNodeId": 26,
              "Unit": 0.0,
              "hasBoundBox": true,
              "hasExternalModel": true,
              "hasTransform": true,
              "transformation": "-6.003204849535802906e-17 0.9998121510377560028 0.01938201839996006939 0 -1 -6.004355054699419157e-17 1.15020516361280407e-20 0 1.17526509248843814e-18 -0.01938201839996006592 0.9998121510377557808 0 49.29280090332022723 2.92990303039551403 28.92100906372069602 1"
            }
          ],
          "ConvertFile": "",
          "Name": "MOBILE PART(MOBILE PART.1)",
          "NodeType": "NodeAssembly",
          "SCNodeId": 5,
          "hasBoundBox": true,
          "hasExternalModel": false,
          "hasTransform": true,
          "transformation": "-0.9999999999999995559 5.967448757360217391e-16 5.796494696965749659e-17 0 -5.963211686108819943e-16 -0.9999751230103874899 0.007053606195465958982 0 6.217270832887803231e-17 0.007053606195465958982 0.9999751230103874899 0 122.3708677341869873 31.22583273451727592 -48.94095597824595245 1"
        },
        {
          "BoundBoxMax": "11.40000057220458984 48.5 0",
          "BoundBoxMin": "-2.775557561562891351e-14 8.5 -40",
          "ConvertFile": "housing back.CATPart.scs",
          "Name": "HOUSING BACK(HOUSING BACK.1)",
          "NodeType": "NodePart",
          "SCNodeId": 6,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": false
        },
        {
          "BoundBoxMax": "41.09999847412109375 20 19.99916648864746094",
          "BoundBoxMin": "-1.90180390119627004e-15 -19.99916648864746094 -19.99916648864746094",
          "ConvertFile": "housing front.CATPart.scs",
          "Name": "HOUSING FRONT(HOUSING FRONT.1)",
          "NodeType": "NodePart",
          "SCNodeId": 7,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "1 -1.224606353822377258e-16 1.224606353822376272e-16 0 1.224606353822377505e-16 9.436895709313830594e-16 -1 0 1.224606353822376026e-16 1 9.436895709313830594e-16 0 31.59999999999999432 28.50000000000000711 -19.99999999999999289 1"
        },
        {
          "BoundBoxMax": "35 1.992075443267822266 1.992075443267822266",
          "BoundBoxMin": "-4 -1.992075443267822266 -1.992075443267822266",
          "ConvertFile": "screw back.CATPart.scs",
          "Name": "SCREW BACK(SCREW BACK.1)",
          "NodeType": "NodePart",
          "SCNodeId": 8,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "1 0 -0 0 -0 1 0 0 0 0 1 0 4.999999999999998224 40.99999999999999289 -7.499999999999985789 1"
        },
        {
          "BoundBoxMax": "35 1.992075443267822266 1.992075443267822266",
          "BoundBoxMin": "-4 -1.992075443267822266 -1.992075443267822266",
          "ConvertFile": "screw back.CATPart.scs",
          "Name": "SCREW BACK(SCREW BACK.2)",
          "NodeType": "NodePart",
          "SCNodeId": 9,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "1 0 -0 0 -0 1 0 0 0 0 1 0 5 15.99999999999999112 -7.49999999999999023 1"
        },
        {
          "BoundBoxMax": "35 1.992075443267822266 1.992075443267822266",
          "BoundBoxMin": "-4 -1.992075443267822266 -1.992075443267822266",
          "ConvertFile": "screw back.CATPart.scs",
          "Name": "SCREW BACK(SCREW BACK.3)",
          "NodeType": "NodePart",
          "SCNodeId": 10,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "1 0 -0 0 -0 1 0 0 0 0 1 0 4.999999999999998224 40.99999999999997868 -32.49999999999997868 1"
        },
        {
          "BoundBoxMax": "35 1.992075443267822266 1.992075443267822266",
          "BoundBoxMin": "-4 -1.992075443267822266 -1.992075443267822266",
          "ConvertFile": "screw back.CATPart.scs",
          "Name": "SCREW BACK(SCREW BACK.4)",
          "NodeType": "NodePart",
          "SCNodeId": 11,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "1 0 -0 0 -0 1 0 0 0 0 1 0 5 16 -32.5 1"
        },
        {
          "BoundBoxMax": "11 1.999916791915893555 1.999916791915893555",
          "BoundBoxMin": "-3.5 -1.999916791915893555 -1.999916791915893555",
          "ConvertFile": "screw top.CATPart.scs",
          "Name": "SCREW TOP(SCREW TOP.1)",
          "NodeType": "NodePart",
          "SCNodeId": 12,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "3.673819061467131775e-16 0 1 0 0 1 -0 0 -1 0 3.673819061467131775e-16 0 30.49999999999996447 19.49999999999998579 -75.31000000000001648 1"
        },
        {
          "BoundBoxMax": "11 1.999916791915893555 1.999916791915893555",
          "BoundBoxMin": "-3.5 -1.999916791915893555 -1.999916791915893555",
          "ConvertFile": "screw top.CATPart.scs",
          "Name": "SCREW TOP(SCREW TOP.2)",
          "NodeType": "NodePart",
          "SCNodeId": 13,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "3.673819061467131775e-16 0 1 0 0 1 -0 0 -1 0 3.673819061467131775e-16 0 30.49999999999996447 37.49999999999998579 -75.31000000000001648 1"
        },
        {
          "BoundBoxMax": "11 1.999916791915893555 1.999916791915893555",
          "BoundBoxMin": "-3.5 -1.999916791915893555 -1.999916791915893555",
          "ConvertFile": "screw top.CATPart.scs",
          "Name": "SCREW TOP(SCREW TOP.3)",
          "NodeType": "NodePart",
          "SCNodeId": 14,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "3.673819061467131775e-16 0 1 0 0 1 -0 0 -1 0 3.673819061467131775e-16 0 12.49999999999996447 19.49999999999998579 -75.31000000000000227 1"
        },
        {
          "BoundBoxMax": "11 1.999916791915893555 1.999916791915893555",
          "BoundBoxMin": "-3.5 -1.999916791915893555 -1.999916791915893555",
          "ConvertFile": "screw top.CATPart.scs",
          "Name": "SCREW TOP(SCREW TOP.4)",
          "NodeType": "NodePart",
          "SCNodeId": 15,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "3.673819061467131775e-16 0 1 0 0 1 -0 0 -1 0 3.673819061467131775e-16 0 12.49999999999996447 37.49999999999998579 -75.31000000000000227 1"
        },
        {
          "BoundBoxMax": "4.9136199951171875 19.20000076293945313 21.00900077819824219",
          "BoundBoxMin": "-4.9136199951171875 -22.94000053405761719 -9.991000175476074219",
          "ConvertFile": "carburetor.CATPart.scs",
          "Name": "CARBURETOR(CARBURETOR.1)",
          "NodeType": "NodePart",
          "SCNodeId": 16,
          "Unit": 0.0,
          "hasBoundBox": true,
          "hasExternalModel": true,
          "hasTransform": true,
          "transformation": "-0.9545378982843744087 -0.00561760026895690226 -0.2980366475889619782 0 0.005362296964962680844 -0.9999842211591232211 0.001674277169806927257 0 -0.298041350336003652 -9.278602192130944974e-16 0.9545529600236392076 0 44.57569385133714945 28.50000000000003553 -49.14356334905227186 1"
        }
      ],
      "ConvertFile": "",
      "Name": "Product1",
      "NodeType": "NodeAssembly",
      "SCNodeId": 1,
      "hasBoundBox": true,
      "hasExternalModel": false,
      "hasTransform": false
    }
  ],
  "ConvertFile": "",
  "LogFilePath": "D:\\dev_code\\Bin\\win64_bin\\SCConverter\\2021_SP2_U2\\log\\SCConverter2022_10_21_03_04_32_0c1af3af-a7bb-49cf-b752-54d64fab0a4b.log",
  "Name": "_micro engine",
  "NodeType": "NodeAssembly",
  "SCNodeId": 0,
  "hasBoundBox": false,
  "hasExternalModel": false,
  "hasTransform": false
}

I want to use it to generate xmlString to load the model, is that okay?

Yes, it looks like this has all the data you need to generate the XML. One important thing to note is that the bounding boxes in the XML should be in object space, meaning they are relative to the parent node, not absolute.

2 Likes