Creation of the Lamborghini Urus project (WebGL-PlayCanvas). Part 9.

Vasyl Lukianenko
Vasyl Lukianenko
3D Artist and Technical Author
You are reading part: 1 2 3 4 5 6 7 8 9 10

Intro Part 9

This is Part 9 of the tutorial series on building a Lamborghini Urus with WebGL/PlayCanvas.

For those who haven't read the previous parts, here's a demo video.



In this part of the tutorial, we will add even more interactivity to the scene, create custom scripts and program the interface.

Access to materials, such as: models in the format "FBX", textures, baked maps "AO" and more, you can get by subscribing to Patreon.

Patreon - 3DGROUND

Wheel rotation script

Download the script below by calling the context menu on the "view raw" link and clicking "Save link as...". Add the script to the project by dragging the "wheelRotation.js" file into the "Assets" panel → "scripts".



Select the front tires object in the "Viewport", then click the "Inspector" button "Add Component", add the "Script" component. From the "Add Script" list of scripts, select "wheelRotation".

playcanvas add script wheel rotation
Loading...

Do the same for the rear tires object and all disks. It is important to apply the script specifically to objects, and not to templates or "Entity", which is higher in the hierarchy.

What is convenient, you do not need to make any additional settings, just apply the script and you're done.

Press "Play", the wheels began to spin! Due to the fact that our texture is shifting and the wheels are spinning, it creates the effect that the car is really driving through the desert, although it is static.

Result

wheel rotation result script
Loading...

Door opening script

Download the "openDoors.js" script and add it to your project in "Assets" → "scripts".



Select the left doors in the "Viewport" and apply the "openDoors" script to the object, after adding the "Script" component.

playcanvas script open door settings left door 2
Loading...

Be sure to set "axis" equal to "y" in the script settings for the left door and enable the "Inverted" checkbox.

By analogy, we act with the right door. Select the object in "Viewport", apply the "Script" component, select "openDoors" from the list, specify the settings as in the screenshot below.

playcanvas script open doors setting right door
Loading...

And all the same for the tailgate.

playcanvas script open doors settings trunk
Loading...

Press "Play" when the player loads, press the 1 button on the keyboard, the doors will open for you. Later, we will open the doors with a button in the interface.

As you can see, working with crypts is very simple, and thanks to the universal settings, they can be used in other projects.

Result

playcanvas script open door settings left door 2
Loading...

Disk changer script

Download the "setColor.js" script and add it to your project under "Assets" → "scripts".

playcanvas add script setdisk
Loading...

Apply the script to "Entity" - "Discs".



Select "Entity": "SM_WheeDisc_1", "SM_WheeDisc_2", "SM_WheeDisc_3". On the "Inspector" panel and add the "disk" tag. Don't forget to press Enter on your keyboard to add the tag.

playcanvas set disk tag
Loading...

Carpaint color change script

Download the "setColor.js" script and add it to your project under "Assets" → "scripts".



Apply the script to "Entity" - "Car". In the script settings, leave the "Material Tag" parameter equal to the default.

How this script works: when we generate an event to change color (pressing a button in the interface), for all materials that have the "carpaint" tag, "Diffuse" color will be changed to the one that we will transmit directly through this event.

playcanvas assign script setcolor
Loading...

Go to the "Assets" panel, in the search find all the materials of our "M_CarPaint....", select these materials and in the "Inspector" panel, in the "Tags" form, write the tag "carpaint ". Don't forget to press Enter on your keyboard to add the tag.

playcanvas assign tag carpaint to materials
Loading...

In the next step, we will create an interface and associate button clicks and colors.

Creating an interface

Create a new "Entity" in the "Hierarchy" panel named "UI". Then download the "ui.js" script and add it to the project in "Assets" → "scripts".

playcanvas add entity ui with script
Loading...

Assign "ui" script to "Entity" - "UI" by adding the "Script" component and selecting the suggested script from the list.



In this script, we create an interface using HTML code. By adding dynamically necessary "div" elements and defining "CSS" styles.

We will not describe the entire process in detail, since this is beyond the scope of this master class.

The principle is that we create a block in the center, at the bottom of the page, in which we add buttons for changing colors and additional buttons for changing disks and opening doors.

In this array, we determine what the colors of the buttons will be. "color" is the color to change in the material, and "hex" is the hexadecimal color code of the HTML button.

var colors = [    {        
        color: new pc.Color(255.0/255.0, 131.0/255.0, 0/255.0),
        hex: "#ff8300"
    },
    {        
        color: new pc.Color(82.0/255.0, 176.0/255.0, 0/255.0),
        hex: "#52b000"
    },
    {        
        color: new pc.Color(17.0/255.0, 74.0/255.0, 151.0/255.0),
        hex: "#114a97"
    },
    {        
        color: new pc.Color(162.0/255.0, 24.0/255.0, 24.0/255.0),
        hex: "#a21818"
    }
];

The size of the buttons is set using this variable.

var buttonSize = '30px';

Buttons for opening doors and changing rims. Additional properties have also been defined here, such as the name of the button, the size of the icon, the icon itself, and the name of the event that is being sent.

var buttons = [     {
        name: 'Door',
        icon: iconDoor,
        iconSize: '90%',
        action: 'opendoor',
        tag: '',
        data: ''
    },
    {
        name: 'Wheel',
        icon: iconWheel,
        iconSize: 'contain',
        action: 'setdisk',
        tag: 'disk',
        data: ''
    }
];

The icons for the color change buttons are dynamically generated by creating a square "div" block with a background and "CSS" overlaid with a translucent gradient. There are no graphics at all here.

The buttons for opening doors and changing discs were drawn in Photopea in vector, then saved as "SVG", then the code from "SVG" was translated into "CSS" code.

var iconWheel = "url("data:image/svg+xml,%3Csvg version='1.2' baseProfile='tiny-ps' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 94 94' width='94' height='94'%3E%3Ctitle%3Eimage%3C/title%3E%3Cstyle%3E tspan %7B white-space:pre %7D .s0 %7B fill: %23fff %7D %3C/style%3E%3Cpath fill-rule='evenodd' class='s0' d='m47 94c-25.99 0-47-21.01-47-47c0-25.99 21.01-47 47-47c25.99 0 47 21.01 47 47c0 25.99-21.01 47-47 47zm37.82-47c0-20.92-16.91-37.82-37.82-37.82c-20.92 0-37.82 16.91-37.82 37.82c0 20.92 16.91 37.82 37.82 37.82c20.92 0 37.82-16.91 37.82-37.82zm-37.82 33.41c-18.47 0-33.41-14.93-33.41-33.41c0-18.47 14.93-33.41 33.41-33.41c18.47 0 33.41 14.93 33.41 33.41c0 18.47-14.93 33.41-33.41 33.41zm4.72-33.41c0-2.61-2.11-4.72-4.72-4.72c-2.61 0-4.72 2.11-4.72 4.72c0 2.61 2.11 4.72 4.72 4.72c2.61 0 4.72-2.11 4.72-4.72zm-15.08-25.95c0.37 8.16 5.18 14.59 11.06 14.59c5.94 0 10.78-6.55 11.07-14.81c-3.34-1.33-6.99-2.06-10.81-2.06c-4.02 0-7.85 0.81-11.33 2.28zm31.85 8.05c-7.64 2.87-12.28 9.43-10.46 15.03c1.84 5.65 9.56 8.23 17.5 5.96c0.23-3.59-0.2-7.28-1.38-10.92c-1.24-3.82-3.19-7.21-5.66-10.07zm2.18 32.78c-5.09-6.38-12.76-8.76-17.53-5.3c-4.81 3.49-4.87 11.63-0.26 18.49c3.49-0.89 6.87-2.44 9.96-4.68c3.25-2.36 5.87-5.27 7.83-8.5zm-30.5 12.21c4.49-6.82 4.39-14.85-0.37-18.31c-4.81-3.49-12.57-1.04-17.66 5.47c1.92 3.04 4.44 5.78 7.53 8.02c3.25 2.36 6.82 3.96 10.5 4.82zm-21.03-25.24c7.87 2.17 15.48-0.41 17.3-6.01c1.84-5.65-2.9-12.27-10.66-15.11c-2.3 2.77-4.12 6.01-5.3 9.64c-1.24 3.82-1.65 7.71-1.34 11.48z' /%3E%3C/svg%3E")";

var iconDoor = "url("data:image/svg+xml,%3Csvg version='1.2' baseProfile='tiny-ps' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 164 165' width='164' height='165'%3E%3Ctitle%3Ecardoor%3C/title%3E%3Cstyle%3E tspan %7B white-space:pre %7D .s0 %7B fill: %23ffffff %7D %3C/style%3E%3Cpath fill-rule='evenodd' class='s0' d='m60.62 11.98c7.56-7.67 17.88-11.98 28.65-11.98h69.7c2.78 0 5.03 2.25 5.03 5.03v154.94c0 2.78-2.25 5.03-5.03 5.03h-121.71c-7.17 0-13.48-4.74-15.47-11.63l-20.35-70.43c-1.52-5.25-0.08-10.9 3.76-14.79l55.42-56.18zm50.05 81.59c0 3.33 2.7 6.04 6.04 6.04h21.13c3.33 0 6.04-2.7 6.04-6.04c0-3.33-2.7-6.04-6.04-6.04h-21.13c-3.33 0-6.04 2.7-6.04 6.04zm28.12-21.13c2.8 0 5.06-2.28 5.03-5.08l-0.43-41.73c-0.03-2.76-2.27-4.98-5.03-4.98h-44.91c-8.13 0-15.92 3.28-21.6 9.1l-31.67 32.44c-3.73 3.82-1.02 10.25 4.32 10.25h94.28z' /%3E%3C/svg%3E")";

Thus, we did not connect additional graphics, and all icons are implemented in the form of code.

On pressing the color change button, we call the "app.fire" function, in which we pass the name of the event and the color itself. We take the color dynamically from the "colors " array.

app.fire('setcolor', colors[index].color);

To open doors and change disks, we call the event dynamically, where we take the name of the event and the tag parameter from the "buttons" array.

app.fire(buttons[index].action, buttons[index].tag);

Thus we connected the interface with other scripts. And we can remove or add new colors or buttons in arrays without changing the "ui " script code itself.

Note!
Pay attention to the fact that for the "setColor" script we specified the tag ourselves in the parameters, and for the "setDisk" script the tag is passed dynamically through an event. This is done on purpose, to demonstrate different approaches to the problem.

Result

playcanvas complete result
Loading...

Conclusion

playcanvas car urus done
Loading...

In this part, we added interactivity to our scene, made the interface and the project is complete. In the next part, we will improve the lighting, shadows and make the picture more attractive.

You are reading part: 1 2 3 4 5 6 7 8 9 10

FAQ

1. What is this article about?
This article continues the Lamborghini Urus PlayCanvas project and focuses on the next stage of developing an interactive automotive WebGL configurator.
2. What is covered in Part 9?
Part 9 explores new project features, further optimization, visual quality improvements, and enhancements to the user interface.
3. Why does the project span multiple development stages?
Building a high-quality interactive configurator requires gradual feature implementation, continuous testing, and ongoing improvements to the user experience.
4. What tasks are typically addressed at this stage of development?
At later stages, developers focus on interface details, visual effects, performance optimization, and additional interactive functionality.
5. Why is improving visual quality important?
More realistic visualization helps users better evaluate the product and increases the overall appeal of the presentation.
6. How does optimization affect user experience?
An optimized application runs faster, performs more smoothly, and provides a better experience across a wide range of devices.
7. Can new vehicle configuration options be added?
Yes. Additional colors, materials, trim options, and customization features can be introduced throughout the development process.
8. Why is user interface design important?
An intuitive interface helps users quickly find the features they need and makes interaction with the configurator more enjoyable.
9. Is PlayCanvas suitable for commercial configurators?
Yes. PlayCanvas is widely used for creating browser-based interactive product presentations and configurators.
10. Can similar technologies be used outside the automotive industry?
Yes. The same approaches are commonly used in real estate, e-commerce, manufacturing, furniture visualization, and interior design.
11. Why is maintaining a well-organized project structure important?
A structured project simplifies maintenance, future feature development, and collaboration between team members.
12. Can these applications run on mobile devices?
Yes. With proper optimization, WebGL applications can perform effectively on smartphones and tablets.
13. Are programming skills required for advanced functionality?
Yes. JavaScript and PlayCanvas API knowledge are typically required to create advanced logic and interactive systems.
14. What advantages does an interactive configurator offer over static images?
Users can explore the vehicle, customize options, and gain a much deeper understanding of the product through real-time interaction.
15. Can the project continue to evolve after release?
Yes. New features, interface improvements, performance optimizations, and additional customization options can be added after launch.
16. Who is this article useful for?
This article is useful for PlayCanvas developers, WebGL specialists, technical artists, automotive visualization professionals, and anyone interested in creating interactive 3D applications for the web.
Vasyl Lukianenko
Vasyl Lukianenko
3D Artist and Technical Author
Vasyl Lukianenko is a 3D artist and technical author focused on practical workflows, optimization, and production-ready techniques. He publishes tutorials, courses, and tools to help artists work faster and get cleaner results.
{{commentsMsg}}
  

No one has posted a comment yet
{{comment.lastname}} {{comment.name}} {{comment.date}}
{{comment.text}}
Sponsored content