Create a basic 3D configurator
  • 20 Sep 2024
  • 6 Minutes to read
  • Contributors
  • Dark
    Light

Create a basic 3D configurator

  • Dark
    Light

Article summary

The goal is to create a basic 3D Mokapot configurator. The user should be able to

  • change the color of the upper and lower part
  • open and close the lid
  • set a individual motive for the bottom part
  • view the Mokapot in AR mode

2024-04-29_10h21_41

Link to the finished configurator.

Needed content

For the implemenatation you need the following files

moka-pot.glb

Graphics.zip

Steps to reproduce

To achieve the functionalities mentioned, the following steps must be implemented.

First steps

  1. Create a new configurator based on the Mokapot step by step example template.
    • Name: Use a meaningful name of your choice
    • ID and Asset bundles are prefilled correctly

    If the assigned bundles are changed/renamed, it cannot be guaranteed that the following example can be implemented without any problems.

create-cfgr

  1. Use the asset manager to upload the mokapot.glb file.
    Asset bundle: Assets3DMoka
    Folder: Models3d
    2024-06-04_15h23_22
    See the documentation for detailed information.

    Handling textures when uploading your model

    The bundle already contains some textures (see folder Textures3d) which will automatically be linked with the respective material when uploading your model. In general, textures need to be uploaded separately as GLB files encode textures into base64 strings, which might lead to warnings in your Materials3d folder. If such warnings occur, just select the detected asset and set the Image in Channels to - and save the changes. It's best practice to save your textures separately when exporting your models to GLB (e.g. in Blender or Autodesk Maya). That way you won't run into the described issues with textures being encoded to base64.
    2024-06-04_15h23_22

  2. Add the following line of code to the ViewerParams value component.

         Viewer3d.modelParameter(Models3d.mokapot, "visible", true)
    

    To gain more information about this component, have a look at our documentation.

  3. To make the 3D model visible in the viewer, connect the viewer control with the viewer parameters component. Add the following SigSlo.

    2024-06-04_15h33_30

Change colour individually

  1. Go to the Asset Editor and create data source Colours based on the file asset Moka_ProductData (see Create data source)
    2024-06-04_15h40_36

  2. Back in the configurator backend, create a table component named Colours_Tbl.

  3. Load the colours into the component (see Queries). To do this, add the following query to your table component:

    from ProductData.Colours select all
    
  4. Connect the table component and dataview for the top colour

    Solution

    1. Set the entries of the dataview
    • Open the SigSlo editor.
    • As Signal, select your Colours_Tbl component.
    • As Slot, select your dataview TopColours_dv with the option Set entries.
    • Set the source type of the entries-parameter to Control or Component and select your Colours_Tbl component, for property select Value.

    2024-06-04_15h48_36

    • Edit the mapping-parameter so that Text and Value is mapped to ID and Image background to HEX_CODE.

    2024-06-04_15h49_01

    1. Write selection changes from the dataview back to the value component
    • Create a value component with the name TopColour.
    • Add the following code to the component
    Colours_Tbl.Get(Input or 0) or Colours_Tbl.GetFirst()
    
    • Set the input type of the component to Number.
      2024-06-05_14h05_50

    • Open the SigSlo Editor

    • As Signal use the TopColours_dv with the Value Changed signal

    • The Slot is your created TopColour value component with the option Set value

    • Set the source type of the entries-parameter to Control or Component and select your control TopColours_dv, for property select Value.

    2024-06-04_15h54_25

    1. Write selection changes from the value component back to the dataview.
    • Go to the TopColours_dv dataview and enable Hive for the dataviews value property, by clicking on the code icon next to the input field
    • Open the Editor by clicking on the Value label

    2024-06-04_15h56_37

    • Get the data from the value component TopColour by writing a simple script like
        TopColour
    


  5. Connect the table component and dataview for the lower colour

    To do this repeat step 4. When creating value or table components use the word Lower instead of Top.

    Following components and controls are needed: Colours_Tbl, LowerColour, LowerColours_dv

  6. Make colour changes visible in 3D

    Adapt the viewer parameters in the ViewerParams component. Add the following lines of code

        Viewer3d.materialParameter(Materials3d.matPaint_top, "color", TopColour.HEX_CODE),
        Viewer3d.materialParameter(Materials3d.matPaint_bot, "color", LowerColour.HEX_CODE)
    

Open/Close lid

  1. Create a new value component named LidOpened, to store if the lid should be opened or closed.

  2. Set the input type of the component to Logic and add the following script

        if Input is Empty then false else Input end
    
  3. To store the user input, connect the checkbox with the value component. To do this, create a SigSlo (the button with the node-like icon in the top right corner of the Controls panel) with the shown settings below.

    2024-06-05_08h08_40

  4. You also need a connection in the other direction. If the value in LidOpened changes, the checkbox has to be updated.
    For that, enable Hive for the checkbox value property by clicking on the code icon next to the input field.
    2024-06-05_08h10_08

  5. Set the position of the opened/closed lid. To do this, you have to adapt the ViewerParams component. Add the following line of code to make the animation visible in 3D.

            Viewer3d.nodeParameter("Toplid", "rotation", if LidOpened then "(-45,0,0)" else "(0,0,0)" end)
    

Display a individual motive on the bottom part

  1. Upload the images graphic1.svg, graphic2.svg, graphic3.svg and graphic4.svg as text assets in the asset manager. Make sure that the uploaded SVG files do not contain any DOCTYPE or xml tags as they must only include the pure svg.
    Asset bundle: ProductDataMoka
    Folder: Visualization
    Asset type: Text
    2024-06-05_08h18_52

    The corresponding data is already available in the configurator (components Graphic_Tbl and LowerGraphic).

  2. Create a new Graphic component named TextureView.
    2024-06-05_08h24_05

    • Set the size to 1024 x 1024px. Please click on the texts (Width, Height) to bring up the component editor rather than entering the values directly into the input field.
    • Add a new Visual of type Single VisualSVG and name it Graphic.
    • To show the chosen image, set the Texture.Source to
          """<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"  version="1.1" viewBox="5 -25 100 512">
              {=LowerGraphic.VIS_IMG.getText()}
          </svg>"""
      
ViewBox

Nesting the motive within a parent svg element is necessary in this example as we want the motives to have a certain size, which is given by the outer svg's viewBox attribute.

  1. To display the motive on the mokapot use a so called paintable.
    Add the following line of code to the ViewerParams component.
        Viewer3d.materialParameter(Materials3d.matLogo_2, "paintable", { src: TextureView.Value.ToText(), uScale: 1, vScale: -1 }.ToText())
    
Blend mode

The paintable will most likely just show a black surface instead of the expected motive. If so, head over to the Asset Editor, go to the Materials3d folder and select the matLogo_2 material. Head over to the Transparency section and set the Transparency mode property to Alpha blend and test.

AR mode

To make the AR button work, you have to create a SigSlo with the Start AR slot.

2024-06-05_08h28_11

Adjust the parameters below. These parameters are essentially texts displayed in the User Interface. By default, those values are static and filled with texts in English. If you want this texts to be dependent on the currently selected language, you might want to link to a component containing translations. In our example that's the GeneralUI component which holds dedicated columns for those AR-related texts.

ParameterSourceProperty
QR sub titleGeneralUIqrSubtitle
QR descriptionGeneralUIqrDescription
Preparation textGeneralUIarPrepText

For detailed information about the AR mode have a look at the documenation.

Auto focus camera

The auto-focus camera is used to find a default position, where all nodes are visible in the scene. To make the CenterCamera_btn work you have to create a SigSlo with the following settings.
2024-06-05_08h30_58

For a good camera perspective, adjust the parameters as follows

  • Alpha to 180,
  • Beta to 90 and
  • Radius factor to 1.4.

See auto focus camera for detailed information.


Was this article helpful?