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

Compile errors when using @pixi/math-extras #173

Closed
Giacom opened this issue Apr 3, 2023 · 3 comments
Closed

Compile errors when using @pixi/math-extras #173

Giacom opened this issue Apr 3, 2023 · 3 comments

Comments

@Giacom
Copy link

Giacom commented Apr 3, 2023

When depending on and importing @pixi/math-extras, PIXI3D will produce these compile errors:

src/index.ts:43:36 - error TS2345: Argument of type 'Model' is not assignable to parameter of type 'DisplayObject'.
  The types of 'transform.position.normalize(...).magnitude' are incompatible between these types.
    Type 'number' is not assignable to type '() => number'.

43     let model = container.addChild(Model.from(assets.teapot));

src/index.ts:48:29 - error TS2554: Expected 0-2 arguments, but got 3.

48     ground.scale.set(10, 1, 10);
                                      ~~~~~~~~~~~~~~~~~~~~~~~~~
import { Assets } from "@pixi/assets";
import { autoDetectRenderer, Renderer } from "@pixi/core";
import { Container } from "@pixi/display";
import "@pixi/math-extras";
import { CameraOrbitControl, ImageBasedLighting, Light, LightingEnvironment, LightType, Mesh3D, Model, ShadowCastingLight, ShadowQuality } from "pixi3d/pixi7";

let renderer = autoDetectRenderer({
    backgroundColor: 0xdddddd,
    antialias: true,
    width: 1200,
    height: 800,
});
document.body.appendChild(renderer.view as HTMLCanvasElement);

const manifest = {
    bundles: [
        {
            name: "assets",
            assets: [
                {
                    name: "diffuse",
                    srcs: "assets/chromatic/diffuse.cubemap",
                },
                {
                    name: "specular",
                    srcs: "assets/chromatic/specular.cubemap",
                },
                {
                    name: "teapot",
                    srcs: "assets/teapot/teapot.gltf",
                },
            ],
        },
    ],
};

async function start(): Promise<void> {
    await Assets.init({ manifest });
    let assets = await Assets.loadBundle("assets");

    const container = new Container();

    let model = container.addChild(Model.from(assets.teapot));
    model.y = -0.8;

    let ground = container.addChild(Mesh3D.createPlane());
    ground.y = -0.8;
    ground.scale.set(10, 1, 10);

    LightingEnvironment.main.imageBasedLighting = new ImageBasedLighting(assets.diffuse, assets.specular);

    let directionalLight = new Light();
    directionalLight.intensity = 1;
    directionalLight.type = LightType.directional;
    directionalLight.rotationQuaternion.setEulerAngles(25, 120, 0);
    LightingEnvironment.main.lights.push(directionalLight);

    let shadowCastingLight = new ShadowCastingLight(renderer as Renderer, directionalLight, { shadowTextureSize: 1024, quality: ShadowQuality.medium });
    shadowCastingLight.softness = 1;
    shadowCastingLight.shadowArea = 15;

    let pipeline = renderer.plugins.pipeline;
    pipeline.enableShadows(ground, shadowCastingLight);
    pipeline.enableShadows(model, shadowCastingLight);

    let control = new CameraOrbitControl(renderer.view as HTMLCanvasElement);

    function render() {
        renderer.render(container);
        requestAnimationFrame(render);
    }

    requestAnimationFrame(render);
}

start();

Example Project
math-extra.zip

@Giacom Giacom changed the title Compile errors when using @pixi/math-extra Compile errors when using @pixi/math-extras Apr 3, 2023
@jnsmalm
Copy link
Owner

jnsmalm commented Apr 5, 2023

Thanks, I'll look into this!

@jnsmalm
Copy link
Owner

jnsmalm commented Apr 10, 2023

There is a type collision between math-extras and Pixi3D. Not sure what can be done right now. I guess you can do this:

let ground = app.stage.addChild(Mesh3D.createPlane() as unknown as DisplayObject) as unknown as Mesh3D

or

// @ts-ignore
let ground = app.stage.addChild(Mesh3D.createPlane())

@Giacom
Copy link
Author

Giacom commented Apr 11, 2023

Alright that's good to know! I'll probably just remove the dependency for now since PIXI3D has 3D versions of the functions I'd be using anyway.

@jnsmalm jnsmalm closed this as completed Apr 17, 2023
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

2 participants