Advanced custom scripts

marc
Hi, I’m trying to create an advanced configurator with many dependencies. I decided to try custom script and I have a few questions. (I did not find an answer in the documentation). How to get information about the obj…

Comments

4 comments

  • Comment author
    marc

    Hi, I’m trying to create an advanced configurator with many dependencies. I decided to try custom script and I have a few questions. (I did not find an answer in the documentation).

    1. How to get information about the object. I use scene.find to get the id… but how do I get its transform?
    2. Is it possible to create/destroy a 3d object using a script?
    3. What does the custom script trigger? Is this any change to the form?
    4. I am using scene.set to make changes. Is this the optimal method? these changes can be many at once.
      Is it possible to create a script over rules-level that could handle the events and send it to the scene? and this script could store the references.

    I hope you understand what’s going on

    0
  • Comment author
    bartosz.stepien

    and my question: Is it possible to change the units on which the stage operates? By default, we now have meters and we need to represent in inches.

    0
  • Comment author
    marc

    Ad 1. I found method scene.get and it does what I need

    So only 3 questions are open

    0
  • Comment author
    William Thompson

    Hi Bartosz, I was told a Threekit developer reached out to Marcin directly, I will paste his comments here:

    Hi Marcin, once you get an id of an asset, you can use api.scene.get({ id }); to get the asset. To get it’s transform, I’ll throw an answer first - api.scene.get({ id, plug: ’Transform’, property: ’translation’ }); . When you get an asset or node, you may notice from the result that there are several types of plugs, the context are the same to what you are seeing on the right panel when you are using a Threekit editor. Hence to get the translation, in the second call I added the path of Transform plug and it’s translation property.

    For #2 Yes. To add a node we use api.scene.addNode( node, parentId ) , the first param: node is similar to what is seen from scene.get({ id }) . You need to specify the name, type of the node ( Null, Scene, Model, etc ), and based on types, the plugs. For instance if you want to add a model that references another asset in our platform, you can:

      const nodeId = api.scene.addNode(
        {
          id,
          type: ’Model’,
          name: `${type}_${key}`,
          plugs: {
            Null: [
              {
                type: ’Model’,
                asset: {
                  assetId,
                  // or query: { metadata: { SomeA: type, SomeB: key } },
                },
              },
            ],
          },
        },
        parentId
      );
    

    For deleting : api.scene.deleteNode(itemId);
    For 3#, the custom scripts are triggered when configuration changed.
    For 4# Yes scene.set() is the API for changing the scene and has been used widely. Unfortunately you can’t set translation and rotation at the same time. Besides, I guess you are looking for a place elsewhere to keep a track what’s being done? I don’t think it can be achieved inside our platform

    0

Please sign in to leave a comment.