Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic render engine example #351

Open
vorg opened this issue Oct 18, 2023 · 0 comments
Open

Add basic render engine example #351

vorg opened this issue Oct 18, 2023 · 0 comments

Comments

@vorg
Copy link
Member

vorg commented Oct 18, 2023

Minimal example seems to be below. Our current basic.js is quite verbose (even if indeed basic)

import {
  renderEngine as createRenderEngine,
  world as createWorld,
  entity as createEntity,
  components,
} from "../index.js";

import createContext from "pex-context";

import { cube } from "primitive-geometry";

const pixelRatio = devicePixelRatio;
const ctx = createContext({ pixelRatio });
const renderEngine = createRenderEngine({ ctx });
const world = createWorld();

const perspectiveCameraEntity = createEntity({
  transform: components.transform({
    position: [5, 5, 5],
  }),
  camera: components.camera({}),
  orbiter: components.orbiter(),
});
world.add(perspectiveCameraEntity);

const cubeEntity = createEntity({
  transform: components.transform(),
  geometry: components.geometry(cube()),
  material: components.material({}),
});
world.add(cubeEntity);

const gridTenEntity = createEntity({
  transform: components.transform({ scale: [2, 2, 2] }),
  gridHelper: components.gridHelper({ size: 10 }),
});
world.add(gridTenEntity);

const skyboxReflectionProbeEntity = createEntity({
  skybox: components.skybox({ sunPosition: [2, 2, 2] }),
  reflectionProbe: components.reflectionProbe(),
  transform: components.transform(),
});
world.add(skyboxReflectionProbeEntity);

ctx.frame(() => {
  renderEngine.update(world.entities);
  renderEngine.render(
    world.entities,
    world.entities.filter((entity) => entity.camera)
  );

  window.dispatchEvent(new CustomEvent("pex-screenshot"));
});

Screenshot 2023-10-18 at 12 51 13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant