Skip to content

Commit

Permalink
update to new codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
dinomut1 committed Jan 29, 2024
1 parent faa4725 commit aa4a0d6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
22 changes: 10 additions & 12 deletions src/components/BubbleComponent.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { defineComponent, getComponent, setComponent, useComponent } from "@etherealengine/engine/src/ecs/functions/ComponentFunctions"
import { createEntity, useEntityContext } from "@etherealengine/engine/src/ecs/functions/EntityFunctions"
import { Color, MathUtils, Mesh, MeshStandardMaterial, SphereGeometry, Vector3 } from "three"
import { useEffect } from "react"
import { addObjectToGroup } from "@etherealengine/engine/src/scene/components/GroupComponent"
import { Entity } from "@etherealengine/engine/src/ecs/classes/Entity"
import { NameComponent } from "@etherealengine/engine/src/scene/components/NameComponent"
import { EntityUUID } from "@etherealengine/common/src/interfaces/EntityUUID"
import { EntityTreeComponent } from "@etherealengine/engine/src/ecs/functions/EntityTree"
import { VisibleComponent } from "@etherealengine/engine/src/scene/components/VisibleComponent"
import { LocalTransformComponent } from "@etherealengine/engine/src/transform/components/TransformComponent"

import { defineComponent, useEntityContext, setComponent } from "@etherealengine/ecs"
import { NameComponent } from "@etherealengine/engine/src/common/NameComponent"
import { addObjectToGroup } from "@etherealengine/engine/src/renderer/components/GroupComponent"
import { VisibleComponent } from "@etherealengine/engine/src/renderer/components/VisibleComponent"
import { Mesh, SphereGeometry, MeshStandardMaterial, Color } from "three"
import matches from "ts-matches"

import React, { useEffect } from "react"
import { TransformComponent } from "@etherealengine/engine/src/transform/components/TransformComponent"

export const BubbleComponent = defineComponent({
//name: The human-readable label for the component. This will be displayed in the editor and debugging tools.
name: "Bubble Component",
Expand Down Expand Up @@ -44,7 +42,7 @@ export const BubbleComponent = defineComponent({
useEffect(() => {
setComponent(entity, VisibleComponent) // Set if the entity is visible
setComponent(entity, NameComponent, "Bubble") // Give the entity a name
setComponent(entity, LocalTransformComponent) // Give the entity a local transform
setComponent(entity, TransformComponent) // Give the entity a local transform
const bubbleMesh = new Mesh(new SphereGeometry(), new MeshStandardMaterial())
bubbleMesh.material.color = new Color(0xFFFFFF)
addObjectToGroup(entity, bubbleMesh) // Add GroupComponent and add mesh to Group
Expand Down
26 changes: 12 additions & 14 deletions src/components/BubbleEmitterComponent.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { defineComponent, getComponent, getMutableComponent, setComponent, useComponent } from "@etherealengine/engine/src/ecs/functions/ComponentFunctions"
import { createEntity, removeEntity, useEntityContext } from "@etherealengine/engine/src/ecs/functions/EntityFunctions"
import { BufferGeometry, Color, MathUtils, Mesh, MeshStandardMaterial, SphereGeometry, Vector3 } from "three"
import { useEffect } from "react"
import { GroupComponent, addObjectToGroup } from "@etherealengine/engine/src/scene/components/GroupComponent"
import { Entity } from "@etherealengine/engine/src/ecs/classes/Entity"
import { NameComponent } from "@etherealengine/engine/src/scene/components/NameComponent"
import { EntityUUID } from "@etherealengine/common/src/interfaces/EntityUUID"
import { EntityTreeComponent } from "@etherealengine/engine/src/ecs/functions/EntityTree"
import { VisibleComponent } from "@etherealengine/engine/src/scene/components/VisibleComponent"
import { defineComponent, Entity, useEntityContext, useComponent, removeEntity, getComponent, useExecute, createEntity, setComponent, SimulationSystemGroup, getMutableComponent } from "@etherealengine/ecs"
import { EngineState } from "@etherealengine/engine/src/EngineState"
import { GroupComponent } from "@etherealengine/engine/src/renderer/components/GroupComponent"
import { EntityTreeComponent } from "@etherealengine/engine/src/transform/components/EntityTree"
import { getState, NO_PROXY } from "@etherealengine/hyperflux"
import { Color, Vector3, Mesh, BufferGeometry, MeshStandardMaterial, MathUtils } from "three"
import { BubbleComponent } from "./BubbleComponent"
import { NO_PROXY, getState } from "@etherealengine/hyperflux"
import { useExecute } from "@etherealengine/engine/src/ecs/functions/SystemFunctions"
import { SimulationSystemGroup } from "@etherealengine/engine/src/ecs/functions/EngineFunctions"
import { EngineState } from "@etherealengine/engine/src/ecs/classes/EngineState"

import React, { useEffect } from "react"
import { ECSState } from "@etherealengine/ecs/src/ECSState"


export const BubbleEmitterComponent = defineComponent({
//name: The human-readable label for the component. This will be displayed in the editor and debugging tools.
Expand Down Expand Up @@ -85,7 +82,8 @@ export const BubbleEmitterComponent = defineComponent({
// Systems will run once per frame
// You must explicitly say where you want your system to run(i.e. after SimulationSystemGroup)
useExecute(() => {
const { elapsedSeconds, deltaSeconds } = getState(EngineState)

const deltaSeconds = getState(ECSState).deltaSeconds
ageEmitterBubbles(entity, deltaSeconds) // This function is accumulating the age of every bubble with the time from deltaSeconds.
// deltaSeconds is the time since the last system execute occured

Expand Down
14 changes: 5 additions & 9 deletions src/systems/BubbleSystem.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { defineQuery, getComponent, getMutableComponent } from "@etherealengine/engine/src/ecs/functions/ComponentFunctions";
import { defineSystem } from "@etherealengine/engine/src/ecs/functions/SystemFunctions";
import { BubbleEmitterComponent, removeBubble } from "../components/BubbleEmitterComponent";
import { LocalTransformComponent } from "@etherealengine/engine/src/transform/components/TransformComponent";
import { NO_PROXY, getState } from "@etherealengine/hyperflux";
import { EngineState } from "@etherealengine/engine/src/ecs/classes/EngineState";
import { Vector3 } from "three";
import { SimulationSystemGroup } from "@etherealengine/engine/src/ecs/functions/EngineFunctions";
import { defineQuery, defineSystem, SimulationSystemGroup, getComponent } from "@etherealengine/ecs"
import { Vector3 } from "three"
import { BubbleEmitterComponent } from "../components/BubbleEmitterComponent"
import { TransformComponent } from "@etherealengine/engine/src/transform/components/TransformComponent"

const bubbleEmitterQuery = defineQuery([BubbleEmitterComponent])
const velocity = new Vector3(0,0,0)
Expand All @@ -18,7 +14,7 @@ export const BubbleSystem = defineSystem({
// [Exercise 2]: Using the below basic setup. Move every bubble not just the first one
const tempvector = new Vector3(0,0,0)
const emitterComponent = getComponent(entity, BubbleEmitterComponent)
const localTransform = getComponent(emitterComponent.bubbleEntities![0], LocalTransformComponent)
const localTransform = getComponent(emitterComponent.bubbleEntities![0], TransformComponent)
if(!localTransform) continue;
velocity.copy(emitterComponent.direction).multiplyScalar(emitterComponent.speed)
tempvector.addVectors(localTransform.position, velocity)
Expand Down

0 comments on commit aa4a0d6

Please sign in to comment.