Skip to content

Commit 5e620cb

Browse files
committed
Initial commit: Color & Lighting Test Scene
Test scene for comparing colors, PBR materials, emissive materials, and directional lighting across different times of day. Features: - Primary, secondary, and grayscale color cubes - Emissive cubes with varying intensities - PBR material tests (roughness, metallic, metals) - Sundial for visualizing light direction - UI controls for time of day presets - Virtual camera positions for consistent screenshots - Sky viewing positions (100m up)
0 parents  commit 5e620cb

31 files changed

+10096
-0
lines changed

.dclignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.*
2+
bin/*.map
3+
package-lock.json
4+
yarn-lock.json
5+
build.json
6+
export
7+
tsconfig.json
8+
tslint.json
9+
node_modules
10+
*.ts
11+
*.tsx
12+
.vscode
13+
Dockerfile
14+
dist
15+
README.md
16+
*.blend
17+
*.fbx
18+
*.zip
19+
*.rar
20+
*.md
21+
src
22+
cursor.config
23+
cursorignore
24+
.github

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: test-build
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
lint-and-build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Use Node.js 18.x
13+
uses: actions/setup-node@v1
14+
with:
15+
node-version: 18.x
16+
- name: install dependencies
17+
run: npm install
18+
- name: npm run build
19+
run: npm run build

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package-lock.json
2+
*.js
3+
node_modules
4+
bin/
5+
.DS_Store
6+
**/.DS_Store
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": []
3+
}

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// Use the Decentraland Editor extension of VSCode to debug the scene
3+
// in chrome from VSCode
4+
"version": "0.2.0",
5+
"configurations": [
6+
{
7+
"type": "chrome",
8+
"request": "launch",
9+
"name": "Debug Decentraland in Chrome",
10+
"url": "${command:decentraland-sdk7.commands.getDebugURL}",
11+
"webRoot": "${workspaceFolder}/bin",
12+
"sourceMapPathOverrides": {
13+
"dcl:///*": "${workspaceFolder}/*"
14+
}
15+
}
16+
]
17+
}

README.md

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
# SDK7 Template scene
2+
3+
## Try it out
4+
5+
**Previewing the scene**
6+
7+
1. Download this repository.
8+
9+
2. Install the [Decentraland Editor](https://docs.decentraland.org/creator/development-guide/sdk7/editor/)
10+
11+
3. Open a Visual Studio Code window on this scene's root folder. Not on the root folder of the whole repo, but instead on this sub-folder that belongs to the scene.
12+
13+
4. Open the Decentraland Editor tab, and press **Run Scene**
14+
15+
Alternatively, you can use the command line. Inside this scene root directory run:
16+
17+
```
18+
npm run start
19+
```
20+
21+
## What's new on SDK 7
22+
23+
Below are some basic concepts about the SDK 7 syntax. For more details, see the [Documentation site](https://docs.decentraland.org/creator/).
24+
25+
### Entities
26+
27+
An Entity is just an ID. It is an abstract concept not represented by any data structure. There is no "class Entity". Just a number that is used as a reference to group different components.
28+
29+
```ts
30+
const myEntity = engine.addEntity()
31+
console.console.log(myEntity) // 100
32+
33+
// Remove Entity
34+
engine.removeEntity(myEntity)
35+
```
36+
37+
> Note: Note that it's no longer necessary to separately create an entity and then add it to the engine, this is all done in a single act.
38+
39+
### Components
40+
41+
The component is just a data container, WITHOUT any functions.
42+
43+
To add a component to an entity, the entry point is now the component type, not the entity.
44+
45+
```ts
46+
Transform.create(myEntity, <params>)
47+
```
48+
49+
This is different from how the syntax was in SDK6:
50+
51+
```ts
52+
// OLD Syntax
53+
myEntity.addComponent(Transform)
54+
```
55+
56+
#### Base Components
57+
58+
Base components already come packed as part of the SDK. Most of them interact directly with the renderer in some way. This is the full list of currently supported base components:
59+
60+
- Transform
61+
- Animator
62+
- Material
63+
- MeshRenderer
64+
- MeshCollider
65+
- AudioSource
66+
- AudioStream
67+
- AvatarAttach
68+
- AvatarModifierArea
69+
- AvatarShape
70+
- Billboard
71+
- CameraMode
72+
- CameraModeArea
73+
- GltfContainer
74+
- NftShape
75+
- PointerEventsResult
76+
- PointerHoverFeedback
77+
- PointerLock
78+
- Raycast
79+
- RaycastResult
80+
- TextShape
81+
- VisibilityComponent
82+
83+
```ts
84+
const entity = engine.addEntity()
85+
Transfrom.create(entity, {
86+
position: Vector3.create(12, 1, 12)
87+
scale: Vector3.One(),
88+
rotation: Quaternion.Identity()
89+
})
90+
GltfContainer.create(zombie, {
91+
withCollisions: true,
92+
isPointerBlocker: true,
93+
visible: true,
94+
src: 'models/zombie.glb'
95+
})
96+
```
97+
98+
#### Custom Components
99+
100+
Each component must have a unique number ID. If a number is repeated, the engine or another player receiving updates might apply changes to the wrong component. Note that numbers 1-2000 are reserved for the base components.
101+
102+
When creating a custom component you declare the schema of the data to be stored in it. Every field in a component MUST belong to one of the built-in special schemas provided as part of the SDK. These special schemas include extra functionality that allows them to be serialized/deserialized.
103+
104+
Currently, the names of these special schemas are:
105+
106+
##### Primitives
107+
108+
1. `Schemas.Boolean`: true or false (serialized as a Byte)
109+
2. `Schemas.String`: UTF8 strings (serialized length and content)
110+
3. `Schemas.Float`: single precission float
111+
4. `Schemas.Double`: double precision float
112+
5. `Schemas.Byte`: a single byte, integer with range 0..255
113+
6. `Schemas.Short`: 16 bits signed-integer with range -32768..32767
114+
7. `Schemas.Int`: 32 bits signed-integer with range -2³¹..(2³¹-1)
115+
8. `Schemas.Int64`: 64 bits signed-integer
116+
9. `Schemas.Number`: an alias to Schemas.Float
117+
118+
##### Specials
119+
120+
10. `Schemas.Entity`: a wrapper to int32 that casts the type to `Entity`
121+
11. `Schemas.Vector3`: a Vector3 with { x, y, z }
122+
12. `Schemas.Quaternion`: a Quaternion with { x, y, z, w}
123+
13. `Schemas.Color3`: a Color3 with { r, g, b }
124+
14. `Schemas.Color4`: a Colo4 with { r, g, b, a }
125+
126+
##### Schema generator
127+
128+
15. `Schemas.Enum`: passing the serialization Schema and the original Enum as generic
129+
16. `Schemas.Array`: passing the item Schema
130+
17. `Schemas.Map`: passing a Map with Schemas as values
131+
18. `Schemas.Optional`: passing the schema to serialize
132+
133+
Below are some examples of how these schemas can be declared.
134+
135+
```ts
136+
const object = Schemas.Map({ x: Schemas.Int }) // { x: 1 }
137+
138+
const array = Schemas.Map(Schemas.Int) // [1,2,3,4]
139+
140+
const objectArray = Schemas.Array(Schemas.Map({ x: Schemas.Int })) // [{ x: 1 }, { x: 2 }]
141+
142+
const BasicSchemas = Schemas.Map({
143+
x: Schemas.Int,
144+
y: Schemas.Float,
145+
text: Schemas.String,
146+
flag: Schemas.Boolean
147+
}) // { x: 1, y: 1.412, text: 'ecs 7 text', flag: true }
148+
149+
const VelocitySchema = Schemas.Map({
150+
x: Schemas.Float,
151+
y: Schemas.Float,
152+
z: Schemas.Float
153+
})
154+
```
155+
156+
To then create a custom component using one of these schemas, use the following syntax:
157+
158+
```ts
159+
export const myCustomComponent = engine.defineComponent(MyDataSchema, ComponentID)
160+
```
161+
162+
For contrast, below is an example of how components were constructed prior to SDK 7.
163+
164+
```ts
165+
/**
166+
* OLD SDK
167+
*/
168+
169+
// Define Component
170+
@Component('velocity')
171+
export class Velocity extends Vector3 {
172+
constructor(x: number, y: number, z: number) {
173+
super(x, y, z)
174+
}
175+
}
176+
// Create entity
177+
const wheel = new Entity()
178+
179+
// Create instance of component with default values
180+
wheel.addComponent(new WheelSpin())
181+
182+
/**
183+
* ECS 7
184+
*/
185+
// Define Component
186+
const VelocitySchema = Schemas.Map({
187+
x: Schemas.Float,
188+
y: Schemas.Float,
189+
z: Schemas.Float
190+
})
191+
const COMPONENT_ID = 2008
192+
const VelocityComponent = engine.defineComponent(Velocity, COMPONENT_ID)
193+
// Create Entity
194+
const entity = engine.addEntity()
195+
196+
// Create instance of component
197+
VelocityComponent.create(entity, { x: 1, y: 2.3, z: 8 })
198+
199+
// Remove instance of a component
200+
VelocityComponent.deleteFrom(entity)
201+
```
202+
203+
### Systems
204+
205+
Systems are pure & simple functions.
206+
All your logic comes here.
207+
A system might hold data which is relevant to the system itself, but no data about the entities it processes.
208+
209+
To add a system, all you need to do is define a function and add it to the engine. The function may optionally include a `dt` parameter with the delay since last frame, just like in prior versions of the SDK.
210+
211+
```ts
212+
// Basic system
213+
function mySystem() {
214+
console.log('my system is running')
215+
}
216+
217+
engine.addSystem(mySystem)
218+
219+
// System with dt
220+
function mySystemDT(dt: number) {
221+
console.log('time since last frame: ', dt)
222+
}
223+
224+
engine.addSystem(mySystemDT)
225+
```
226+
227+
#### Query components
228+
229+
The way to group/query the components inside systems is using the method getEntitiesWith.
230+
`engine.getEntitiesWith(...components)`.
231+
232+
```ts
233+
function physicsSystem(dt: number) {
234+
for (const [entity, transform, velocity] of engine.getEntitiesWith(Transform, Velocity)) {
235+
// transform & velocity are read only components.
236+
if (transform.position.x === 10) {
237+
// To update a component, you need to call the `.mutable` method
238+
const mutableVelocity = VelocityComponent.getMutable(entity)
239+
mutableVelocity.x += 1
240+
}
241+
}
242+
}
243+
244+
// Add system to the engine
245+
engine.addSystem(physicsSystem)
246+
247+
// Remove system
248+
engine.removeSystem(physicsSystem)
249+
```
250+
251+
### Mutability
252+
253+
Mutability is now an important distinction. We can choose to deal with mutable or with immutable versions of a component. We should use `getMutable` only when we plan to make changes to a component. Dealing with immutable versions of components results in a huge gain in performance.
254+
255+
The `.get()` function in a component returns an immutable version of the component. You can only read its values, but can't change any of the properties on it.
256+
257+
```ts
258+
const immutableTransform = Transform.get(myEntity)
259+
```
260+
261+
To fetch the mutable version of a component, call it via `ComponentDefinition.getMutable()`. For example:
262+
263+
```ts
264+
const mutableTransform = Transform.getMutable(myEntity)
265+
```

assets/alpha.png

905 Bytes
Loading

assets/alpha_gradient.png

7.21 KB
Loading

0 commit comments

Comments
 (0)