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

Fix the problem of abnormal status when pointer script reports a… #1945

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cptbtptpbcptdtptp
Copy link
Collaborator

import {
  BlinnPhongMaterial,
  BoxColliderShape,
  Camera,
  MeshRenderer,
  PointLight,
  PrimitiveMesh,
  Script,
  StaticCollider,
  Entity,
  Vector3,
  WebGLEngine,
} from "@galacean/engine";
import { LitePhysics } from "@galacean/engine-physics-lite";

WebGLEngine.create({ canvas: "canvas", physics: new LitePhysics() }).then(
  (engine) => {
    engine.canvas.resizeByClientSize();
    const scene = engine.sceneManager.activeScene;
    const rootEntity = scene.createRootEntity("root");

    scene.ambientLight.diffuseSolidColor.set(1, 1, 1, 1);
    scene.ambientLight.diffuseIntensity = 1.2;

    const cameraEntity = rootEntity.createChild("camera");
    cameraEntity.addComponent(Camera);
    cameraEntity.transform.setPosition(10, 10, 10);
    cameraEntity.transform.lookAt(new Vector3(0, 0, 0));

    let light = rootEntity.createChild("light1");
    light.transform.setPosition(-8, -2, 8);
    light.addComponent(PointLight).intensity = 0.12;

    light = rootEntity.createChild("light2");
    light.transform.setPosition(8, -2, 0);
    light.addComponent(PointLight).intensity = 0.12;

    class ClickScript extends Script {
      onPointerClick() {
        console.log("TTTTT");
        throw "error";
      }
      onPointerUp() {
        console.log("not trigger");
      }
    }

    function createBox(x: number, y: number, z: number): Entity {
      const cubeSize = 2.0;
      const boxEntity = rootEntity.createChild("BoxEntity");
      boxEntity.transform.setPosition(x, y, z);

      const boxMtl = new BlinnPhongMaterial(engine);
      const boxRenderer = boxEntity.addComponent(MeshRenderer);
      boxMtl.baseColor.set(0.6, 0.3, 0.3, 1.0);
      boxRenderer.mesh = PrimitiveMesh.createCuboid(
        engine,
        cubeSize,
        cubeSize,
        cubeSize
      );
      boxRenderer.setMaterial(boxMtl);

      const boxCollider: StaticCollider =
        boxEntity.addComponent(StaticCollider);
      const boxColliderShape = new BoxColliderShape();
      boxColliderShape.size.set(cubeSize, cubeSize, cubeSize);
      boxCollider.addShape(boxColliderShape);
      return boxEntity;
    }
    createBox(3, 0, -3).addComponent(ClickScript);

    engine.run();
  }
);

@cptbtptpbcptdtptp cptbtptpbcptdtptp added bug Something isn't working Input Input related functions labels Jan 5, 2024
@cptbtptpbcptdtptp cptbtptpbcptdtptp self-assigned this Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Input Input related functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant