Using Triplex Standalone
Let's create your first component with Triplex! No experience is needed to follow along however it's assumed you have a project set up after following a page under Starting a Project.
Creating a New File
First we are going to make a new file to build our scene in. With Triplex Standalone open:
-
Find the New File action in the Tab Bar and click it. A new file called untitled.tsx is opened that contains a box.
-
Click & drag over the scene to rotate the camera around.
-
Click the box in the scene to focus it. When focused press the F key to zoom the camera to it.
The built-in Camera Controls let you view your scene from different
viewpoints. Try zooming in & out by scrolling, and panning by holding Shift
then dragging.
Before continuing let's save the file to the file system using the ⌘ + SSave action, name it anything you want.
Adding More Shapes
Now let's add some more shapes to fill the scene out.
-
Click the Add Element action in the scene panel. The Assets Panel will open. Search for Mesh and click it. Nothing will appear in the scene yet.
-
Hover over the added mesh and click the Add Child Element action then search for Sphere Geometry and click it. A sphere will appear in the scene.
-
Hover over the mesh and click the Add Child Element action again then search for Mesh Standard Material and click it. The sphere is now shaded.
-
Click the sphere in the scene, then click the Translate action in the Scene Controls, then finally move the sphere off the box.
The built-in Transform Controls are shown on selected elements. If the element doesn't declare the prop for the selected transform mode it will be disabled.
Before continuing try adding a cylinder mesh in code instead of the UI. Jump to code quickly by clicking the "View source" link in the scene panel.
Adding Lights
Now let's add three-point lighting to the scene.
-
When no lights are present in the scene default lights are turned on. Click the Turn Off Default Lights action in the Scene Controls to turn them off. Click it again to turn it back on.
-
Click the Add Element action in the scene panel then search for Point Light and click it. A point light will appear in the scene.
-
With the point light selected, go to the context area and update its
Name
prop to "Key light". -
Position the key light in front and to the side of the scene.
-
Duplicate the key light by selecting it then using the ⌘ + DDuplicate Element action. Name the duplicated light "Fill light" and move it to the opposite side of the scene.
-
Create the last light by adding another point light named "Backlight" then move it to the back of the scene.
The built-in Scene Helpers are shown for select objects such as lights and cameras helping you see where they have been positioned in your scene.
Before continuing try adjusting the lights Intensity
and Color
props in the context area. The key light should have the highest intensity, then about half as much for the fill light, and then the backlight about the same.
Adding a Camera
Now let's add a camera to the scene by updating code.
-
Install Drei — a companion library for Three Fiber.
Terminalnpm i @react-three/drei
-
Copy the highlighted code into your component then jump back into Triplex Standalone. A camera will appear in the scene.
new-scene.tsximport { PerspectiveCamera } from "@react-three/drei"; export function Untitled() { return ( <> ... <PerspectiveCamera /> </> ); }
-
Position and rotate the camera at an angle in-front of the scene. We're operating on vibes here so do what feels good!
-
Click the Set Local Transform action in the Scene Controls. Transforms now operate in local space, when translating the camera it will move in the direction it's facing. Click again to move back to global space.
-
On the camera set the
Make Default
prop to be checked. When playing your scene this camera will now be used. -
Click the Play action in the Scene Controls to run the scene through your camera.
-
Click the Settings action next to the Play action to switch to other cameras.
Play Controls let you run and interact with your scene. When pressing the stop or the reset action your scene is reset to its initial state.
Before continuing try adjusting the camera Fov
, Near
and Far
props in the context area. They control the field of view and where objects are rendered in relation to the camera.
Component Props
Finally we're going to add some props to your component.
-
Click the "View source" link in the scene panel to jump to code.
-
Add two props to your component, the
backlight
prop should be a boolean that defaults totrue
and thebacklightColor
prop should be a string.new-scene.tsxexport function Untitled({ backlight = true, backlightColor, }: { backlight?: boolean; backlightColor?: string; }) { // ... }
-
Conditionally render the backlight element using the
backlight
prop.new-scene.tsxexport function Untitled({ backlight = true, backlightColor, }: { backlight?: boolean; backlightColor?: string; }) { return ( <> ... {backlight && <pointLight name="Backlight" />} </> ); }
-
Pass the
backlightColor
prop to the backlight point light.new-scene.tsxexport function Untitled({ backlight = true, backlightColor, }: { backlight?: boolean; backlightColor?: string; }) { return ( <> ... {backlight && <pointLight color={backlightColor} name="Backlight" />} </> ); }
-
Click the Component Controls action in the ScenePanel. The controls shown in the scene panel are the props the component accepts which can be changed as you build!
-
Toggle the
backlight
prop on and off, then set thebacklightColor
prop to a color you like. Red is always a great choice!
Component controls let you change the props of the open component. Very useful when you want to see how your component behaves with props of different values!
Next Steps
Congratulations on building your first 3D component! From here you can learn more about the features of Triplex and join our community to build amazing things together.