Giter Site home page Giter Site logo

jnsmalm / pixi3d Goto Github PK

View Code? Open in Web Editor NEW
722.0 16.0 39.0 32.95 MB

The 3D renderer for PixiJS. Seamless integration with 2D applications.

Home Page: https://pixi3d.org

License: MIT License

TypeScript 74.06% JavaScript 13.57% GLSL 11.76% HTML 0.51% CSS 0.10%
pixijs 3d typescript javascript-library webgl renderer

pixi3d's Introduction

Pixi3D

Pixi3D is a 3D rendering library for the web. It's built on top of PixiJS (which is at it's core, an established 2D rendering library). This makes Pixi3D have seamless integration with already existing 2D applications.

  • Load models from file (glTF) or create procedural generated meshes
  • Physically-based rendering (PBR) and image-based lighting (IBL)
  • Customized materials and shaders
  • 3D sprites
  • Transformation, morphing and skeletal animations
  • Compatible with PixiJS v5, v6 and v7.

SPY-HYPERSPORT

"SPY-HYPERSPORT" (https://skfb.ly/o8z7t) by Amvall is licensed under Creative Commons Attribution (http://creativecommons.org/licenses/by/4.0/). Rendered using Pixi3D.

Production ready?

Yes, it's currently being used in multiple projects in production running on hundreds of thousands of different devices (both desktop and mobile).

Getting started

The easiest way to get started is to use the automatic setup which creates a simple project with everything needed to start immediatly. Node.js must be installed, go to https://nodejs.org to download.

Type in the following using the terminal/console:

npx create-pixi3d-app@latest my-pixi3d-app

After installation is complete, type cd my-pixi3d-app and npm start to start local web server.

Manual setup

Next, create a file app.js with the following contents.

let app = new PIXI.Application({
  backgroundColor: 0xdddddd, resizeTo: window, antialias: true
})
document.body.appendChild(app.view)

let mesh = app.stage.addChild(PIXI3D.Mesh3D.createCube())

let light = new PIXI3D.Light()
light.position.set(-1, 0, 3)
PIXI3D.LightingEnvironment.main.lights.push(light)

let rotation = 0
app.ticker.add(() => {
  mesh.rotationQuaternion.setEulerAngles(0, rotation++, 0)
})

Then create index.html and include the required scripts.

<!doctype html>
<html lang="en">
<body>
  <script type="text/javascript" src="pixi.js"></script>
  <script type="text/javascript" src="pixi3d.js"></script>
  <script type="text/javascript" src="app.js"></script>
</body>
</html>

Using npm

Pixi3D is also available as a npm package. Install the latest release with npm install pixi3d. This requires that an up-to-date version of Node.js is already installed.

If PixiJS v5 or v6 is used, import from pixi3d i.e. import { Model } from "pixi3d". If PixiJS v7 is used, instead import from pixi3d/pixi7 i.e. import { Model } from "pixi3d/pixi7".

Examples

Examples are available as sandboxes at https://codesandbox.io to quickly get started. Download repo at https://github.com/jnsmalm/pixi3d-sandbox to instead run them locally.

Example Description Sandbox
Getting started Create application, rotating cube View
Standard material Load glTF model, image-based lighting, physically-based rendering View
Animation Model animation, dynamic shadows View
Custom material Custom material/shader View
Sprites Billboard sprites in 3D space View
Punctual lights Directional light, spot light, point light View
Custom geometry Mesh with custom vertex attributes View
Interaction Mesh picking View
Post processing Post processing sprite with filters View

Quick guide

An introduction to Pixi3D and a overview of the core concepts and components. Go to the Quick guide sandbox to view a real-time demo of the scene created with this guide.

Creating an application

The quickest way to get started is by creating an PixiJS application object. The application object creates a renderer and automatically starts the render loop. It also creates a canvas element which should be added to the HTML document.

let app = new PIXI.Application({
  resizeTo: window, backgroundColor: 0xdddddd, antialias: true
});
document.body.appendChild(app.view);

Creates an application and adds the canvas element which results in an empty page with a grey background.

Loading a 3D model

A model includes a hierarchy of 3D objects which are called meshes. A mesh contains the geometry and material used for rendering that object. Models are generally being loaded from a file which has been created in a 3D modeling tool like Maya or Blender. Pixi3D supports loading of models using the glTF 2.0 file format. Learn more about glTF at https://www.khronos.org/gltf/

Loading a model is different depending on the PixiJS version used. This is how to do it when using PixiJS v5 or v6.

app.loader.add(
  "teapot.gltf",
  "https://raw.githubusercontent.com/jnsmalm/pixi3d-sandbox/master/assets/teapot/teapot.gltf"
);

app.loader.load((_, resources) => {
  setup(resources["teapot.gltf"].gltf);
})

function setup(gltf) {
  let teapot = app.stage.addChild(PIXI3D.Model.from(gltf));
}

This is how to do it when using PixiJS v7.

// Using a self executing function just to make the different methods more comparable.
(async function load() {
  let gltf = await PIXI.Assets.load("https://raw.githubusercontent.com/jnsmalm/pixi3d-sandbox/master/assets/teapot/teapot.gltf")
  setup(gltf)
})()

function setup(gltf) {
  let teapot = app.stage.addChild(PIXI3D.Model.from(gltf));
}

Loads a glTF 2.0 file and creates a model. The silhouette of a teapot should appear. For now, it will be rendered black because there is no lighting.

Position, rotation and scale

All objects in a scene have a transform which is used for setting the position, rotation and scale of that object. The transform of an object is always relative to it's parent transform. So when changing the transform of the parent object, all of it's childrens transforms will be affected as well.

Both position and scale is represented by a vector with three components (x, y, z), one for each axis. Rotation is represented by a quaternion and has four components (x, y, z, w). A quaternion is not as straight forward to use as a vector, and because of that the method setEulerAngles is used to change the rotation.

teapot.position.y = -1;
teapot.scale.set(1.2);
teapot.rotationQuaternion.setEulerAngles(0, 15, 0);

Moves the model to -1 on the y-axis. Rotates it to 15 degrees on the y-axis and scales it on all axes.

Lighting environment

Lights are needed to illuminate the objects in the scene, otherwise they may be rendered completely black (depending on the material being used). A lighting environment contains the different components used for lighting a scene. The lighting environment can be shared across objects, or each object can have it's own. The main lighting environment is created and used by default.

There are a few different types of lights available. The "point" type is a light that is located at a point and emits light in all directions equally. The "directional" type is a light that is located infinitely far away, and emits light in one direction only. The "spot" type is a light that is located at a point and emits light in a cone shape. Lights have a transform and can be attached to other objects.

let dirLight = new PIXI3D.Light();
dirLight.type = "directional";
dirLight.intensity = 0.5;
dirLight.rotationQuaternion.setEulerAngles(45, 45, 0);
dirLight.position.set(-4, 7, -4);
PIXI3D.LightingEnvironment.main.lights.push(dirLight);

let pointLight = new PIXI3D.Light();
pointLight.type = "point";
pointLight.intensity = 10;
pointLight.position.set(1, 0, 3);
PIXI3D.LightingEnvironment.main.lights.push(pointLight);

Adds a directional light and a point light to the main lighting environment. The teapot should now be illuminated by the light.

Changing the material

Each mesh contains a material, and the standard material is used by default. The standard material has several properties which can be used for changing the appearance of a mesh. It's also possible to create custom materials to achieve almost any visual effect.

teapot.meshes.forEach((mesh) => {
  mesh.material.baseColor = PIXI3D.Color.fromHex("#ffefd5");
});

Gives the model a different color by setting the material color of each mesh.

Playing animations

Models can contain animations which has been created in a 3D modeling tool. There are three different kinds of animations: skeletal, morphing and transformation. Skeletal animation is often used for animating characters, but it can also be used to animate anything else as well. Morphing is used to animate per-vertex, for example to create a waving flag or a face expression. Transformation animations are used for moving, rotating and scaling entire objects.

setInterval(() => {
  teapot.animations.forEach((anim) => anim.play());
}, 1500);

Starts playing all animations in the model every 1.5 seconds.

Casting shadows

To enable lights to cast shadows, a shadow casting light is required. It wraps a light and gives it the ability to cast shadows. It has multiple settings for controlling the quality of the shadow, for example the size of the shadow texture and the softness of the shadow. Directional and spot light types have support for casting shadows.

let ground = app.stage.addChild(PIXI3D.Mesh3D.createPlane());
ground.y = -1;
ground.scale.set(10);

Creates a ground plane to have something to cast the shadows on.

The shadows must also be enabled (using the standard pipeline) for an object to both receive and cast shadows.

let shadowCastingLight = new PIXI3D.ShadowCastingLight(app.renderer, dirLight, {
  shadowTextureSize: 512,
  quality: PIXI3D.ShadowQuality.medium
});
shadowCastingLight.softness = 1;
shadowCastingLight.shadowArea = 8;

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

Enables shadows to be casted and received for both the model and the ground.

2D and 3D

Compositing 2D (PixiJS) and 3D (Pixi3D) containers is simple and can be combined in many ways. 2D containers can be added on top of 3D containers, and the other way around. Although the containers can be combined, the transforms used by 2D and 3D works differently from each other and are not compatible. The transforms won't be affected by each other, even if they have a parent-child relation.

To be able to convert 3D coordinates to 2D coordinates (or the other way around) the camera methods screenToWorld and worldToScreen can be used.

Another way of combining 2D and 3D objects is to render a 3D object as a sprite using CompositeSprite. Thay way, the 3D object can easily be positioned in 2D space. This method also makes it possible to use regular PixiJS filters with 3D objects.

let vignette = app.stage.addChild(
  PIXI.Sprite.from(
    "https://raw.githubusercontent.com/jnsmalm/pixi3d-sandbox/master/assets/vignette.png"
  )
);

app.ticker.add(() => {
  Object.assign(vignette, {
    width: app.renderer.width, height: app.renderer.height
  });
});

Adds a 2D vignette layer on top of the 3D scene to give it a more cinematic effect. Resizes the vignette to the size of the renderer.

Controlling the camera

The camera is used for controlling from which position and direction the 3D scene is rendered, it has a position and rotation which is used for changing the view. Like any other object which has a transform, it can be attached to another object. The camera can also be directly controlled by using a mouse or trackpad. The main camera is created and used by default.

let control = new PIXI3D.CameraOrbitControl(app.view)

Gives the user orbit control over the main camera using mouse/trackpad. Hold left mouse button and drag to orbit, use scroll wheel to zoom in/out.

API

The API documentation is available at https://api.pixi3d.org

Changelog

All notable changes to this project will be documented in the changelog

Development

For developing new features or fixing bugs, use serve/src/index.js with npm start.

Tests

Automatic tests can run both using Puppeteer (Headless Chrome) and on a specific device/browser. Run command npm test to execute tests using Puppeteer or start local web server with npm run test:browser and go to http://localhost:8080/. Before running tests, build using npm run build.

Building

Build to dist folder with npm run build.

pixi3d's People

Contributors

bigtimebuddy avatar choephix avatar cqh963852 avatar goldenratio avatar gordontombola avatar jnsmalm avatar lovelle-cardoso avatar nevermemo avatar nous- avatar vujadin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pixi3d's Issues

3D particles support

Hi there, it's me again. I was wondering is the a way to use particles in 3d space. Example: the particles goes around a cylinder.
Thanks in advance.

pixi3d destroy

import { Mesh3D, Light, LightingEnvironment } from "pixi3d";

app.desdory(); // error.
โ†“
AbstractRenderer.prototype.destroy = function (removeView) {
for (var o in this.plugins) {
this.plugins[o].destroy(); // Here! this.plugins['lighting'].destroy is undefined. and this.plugins['picking'].destroy.
this.plugins[o] = null;
}
.
.
.
}

Plane Normals In GLTF - Cannon ConvexPolyhedron from Model

Hi there!
I want to implement deterministic dice rolling with a physics engine and I wonder, how I can identify the side of the dice, which is on top. Ideally, I would have some named normals, to compare this with the up vector. But I have no idea, if this is possible with GLTF.

EDIT: I want this not only for six sides dies, but also for dice with 8, 10, 12 and 20 sides.

Do you have any ideas, how I could identify the sides of a loaded model?

Regards
Jonas

Combining meshes and rotating them?

First of all, great work! Let's say there are three cubes stacked on top of each other or some more complex geometry. How is it possible to group them into one single mesh (to later rotate the mesh)? There is not much to be found about combining 3d meshes in the examples. Thanks

const c1 = app.stage.addChild(Mesh3D.createCube());
const c2 = app.stage.addChild(Mesh3D.createCube());
const c3 = app.stage.addChild(Mesh3D.createCube());

// ..? Combine & rotate c1,c2,c3 as one mesh?

Please change comments in code as they enter the copyright realm!

We're building a project with Webpack we use Terser (newer uglyjs lib) to compress all javascript. Terser extracts all copyright info and put it nicely in a copyright file so the copyright info doesn't get lost and is for willingly to read.

This works fine for all libs we use as they all have their copyright information behind comments starting with /*!.

However, pixi3d is using the same prefix for a whole bunch of comments in the javascript, resulting all kinds of junk being included in the copyright file now, so users see this in the copyright file, coming from pixi3d, which is obviouly not copyright information:
image

You might understand we don't like this and want to ask you if you could replace these 'copyright'-prefixes with normal comment prefixes, like / or /*. On the other hand you could also add your copyright information in there WITH the given 'copyright' (/*! ) prefix so it gets included in there.
For you this would probably mean 5 minutes of work, but for us it's basically impossible to strip it out as it's all being done automatically by terser on each webpack build.

Could you please change these comment prefixes?

Thanks in advance!

General Question: 3D GUI Generator

Hello @jnsmalm

AWESOME project of yours... One of my biggest dreams and challenges of 3D has always been to build a 3D user interface that combines the power of pixi.js, the beauty of 3D (like this library of yours) and combining HTML5 elements that can be brought to life and animated under these set of tools.

Is there a way to achieve this as of today?

Can you make this happen or recommend additional libraries that can allow me to put this all together?

Thanks and Congrats on your project!

Camera translations

Hey, thank you for this extremely cool api. After 5 days head banging, I found that I need to take into account the pixi's renderer resolution in order to make the camera coord conversion to work as it should.
Here are the wrapped methods (I am not sure 100% about the z values, because I do not need z at all in my app).

public static toWorld(
        container: Container,
        anchor: Point,
        model: Model
    ): ObservablePoint3D {
        let bounds = container.getBounds();
        let x = bounds.x + anchor.x * bounds.width;
        let y = bounds.y + anchor.y * bounds.height;
        return this.screenToWorld(x, y, model);
    }

    public static screenToWorld(
        x: number,
        y: number,
        model: Model
    ): ObservablePoint3D {
        let worldCoordinates = Camera.main.screenToWorld(
            x,
            y,
            Camera.main.z - model.z,
            undefined,
            {
                width:
                    App.instance.renderer.width /
                    App.instance.renderer.resolution,
                height:
                    App.instance.renderer.height /
                    App.instance.renderer.resolution,
            }
        );

        return worldCoordinates;
    }

    public static worldToScreen(
        x: number,
        y: number,
        z: number = Camera.main.z
    ): Point {
        let worldCoordinates = Camera.main.worldToScreen(x, y, z, undefined, {
            width:
                App.instance.renderer.width / App.instance.renderer.resolution,
            height:
                App.instance.renderer.height / App.instance.renderer.resolution,
        });

        return worldCoordinates;
    }

I hope this helps and it will save time to someone using your api.

Thanks,
Ivan

Invalid typed array length

I got this error when loading the model:

RangeError: Invalid typed array length: 20
    at new Float32Array (&lt;anonymous&gt;)
    at Function.e.from (pixi3d.min.js:17:212373)
    at e.parseBuffer (pixi3d.min.js:17:199160)
    at e.parsePrimitive (pixi3d.min.js:17:204392)
    at pixi3d.min.js:17:203825
    at Array.map (&lt;anonymous&gt;)
    at e.parseMesh (pixi3d.min.js:17:203785)
    at c (pixi3d.min.js:17:206008)
    at c (pixi3d.min.js:17:206399)
    at e.parseModel (pixi3d.min.js:17:206588)

glTF version 2.0
Generator: Created using the official Cinema 4D glTF Exporter 1.000x284978

shadow casting

First of all: really great addOn !!! I am amazed how well it works. I tried the demo. i recognized, the drone-object doesnt cast shadows on it self and on the floor. Is it possible to implement shadows ?

'highp' : precision is not supported in fragment shader

This is error from an old android 7.0 device (Infinix Hot 5 Lite). I solved this issue by setting 'mediump' precision for fragment shaders - you should probably use PIXI.settings.PRECISION_FRAGMENT value (its 'mediump' by default but I think they determine its value at runtime ??). Pixi also has PRECISION_VERTEX (https://pixijs.download/dev/docs/PIXI.settings.html#PRECISION_VERTEX).

Then another problem happened as 3D models were not visible with this warning in console:
unsupported index buffer type: uint32
Provided WebGL context does not support 32 index buffer, complex graphics may not render correctly

This was also solved by using Uint16Array (in only 2 places, I've done both of these changes in generated js file).
So check for Uint32Array support would be good too.

How to get and control main camera?

Hi, I'm working on fake 3D and sprite stacks with GDevelop (Game engine with pixi as core)
I'm trying put some 3D object on canvas, just a cube to follow a 2D cube
I create a cube and put as child of 2D, but when I move a scene, the 3D camera stucks
I try create a new Camera() for renderer but when I update positions nothing happens

Imgur

this is possible?

Skybox unable to recover from GL context loss

If the webgl context is lost, the texture for skyboxes becomes non-renderable and throws a multitude of webgl errors. This does not happen for normal meshes. As far as I can tell, this may be an issue with the pixi.js CubeResource, but given your overrides, I wasn't sure if this is necessarily the case. It seems that the textures don't properly upload the second time, because they aren't marked dirty on a context loss?

Raycasting world mouse position on a ground plane in orthographic (isometric) mode

Hey again.

I have been having fun experimenting with Pixi3D.

I succeeded in getting the world mouse position of a 3d ground plane with this code:

		var normal = new PIXI3D.Vec3.fromValues(0, 1, 0)
		var plane = new PIXI3D.Plane(normal, 0.01)
		var ray = PIXI3D.Camera.main.screenToRay(MouseX, MouseY)
		var raycast = plane.rayCast(ray);
		var point = ray.getPoint(raycast)

But it doesn't seem to work in orthographic mode. Only in perspective.

Is there anything I have to change for it to work in orthographic mode?

Please let me know if you need a working example or more code.

Thanks!

Greetings from pixi-projection!

Subj.

I'm looking at your progress, and maybe i'll try to merge something with my architecture at pixi-projection. My project lacks glTF and actual 3d model support, but my ideas with containers and architecture surely can help.

For example, I know by experience that swapping 2d position to 3d in the same field can lead to many problems.

Height map example?

First off good work. But is there a way to do height maps w/ this library? Looking to procedurally generate some terrain...

How to use pixi3d with pixi-viewport?

Hi,

First of all; great work! This is a very nice piece of tool to be able to use 3d inside pixi! Thanks a lot for this!

At the moment I'm learning all features of it. I'm stumbling on one thing though I can't find the answer to so far:
When adding the Model as a child of a pixi-viewport Container (which does scaling, dragging and all kind of cool stuff to navigate a 2d scene), the Model isn't moving with it. This does work with other display objects, but unfortunately not with a pixi3d model. At least I can't get it to work here.

How can we make the Model move and scale with the viewport (preferrably by not changing anything in the 3d object/scene nor the camera, so only its 2d 'render' output)

Create Model3Ds from Submeshes?

Hi!
I am loading a GLTF with six dice models as separate meshes inside. That works well. But I need those 6 meshes as separate Models, because they must be animated independently.
Simply setting the transforms on the children of the model works somehow, but the lighting on the material is not updated while animating, besides other transformation issues ....
I tried something like

const subModel = new PIXI3D.Model();
subModel.meshes.push(mesh.children[0].children[0]);
const dob = pixiApp.app.stage.addChild(subModel)

This does simply nothing. Is there a way to create a Model from a "sub"mesh?

Typescript definition not compatible with Pixi v5.3.7

Can you please advice on how to resolve this?
Versions:

"pixi.js-legacy": "5.3.7",
"pixi3d": "^0.9.8",

node_modules/pixi3d/types/camera/camera-orbit-control.d.ts:15:19 - error TS2315: Type 'ObservablePoint' is not generic.

15     get angles(): PIXI.ObservablePoint<undefined>;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/pixi3d/types/camera/camera.d.ts:26:38 - error TS2694: Namespace 'PIXI' has no exported member 'IDestroyOptions'.

26     destroy(options?: boolean | PIXI.IDestroyOptions): void;
                                        ~~~~~~~~~~~~~~~

node_modules/pixi3d/types/container.d.ts:9:5 - error TS2416: Property 'transform' in type 'Container3D' is not assignable to the same property in base type 'Container'.
  Type 'Transform3D' is not assignable to type 'Transform'.
    Types of property 'worldTransform' are incompatible.
      Type 'TransformMatrix' is not assignable to type 'Matrix'.

9     transform: Transform3D;
      ~~~~~~~~~

node_modules/pixi3d/types/container.d.ts:10:9 - error TS2611: 'position' is defined as a property in class 'Container', but is overridden here in 'Container3D' as an accessor.

10     set position(value: ObservablePoint3D);
           ~~~~~~~~

node_modules/pixi3d/types/container.d.ts:12:9 - error TS2611: 'scale' is defined as a property in class 'Container', but is overridden here in 'Container3D' as an accessor.

12     set scale(value: ObservablePoint3D);
           ~~~~~

node_modules/pixi3d/types/container.d.ts:21:9 - error TS2416: Property 'localTransform' in type 'Container3D' is not assignable to the same property in base type 'Container'.
  Type 'TransformMatrix' is not assignable to type 'Matrix'.

21     get localTransform(): import(".").TransformMatrix;
           ~~~~~~~~~~~~~~

node_modules/pixi3d/types/container.d.ts:21:9 - error TS2611: 'localTransform' is defined as a property in class 'Container', but is overridden here in 'Container3D' as an accessor.

21     get localTransform(): import(".").TransformMatrix;
           ~~~~~~~~~~~~~~

node_modules/pixi3d/types/container.d.ts:22:9 - error TS2416: Property 'worldTransform' in type 'Container3D' is not assignable to the same property in base type 'Container'.
  Type 'TransformMatrix' is not assignable to type 'Matrix'.

22     get worldTransform(): import(".").TransformMatrix;
           ~~~~~~~~~~~~~~

node_modules/pixi3d/types/container.d.ts:22:9 - error TS2611: 'worldTransform' is defined as a property in class 'Container', but is overridden here in 'Container3D' as an accessor.

22     get worldTransform(): import(".").TransformMatrix;
           ~~~~~~~~~~~~~~

node_modules/pixi3d/types/cubemap/cubemap.d.ts:8:38 - error TS2315: Type 'BaseTexture' is not generic.

8 export declare class Cubemap extends PIXI.BaseTexture<CubemapResource> {
                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/pixi3d/types/gltf/gltf-asset.d.ts:48:51 - error TS2724: 'PIXI' has no exported member named 'ILoaderResource'. Did you mean 'LoaderResource'?

48     load(uri: string, onComplete: (resource: PIXI.ILoaderResource) => void): void;
                                                     ~~~~~~~~~~~~~~~

node_modules/pixi3d/types/instanced-model.d.ts:8:37 - error TS2694: Namespace 'PIXI' has no exported member 'DestroyOptions'.

8     destroy(options: boolean | PIXI.DestroyOptions | undefined): void;
                                      ~~~~~~~~~~~~~~

node_modules/pixi3d/types/lighting/image-based-lighting.d.ts:13:17 - error TS2315: Type 'Texture' is not generic.

13     get brdf(): PIXI.Texture<PIXI.Resource>;
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/pixi3d/types/lighting/image-based-lighting.d.ts:13:35 - error TS2724: 'PIXI' has no exported member named 'Resource'. Did you mean 'resources'?

13     get brdf(): PIXI.Texture<PIXI.Resource>;
                                     ~~~~~~~~

node_modules/pixi3d/types/lighting/lighting-environment.d.ts:8:58 - error TS2694: Namespace 'PIXI' has no exported member 'IRendererPlugin'.

8 export declare class LightingEnvironment implements PIXI.IRendererPlugin {
                                                           ~~~~~~~~~~~~~~~

node_modules/pixi3d/types/loader/gltf-binary-loader.d.ts:3:26 - error TS2724: 'PIXI' has no exported member named 'ILoaderResource'. Did you mean 'LoaderResource'?

3     use: (resource: PIXI.ILoaderResource, next: () => void) => void;
                           ~~~~~~~~~~~~~~~

node_modules/pixi3d/types/loader/gltf-loader.d.ts:3:26 - error TS2724: 'PIXI' has no exported member named 'ILoaderResource'. Did you mean 'LoaderResource'?

3     use: (resource: PIXI.ILoaderResource, next: () => void) => void;
                           ~~~~~~~~~~~~~~~

node_modules/pixi3d/types/mesh/instanced-mesh.d.ts:8:37 - error TS2694: Namespace 'PIXI' has no exported member 'IDestroyOptions'.

8     destroy(options: boolean | PIXI.IDestroyOptions | undefined): void;
                                      ~~~~~~~~~~~~~~~

node_modules/pixi3d/types/picking/picking-manager.d.ts:9:53 - error TS2694: Namespace 'PIXI' has no exported member 'IRendererPlugin'.

9 export declare class PickingManager implements PIXI.IRendererPlugin {
                                                      ~~~~~~~~~~~~~~~

node_modules/pixi3d/types/pipeline/standard-pipeline.d.ts:49:5 - error TS2416: Property 'render' in type 'StandardPipeline' is not assignable to the same property in base type 'ObjectRenderer'.
  Type '(mesh: Mesh3D) => void' is not assignable to type '(object: DisplayObject) => void'.
    Types of parameters 'mesh' and 'object' are incompatible.
      Type 'DisplayObject' is missing the following properties from type 'Mesh3D': geometry, pluginName, enabledRenderPasses, _instances, and 34 more.

49     render(mesh: Mesh3D): void;
       ~~~~~~

node_modules/pixi3d/types/pixi/array-resource.d.ts:2:49 - error TS2339: Property 'ArrayResource' does not exist on type 'typeof PIXI'.

2 export declare const ArrayResource: typeof PIXI.ArrayResource;
                                                  ~~~~~~~~~~~~~

node_modules/pixi3d/types/pixi/cube-resource.d.ts:2:48 - error TS2339: Property 'CubeResource' does not exist on type 'typeof PIXI'.

2 export declare const CubeResource: typeof PIXI.CubeResource;
                                                 ~~~~~~~~~~~~

node_modules/pixi3d/types/sprite/post-processing-sprite.d.ts:27:25 - error TS2315: Type 'BaseTexture' is not generic.

27     get depthTexture(): PIXI.BaseTexture<PIXI.Resource, PIXI.IAutoDetectOptions> | undefined;
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/pixi3d/types/sprite/post-processing-sprite.d.ts:27:47 - error TS2724: 'PIXI' has no exported member named 'Resource'. Did you mean 'resources'?

27     get depthTexture(): PIXI.BaseTexture<PIXI.Resource, PIXI.IAutoDetectOptions> | undefined;
                                                 ~~~~~~~~

node_modules/pixi3d/types/sprite/post-processing-sprite.d.ts:27:62 - error TS2694: Namespace 'PIXI' has no exported member 'IAutoDetectOptions'.

27     get depthTexture(): PIXI.BaseTexture<PIXI.Resource, PIXI.IAutoDetectOptions> | undefined;
                                                                ~~~~~~~~~~~~~~~~~~

node_modules/pixi3d/types/transform/observable-point.d.ts:22:9 - error TS2611: 'x' is defined as a property in class 'ObservablePoint', but is overridden here in 'ObservablePoint3D' as an accessor.

22     get x(): number;
           ~

node_modules/pixi3d/types/transform/observable-point.d.ts:27:9 - error TS2611: 'y' is defined as a property in class 'ObservablePoint', but is overridden here in 'ObservablePoint3D' as an accessor.

27     get y(): number;
           ~

node_modules/pixi3d/types/transform/observable-quaternion.d.ts:21:9 - error TS2611: 'x' is defined as a property in class 'ObservablePoint', but is overridden here in 'ObservableQuaternion' as an accessor.

21     get x(): number;
           ~

node_modules/pixi3d/types/transform/observable-quaternion.d.ts:24:9 - error TS2611: 'y' is defined as a property in class 'ObservablePoint', but is overridden here in 'ObservableQuaternion' as an accessor.

24     get y(): number;
           ~

node_modules/pixi3d/types/transform/transform-matrix.d.ts:28:5 - error TS2416: Property 'toArray' in type 'TransformMatrix' is not assignable to the same property in base type 'Matrix'.
  Type '(transpose: boolean, out?: Float32Array | undefined) => Float32Array' is not assignable to type '(transpose: boolean, out?: Float32Array | undefined) => number[]'.
    Type 'Float32Array' is missing the following properties from type 'number[]': pop, push, concat, shift, and 5 more.

28     toArray(transpose: boolean, out?: Float32Array): Float32Array;
       ~~~~~~~

node_modules/pixi3d/types/transform/transform-matrix.d.ts:47:5 - error TS2416: Property 'copyFrom' in type 'TransformMatrix' is not assignable to the same property in base type 'Matrix'.
  Type '(matrix: TransformMatrix) => this' is not assignable to type '(matrix: Matrix) => Matrix'.
    Types of parameters 'matrix' and 'matrix' are incompatible.
      Type 'Matrix' is missing the following properties from type 'TransformMatrix': _transformId, transformId, array, position, and 10 more.

47     copyFrom(matrix: TransformMatrix): this;
       ~~~~~~~~

node_modules/pixi3d/types/transform/transform.d.ts:16:5 - error TS2416: Property 'worldTransform' in type 'Transform3D' is not assignable to the same property in base type 'Transform'.
  Type 'TransformMatrix' is not assignable to type 'Matrix'.
    Types of property 'toArray' are incompatible.
      Type '(transpose: boolean, out?: Float32Array | undefined) => Float32Array' is not assignable to type '(transpose: boolean, out?: Float32Array | undefined) => number[]'.

16     worldTransform: TransformMatrix;
       ~~~~~~~~~~~~~~

node_modules/pixi3d/types/transform/transform.d.ts:18:5 - error TS2416: Property 'localTransform' in type 'Transform3D' is not assignable to the same property in base type 'Transform'.
  Type 'TransformMatrix' is not assignable to type 'Matrix'.

18     localTransform: TransformMatrix;
       ~~~~~~~~~~~~~~

node_modules/pixi3d/types/transform/transform.d.ts:31:5 - error TS2416: Property 'setFromMatrix' in type 'Transform3D' is not assignable to the same property in base type 'Transform'.
  Type '(matrix: TransformMatrix) => void' is not assignable to type '(matrix: Matrix) => void'.
    Types of parameters 'matrix' and 'matrix' are incompatible.
      Type 'Matrix' is not assignable to type 'TransformMatrix'.

31     setFromMatrix(matrix: TransformMatrix): void;
       ~~~~~~~~~~~~~


Found 34 errors.

Framebuffer is incomplete: Attachments are not all the same size.

Using PostProcessingSprite() sometimes the sprite just doesn't get rendered. It's than throwing these kinde of errors:
image

I'm not using any textures on the 3d model, so it seems like it's talking about the PostProcessingSprite itself as being a texture.

I believe I've seen other people with the same error message on the pixi github, but I can't find it nowhere anymore and even then to me and I believe also to them it was completely unclear what was causing this and how this could even be worked around. I'm trying to debug this at the moment.

Any clue on what could cause this issue to happen? Could it be related to using the PostProcessingSprite's resolution, width or height settings? Does this even have anything to do with textures? Or could it even be something else completely?

Example.js is missing

I wanted to test this out but it seems the .js file is missing in the examples folder.
Index.html:
<script src="example.js"></script>

Unable to load certain gltf (.glb) models

Unable to load these models, getting runtime error as described below.
https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Lantern/glTF-Binary
https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/BarramundiFish/glTF-Binary

pixi3d version: 1.1.1

Please note:
I was able to load these models in v0.9.8. Any help is appreciated.

pixi3d.js:10145 Uncaught TypeError: Cannot read properties of undefined (reading 'baseTexture')
    at glTFParser../src/gltf/gltf-parser.ts.glTFParser.parseTexture (pixi3d.js:10145)
    at new glTFParser (pixi3d.js:9965)
    at Function../src/gltf/gltf-parser.ts.glTFParser.createModel (pixi3d.js:9974)
    at Function../src/model.ts.Model.from (pixi3d.js:13325)
    at PixiGLTFManager.getModel (pixi-gltf-manager.ts:67)
    at showGTLFModel (index.ts:68)
    at index.ts:261
    at SafeSubscriber._next (pixi-gltf-manager.ts:41)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:192)
    at SafeSubscriber.next (Subscriber.js:130)

Beginner questions

Hi Guys
This is not really an issue but I have trouble understanding the documentation so I am asking 3 three questions.

I am writing a game with Pixi.js this week and I am enjoying it.
Now I'd like to add a little bit of 3D.
On the photo below, I'd like the entire floor to be skewed to a trapeze while the tree, the characters and various fences stay upward.
I installed pixi3D and managed to display some 3D elements:

I can see a blank cube extracted from your getting started page.
It got me started. Thanks cube.
Then I can see a plane with a grass texture and a quad with a tree texture.
I use a StandardMaterial and set the baseColorTexture to my tree Pixi (classic) texture.
The texture was created from a basetexture that contains multiple images.
It looks like the Standard Material and quad is showing the entire texture and not the small portion of it.

So my first question is :
(1) How can I make the quad only display the top left quarter of the texture.

My second question is:
My floors are composed of 1 to 5 semi transparent textures on top of each other. Sometimes they are animated (the water is).
(2) how I can create a quad to show 4 or 5 textures.

Third and last question.
(3) I expect to display up to 2000 tiles on the screen adding more and deleting others as the player moves and the camera with it.

Does it seem realistic to you?
Do you think Pixi3D is a good match for what I am trying to do?

I am not sure you'll have the time to reply, in any case thank you for your good work.

pixi3d-question

Remove the PostProcessingSprite handler from the shared ticker

Thank you for this great library. I am using it in the context of a Single Page Application (SPA), in which I need to create and destroy several PIXI apps within the lifecycle of the SPA. I noticed that the handler added by a PostProcessingSprite instance on this line is an anonymous function, which makes it pretty much impossible to remove from the PIXI shared ticker. This causes an error when destroying PIXI apps with PostProcessingSprite instances and creating other PIXI apps within the SPA.

When I encountered the error the first time I initially expected that by destroying the PostProcessingSprite instance the handler would be removed. Perhaps this could be a good solution without introducing breaking changes? That is, having the anonymous function to be a named function, which on destroying the sprite could now be removed from the shared ticker. Or perhaps there is another solution?

Thanks in advance!

Is it possible to use spritesheet textures?

Hello I have a problems with the model textures. If the texture comes from a spritesheet, the model displays the whole spritesheet instead of the proper texture. Here is the code, which I am using. Note that everything works perfectly fine, if I pass a 'standalone' texture.

    public setTexture(meshIndex: number, texture: Texture) {
        let mat = this.model.meshes[meshIndex].material as StandardMaterial;
        mat.baseColorTexture = texture;
    }

PIXI v6

When using PIXI v6 there seems to be an issue with the depth buffer:

image

image

Can not even get started

Hello!
I am trying to load the drone demo, but no luck so far. I am using pixi 5.3.9 and this code does not seem to work.
Unfortunately I can't update pixi to v6, because the project is huge and this will take days and days.

`app.loader.add("assets/buster_drone/scene.gltf")

app.loader.load((loader, resources) => {
let model = app.stage.addChild(
PIXI3D.Model.from(resources["assets/buster_drone/scene.gltf"].gltf))
})`

the property gltf is always undefined (it is even missing, because the resource is of type Resource).
I noticed that there is a static method for loading gltf from array, but I did not try this yet. I guess I should load the bin or the model file there?

Thanks for your time.

Edit. I just tried the 3d cube code. It does not work for me too. Idk what's wrong since Mesh3D extends DisplayObject.
image

Maybe I am missing some npm package?

Edit2: The cube works with a hack. I cast the cube to any, then to DisplayObject and the code compiles and runs.

Lights don't work if added after app has started

It looks like lights can't be added after app has started rendering loop.
This can be easily replicated in 'lighting' example if you delay creation of lights a bit:

let app = new PIXI.Application({
  backgroundColor: 0xdddddd, resizeTo: window, antialias: true
})
document.body.appendChild(app.view)

let mesh = app.stage.addChild(PIXI3D.Mesh3D.createCube())
mesh.rotationQuaternion.setEulerAngles(0, 30, 0)

setTimeout(function() {
	let pointLight = Object.assign(new PIXI3D.Light(), {
	  x: 1.1, y: 0.2, z: 2.0, color: [1, 0, 0], intensity: 10, type: PIXI3D.LightType.point,
	})
	PIXI3D.LightingEnvironment.main.lights.push(pointLight)
}, 10); 

Events listners in models and custom camera (creating and moving)

Hi,

I need to listen to DOM Events in each model that i created (model creation on code below)

async renderTerrain() {
    for (let line = 0; line < this.#lines; line++) {
      for (let column = 0; column < this.#columns; column++) {
        const tile = new GameTile();
        await tile.loadAsset();
        tile.renderAsset();

        tile.mesh.position.x = line * 1.9;
        tile.mesh.position.z = column * 2;
        tile.mesh.meshes[1].alpha = 1;

        tile.mesh.interactive = true;
        tile.mesh.on('mouseover', (event) => {
          console.log('ok');
        });
      }
    }
  }

I tried to folow the following documentation (https://api.pixi3d.org/classes/model.html#interactivechildren) but without any success.

My goal is hide one mesh with alpha setted as 0 and when mouse hover this specific model, this mesh that was previously hide show again (only when hovering)

I'm also with some dificultes with the creation of custom cameras, for now i'm using the default internal camera created in CameraOrbitControl method. But i need create some cameras with specific world positions and angles and i couldn't create following the documentation

There is a print from working render from the code above
image

How to detect collisions?

Hello,

Thanks for providing this library, we're trying to migrate our game prototype from 2D to 3D and your library seems great for this purpose!

I was able to show some objects but I don't understand how I should do collision detection. With 2D we would use the object's position with its texture's width and height properties, but there is no texture in a Model object (I have limited knowledge in game dev so this might be an obvious thing).

const drone = stage.addChild(Model.from(resources["drone"]!.gltf));

drone.animations[0]?.play();

console.log(drone.width, drone.height) // => 0 0
console.log(drone.texture) // => undefined

What do you recommend to implement collision detection?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.