Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Initial setup

In this tutorial, you will use the **Hello World project** to learn how to work with iR Engine. This project provides a minimal working example to help you explore the engine’s core concepts.
In this tutorial, you will use the <a href="https://github.com/ir-engine/ir-tutorial-hello" target="_blank">Hello World project</a> to learn how to work with iR Engine. This project provides a minimal working example to help you explore the engine’s core concepts.

## Prerequisites

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ This ensures the engine loads and executes `Hello.ts` when the project starts.

## ➡️ Next steps

Your project is minimal but introduces **critical engine concepts**. Next, you will explore **how iR Engine structures data and logic using the ECS pattern**.
Your project is minimal but introduces critical engine concepts. Next, you will explore **how iR Engine structures data and logic using the ECS pattern**.

Continue to [The ECS pattern](./01_ecs.md) to understand the engine’s core architecture.
📌 Continue to [The ECS pattern](./01_ecs.md) to understand the engine’s core architecture.
24 changes: 14 additions & 10 deletions docs/developer/typescript/02_hello_world/01_ecs.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# The ECS pattern

iR Engine is built on the **Entity-Component-System (ECS)** pattern, a **modular and scalable** architecture used for game engines and simulations.
Now that your Hello World project is set up, it is time to understand the most crucial concept of the engine: **The ECS pattern.**

Understanding ECS is essential to working with iR Engine. This guide provides an overview of how ECS organizes **entities, components, and systems** to define behavior.
This guide provides an overview of how ECS **organizes** **entities, components, and systems** to define behavior.

***

Expand All @@ -26,9 +26,11 @@ The **Entity-Component-System (ECS) pattern** is a **data-driven architecture**

This separation allows for **efficient, modular, and reusable** code.

:::hint{type="info"}
💡 **Why ECS?**

Unlike traditional object-oriented programming, ECS avoids deep inheritance hierarchies. Instead, it **stores data separately** and **applies logic only when needed**, improving performance.
:::

***

Expand Down Expand Up @@ -63,13 +65,14 @@ ECS.setComponent(entity, PrimitiveGeometryComponent, { geometryType: 1 })

To display an entity in a scene, iR Engine requires specific components:

| **Component** | **Purpose** |
| :-------------------------------------------------------- | :----------------------------------------------------------- |
| `NameComponent` | Assigns a human-readable name to the entity. |
| `VisibleComponent` | Ensures the entity is **visible** in the scene. |
| `TransformComponent` | Defines the **position, rotation, and scale** of the entity. |
| - `PrimitiveGeometryComponent` &#xA;or:
- `MeshComponent` | Assigns a **basic 3D shape** or a **mesh **to the entity. |
| **Component** | **Purpose** |
| :------------------------------------------------- | :----------------------------------------------------------- |
| `NameComponent` | Assigns a human-readable name to the entity. |
| `VisibleComponent` | Ensures the entity is **visible** in the scene. |
| `TransformComponent` | Defines the **position, rotation, and scale** of the entity. |
| `PrimitiveGeometryComponent` or a `MeshComponent` | Assigns a **basic 3D shape** or a **mesh **to the entity. |

See more details about these components in the following section.

***

Expand Down Expand Up @@ -127,6 +130,8 @@ ECS.setComponent(entity, PrimitiveGeometryComponent, { geometryType: 1 })

The number `1` represents a [`SphereGeometry`](https://github.com/ir-engine/ir-engine/blob/dev/packages/engine/src/scene/constants/GeometryTypeEnum.ts#L28).

***

## Understand system logic

A **system** is responsible for processing logic on entities **that contain specific components**.
Expand Down Expand Up @@ -156,4 +161,3 @@ You will define a **system** in the following guides.
Now that you understand **ECS**, it’s time to start your first task, **modify an entity in iR Engine**.&#x20;

Continue to [Work in the engine](./02_engine.md) to modify your project’s source code**,** and start interacting with the application.

14 changes: 7 additions & 7 deletions docs/developer/typescript/02_hello_world/02_engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ iR Engine supports **projects**, which function similarly to projects in other g

Each project’s **source code runs globally**, which will become an important concept later.

### **Projects directory structure**
### Projects directory structure

By default, iR Engine scans for projects inside:

Expand All @@ -61,7 +61,7 @@ To integrate a project’s source code with iR Engine, you must:
1. **Import iR Engine modules**.
2. **Export the code so the engine can execute it**.

### **Project configuration file**
### Project configuration file

Each project has an `xrengine.config.ts` file, which registers it with the engine:

Expand All @@ -88,7 +88,7 @@ For now, just remember: **this file tells iR Engine how to load your project**.

In this tutorial, we will modify a **sphere primitive** in the scene.

### **Importing spatial components**
### Importing spatial components

Since the sphere is a **spatial** object, we must import components from the **spatial engine module**:

Expand All @@ -100,7 +100,7 @@ import { PrimitiveGeometryComponent } from '@ir-engine/packages/engine/src/scene
import { Vector3 } from 'three'
```

### **Importing ECS utilities**
### Importing ECS utilities

To manage entities, we also import **ECS functions**:

Expand All @@ -112,17 +112,17 @@ import { ECS } from '@ir-engine/packages/ecs'

Now that we understand the project structure, let's modify the **sphere’s geometry**.

### **Updating the geometry type**
### Updating the geometry type

Instead of hardcoding the value `1` for a sphere, we will use a readable **enum**.

### **Steps**
### Steps

1. Open `ir-tutorial-hello/src/Hello.ts`.
2. Import `GeometryTypeEnum` from the `scene/constants/` module.
3. Replace `1` with `GeometryTypeEnum.SphereGeometry`.

### **Where is the enum?**
### Where is the enum?

If you’re unsure where the enum is located, use these hints:

Expand Down
2 changes: 1 addition & 1 deletion docs/developer/typescript/02_hello_world/03_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A **system** executes logic on entities that contain specific components. Withou

Currently, your **entity creation logic** runs immediately when the project loads.

📌 To follow **best practices**, move it into a function.
📌 To follow best practices, move it into a function.

```typescript
let initialized = false // Track execution state
Expand Down
4 changes: 2 additions & 2 deletions docs/developer/typescript/02_hello_world/04_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ To restrict the sphere’s execution, you need to:
2. **Use a query** to execute logic only when an entity has this component.
3. **Ensure the system only runs under the right conditions**.

By following this approach, your system will **only create the sphere when needed** rather than running globally.
By following this approach, your system will only create the sphere when needed rather than running globally.

***

Expand All @@ -54,7 +54,7 @@ export const HelloComponent = ECS.defineComponent({
})
```

Right now, this component **does nothing on its own**. You will connect it to your system in the next step.
Right now, this component does nothing on its own. You will connect it to your system in the next step.

### What does this do?

Expand Down
16 changes: 8 additions & 8 deletions docs/developer/typescript/02_hello_world/05_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ This query **returns all entities** that have the `HelloComponent`.

Here's a table to help you understand the query:

| **Function** | **Description** |
| :------------------ | :---------------------------------------------------------------- |
| defineQuery(\[...]) | Creates a query to filter entities based on components. |
| \[HelloComponent] | The query will match **only** entities containing this component. |
| helloQuery() | When called, it returns **all matching entities**. |
| **Function** | **Description** |
| :------------------- | :---------------------------------------------------------------- |
| `defineQuery([...])` | Creates a query to filter entities based on components. |
| `[HelloComponent]` | The query will match **only** entities containing this component. |
| `helloQuery()` | When called, it returns **all matching entities**. |

At this stage, the query **does not run automatically**. You need to integrate it into your system.

Expand Down Expand Up @@ -101,10 +101,10 @@ export const HelloSystem = ECS.defineSystem({
})
```

### **How does this improve the system?**
### How does this improve the system?

| **Problem** | **Before** | **Now** |
| -------------------------------- | ------------------------------ | --------------------------------------------- |
| :------------------------------- | :----------------------------- | :-------------------------------------------- |
| Entities were processed manually | Had to store entity references | Query retrieves matching entities dynamically |
| Inefficient execution | System executed every frame | Now only executes for relevant entities |
| No filtering mechanism | Processed all entities | Now limited to entities with `HelloComponent` |
Expand Down Expand Up @@ -199,6 +199,6 @@ By using `defineQuery()`, your system now **retrieves entities dynamically inste

## ➡️ Next steps

Now that you have structured **entities, components, systems, and queries**, it's time to **recap what you've learned and move forward**.
Now that you have structured **entities, components, systems, and queries**, it's time to recap what you've learned and move forward.

📌 Continue to [Recap and next steps](./90_recap.md) .
Loading