Giter VIP home page Giter VIP logo

engine's Introduction

PlayCanvas WebGL Game Engine

API Reference | User Manual | Examples | Forum | Blog

PlayCanvas is an open-source game engine. It uses HTML5 and WebGL to run games and other interactive 3D content in any mobile or desktop browser.

NPM version Minzipped size Average time to resolve an issue Percentage of issues still open Twitter

English 中文 日本語 한글

Project Showcase

Many games and apps have been published using the PlayCanvas engine. Here is a small selection:

Seemore After The Flood Casino
Swooop dev Archer Flappy Bird
Car Star-Lord Global Illumination

You can see more games on the PlayCanvas website.

Users

PlayCanvas is used by leading companies in video games, advertising and visualization such as:
Animech, Arm, BMW, Disney, Facebook, Famobi, Funday Factory, IGT, King, Miniclip, Leapfrog, Mojiworks, Mozilla, Nickelodeon, Nordeus, NOWWA, PikPok, PlaySide Studios, Polaris, Product Madness, Samsung, Snap, Spry Fox, Zeptolab, Zynga

Features

PlayCanvas is a fully-featured game engine.

  • 🧊 Graphics - Advanced 2D + 3D graphics engine built on WebGL 1 & 2.
  • 🏃 Animation - Powerful state-based animations for characters and arbitrary scene properties
  • ⚛️ Physics - Full integration with 3D rigid-body physics engine ammo.js
  • 🎮 Input - Mouse, keyboard, touch, gamepad and VR controller APIs
  • 🔊 Sound - 3D positional sounds built on the Web Audio API
  • 📦 Assets - Asynchronous streaming system built on glTF 2.0, Draco and Basis compression
  • 📜 Scripts - Write game behaviors in Typescript or JavaScript

Usage

Here's a super-simple Hello World example - a spinning cube!

import * as pc from 'playcanvas';

const canvas = document.createElement('canvas');
document.body.appendChild(canvas);

const app = new pc.Application(canvas);

// fill the available space at full resolution
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);

// ensure canvas is resized when window changes size
window.addEventListener('resize', () => app.resizeCanvas());

// create box entity
const box = new pc.Entity('cube');
box.addComponent('model', {
  type: 'box'
});
app.root.addChild(box);

// create camera entity
const camera = new pc.Entity('camera');
camera.addComponent('camera', {
  clearColor: new pc.Color(0.1, 0.2, 0.3)
});
app.root.addChild(camera);
camera.setPosition(0, 0, 3);

// create directional light entity
const light = new pc.Entity('light');
light.addComponent('light');
app.root.addChild(light);
light.setEulerAngles(45, 0, 0);

// rotate the box according to the delta time since the last frame
app.on('update', dt => box.rotate(10 * dt, 20 * dt, 30 * dt));

app.start();

Want to play with the code yourself? Edit it on CodePen.

A full guide to setting up a local development environment based on the PlayCanvas Engine can be found here.

How to build

Ensure you have Node.js installed. Then, install all of the required Node.js dependencies:

npm install

Now you can run various build options:

Command Description Outputs To
npm run build Build all engine flavors and type declarations build
npm run docs Build engine API reference docs docs

PlayCanvas Editor

The PlayCanvas Engine is an open-source engine that you can use to create HTML5 apps/games. In addition to the engine, we also make the PlayCanvas Editor:

Editor

For Editor-related bugs and issues, please refer to the Editor's repo.

engine's People

Contributors

aidinabedi avatar daredevildave avatar dependabot[bot] avatar e-strokov avatar ellthompson avatar epreston avatar erikdubbelboer avatar gsterbrant avatar guycalledfrank avatar h1gdev avatar imgbot[bot] avatar jpauloruschel avatar kpal81xd avatar kungfooman avatar lexxik avatar maksims avatar marklundin avatar merihtaze avatar mushasterion avatar mvaligursky avatar querielo avatar raytranuk avatar scarletsky avatar slimbuck avatar tatsujinichi avatar vkalpias avatar warwithinme avatar willeastcott avatar yaustar avatar yayhi 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  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

engine's Issues

Audio fallback can cause hang on load

IE currently doesn't have Web Audio, so the engine falls back to HTML5 Audio API. When running SWOOOP locally, the game hangs during audio resource loading. No exception is thrown. Interestingly, if you force the engine to use HTML5 Audio API in Chrome (by hacking the engine), the same hang occurs. Note that when running SWOOOP from apps.playcanvas.com, the loading process gets further (indicating that there may be a timing problem), but throws an exception of InalidStateError when setting currentTime to 0 in Channel.stop.

Needs to create a hg repository ?

I was running python build.py and it breaks with index_error because a hg revision check. So, create a hg init into git repo, and it builds ok. Maybe you guys can fix that or put it in documentation/README. :)

Interest in running in web worker?

I'm experimenting with running webGL apps in web workers, by proxying the GL commands over to the main thread. The motivation is that workers never stall the main thread, can do things the main thread cannot (sync binary xhrs), and also this approach can be faster (10% speedup on emscripten'd cube2/bananabread - queuing up gl commands is faster than actually issuing them, freeing up the cpu-intensive thread).

I started to tinker with playcanvas to see how a non-emscripten app does. I haven't quite gotten this to work, but the gl stream seems to be almost correct. Main issue is I'm not familiar with the playcanvas codebase, so for example as I was tracing back a NaN it went into an onSomething call so I don't have a stack trace, and I got confused.

Any interest in getting playcanvas to run in workers? If so it would be great to work together on this. There's probably not much in the way here - the proxying code passes various emscripten tests, works on cube2/bananabread, and on a playcanvas demo as mentioned above, it emits a gl stream that looks almost right barring some NaNs and wrong # of glDrawElements count.

Work is at

https://github.com/kripken/webgl-worker

Basically playcanvas/normal.html runs on the main thread, /worker.html in a worker. The last commit adds an option to show just 1 frame in both, for debugging purposes. There's also a debug branch that adds full gl logging on both.

IE11, Web Audio API, load mp3 without Media Pack installed.

If on Windows 8 in IE11 Audio API is not supported fully, it will report it's availability but will fail to work.
Installing Media Feature Pack for N and KN versions of Windows 8.1 solves the problem.
Engine should not fail screen and expect such scenario, fallback to basic audio and still run the game. Without media pack it assumed it supports Web Audio API, then tried to load mp3 but failed to decode it, threw exception and just failed to play the game.
Is Audio considered high priority that will lead to big fail if it wont load, or should be considered as not mandatory asset, and potentially can fail to load but still will run the game as that would be expected case scenario.

Prefiltered CubeMaps

Consider using textureCubeLodEXT from EXT_shader_texture_lod extension for using MipMap levels to extract different levels of filtering instead of re-uploading individual CubeMaps each bind. 55% supported.
And use individual CubeMaps as fallback.

Add support for mixing maps and colors in the phong shader

It would be a powerful addition to allow people to blend between a material property's map or corresponding color. For example, if the diffuse color is red and there is a diffuse map, we can introduce a diffuseMixAmount property (0 to 1) which blends between the color and the map. Current functionality is that the map (if present) simply takes priority over the color.

What defines the public API?

I am new to Javascript APIs and I'm having trouble distinguishing the engine's public API from its private code.

There seems to be quite a lot of undocumented functionality in the engine which does not show up under the API Reference (such as pc.scene.RENDERSTYLE_WIREFRAME). I've been browsing the source code, but then I encounter areas like src/core which seem to be internal code.

This makes it difficult to tell what I am or am not supposed to call in client code.

Is there any way we can make this clearer? If the API Reference is indeed the canonical definition of the public API, are there any guidelines I can follow to determine whether to submit a patch for missing documentation?

Kinematic bodies can spontaneously rotate

Under certain circumstances, kinematic bodies can suddenly rotate without being influenced by a PlayCanvas script. On initial inspection, it seems that this is something related to ammo.js but logging here until it can be proved it's actually an ammo problem.

Shadow Artefacts & Precision issues: point light depth buffer not cleared, large bias issue, inconsistent precision depending on light range.

  1. Point light shadows seems not clearing depth buffer before rendering depth maps, leading to geometry outside of range of light affecting depth buffer creating "shadows" where they should not be at all (artefacts).
  2. Light shadow is dependant on Range value dramatically, and inconsistent for different light types: For Point light low range increases shadow precision. For Spot light low range dramatically decreases precision, and setting very large range for spot light makes shadows way more precise.

Demo to replicate problems:
http://playcanvas.com/max/shadow-culling/designer/pack/d61d3d0c-7c7e-11e4-984b-12313b0a5ec6

  • Blue point light in the middle of the scene is point light, within big box has really weird circular shadows, looks like shadow precision or distance is linear per depth map rather circular relative to light source.
  • Red spot light has low range, and drops nearly no shadows, increasing range makes shadows to appear.
  • Yellow and Green point lights show same problem where they have low range, and have some weird shadows appearing which is related to boxes in the middle. As moving box_big will affect that artefact, assuming it is out of range and not cleared.
  • Take in account what Cull state is set to material on box_big, and changing that state how it affects shadows too.
  • Change for testing "Cast Shadows" on floor - it affects yellow and green lights dramatically.

Screenshot:
screen shot 2014-12-09 at 15 20 09

graphic_device.js typo error

The line:

this.defaultClearOptions = {
color: [0, 0, 0, 1],
depth: 1,
flags: pc.gfx.CLEARFLAG_COLOR | pc.gfx.CLEARFLAG_COLOR
};

Should be:

this.defaultClearOptions = {
color: [0, 0, 0, 1],
depth: 1,
flags: pc.gfx.CLEARFLAG_COLOR | pc.gfx.CLEARFLAG_DEPTH
};

Probably this is a typo error.

Find parent by name

pc.fw.entity.findByName() seems to only work for the entitys children, so I would suggest adding getParentByName():

getParentByName: function(name){
    var tmp = this.entity;
    while(tmp.getParent() && tmp.getName() !== name){
        tmp = tmp.getParent();
    }
    if(tmp.getName() === name) return tmp;
    else return null;
}

Kind regards,
Aaron

[RFC] Improve Audio API

We currently don't expose much of the Audio API through the AudioManager, Channel, Sound interfaces.

This is a request for features that you would like to see added to the API. Please comment on this thread with your requirements.

Mouse can lose button up events if outside bounds of canvas

If you mouse down on the PlayCanvas canvas but then move the mouse outside the bounds of the canvas and mouse up, PlayCanvas still reports the button as pressed (via the isPressed function).

Perhaps we should be capturing the mouse (see Element.setCapture docs) internally in the engine.

Post process drawFullscreenQuad rect issue

Duiring setting the viewport and scissor on drawFullscreenQuad there is issue to rect properties access:

if(rect) {
x = rect.x * w;
y = rect.y * h;
w *= rect.z;
h *= rect.w
}

But if I log rect i see: {"data":{"0":0,"1":0,"2":1,"3":1}
So property is wrong to access to x, y, z, w.
To fix this the posteffectqueue enable function need to use camera.getRect() instead of camera.rect.

Thanks,
Amer

It is not possible to set a procedurally created mesh on a collision component

If you create a model procedurally and set it on a model component for rendering, it is not currently possible to also set it on a collision component to make the mesh into a static body. Not using the API anyway. A workaround is to call:

        context.systems.collision.addComponent(this.entity, {
            type: 'mesh'
        });
        this.entity.collision.model = model;
        context.systems.collision.implementations.mesh.doRecreatePhysicalShape(this.entity.collision);

Parallax Strength

There is no way to set strength of parallax at the moment.
Would be great to have parallax strength property with 0.0 to 2.0 value range, to multiply parallax offset by, same as bumpiness.

Texture ignores autoMipMap option

As you can see, autoMipMap variable is simply not used, but initialized to true anyway. This forces all textures with any options to have automipmaps, unless user will change this property after creation. I suggest replacing this.autoMipmap = true withthis.autoMipmap = autoMipMap

var autoMipmap = true;

if (typeof options !== 'undefined') {
    width = (typeof options.width !== 'undefined') ? options.width : width;
    height = (typeof options.height !== 'undefined') ? options.height : height;
    format = (typeof options.format !== 'undefined') ? options.format : format;
    cubemap = (typeof options.cubemap !== 'undefined') ? options.cubemap : cubemap;
    autoMipmap = (typeof options.autoMipmap !== 'undefined') ? options.autoMipmap : autoMipmap;
}

// PUBLIC
this.name = null;
this.autoMipmap = true;

if (this.autoMipmap && pc.math.powerOfTwo(this._width) && pc.math.powerOfTwo(this._height) && this._levels.length === 1) {
    gl.generateMipmap(this._glTarget);
}

PostEffects + Additive Render State

If there are geometry rendered with material using Additive Blend Type, PostEffects will be screwed, as they don't set own Blending and will inherit what was set in rendering scene process. Good example would be Bloom PostEffect.

In order to replicate it, have some entity with Additive Blend Type and clone it by keypress, so that it will be at the end of render queue.

.clone() is not synchronous

The function entity.clone() creates components and loads data using the normal resource loader (even though all resources are already loaded). This means that this code doesn't work:

var newCloneObject = this.masterObject.clone();
newCloneObject.script.scriptName.someVariable = 3;

As clone is async and the script component is not loaded during the clone function.

This problem also applies to addComponent()

clone() should return an entity with all components completely initialized.

PlayCanvas intercepts all mouse events on window (breaks HTML UI)

The change in this commit makes it pretty hard to integrate an HTML-based UI into PlayCanvas. When clicking on an overlay, the mouse events are still handled by PlayCanvas (as if clicking on the canvas) - so you often handle clicks that should be suppressed.

Part of that commit message mentions that it was to fix full screen in Chrome. I've been testing with Chrome and fullscreen for the past couple of months without any issue. Here's what I've been doing / a suggestion for fullscreen functionality:

In framework_application , enableFullscreen starts with this:

        enableFullscreen: function (element, success, error) {
            element = element || this.canvas;

I've had a lot of success calling enableFullscreen by doing the following:

pc_app.enableFullscreen(document.documentElement);

I'm not 100% sure if this would work, but you could listen for mouse events on the element, and default the element to document.documentElement instead of the canvas.

Opacity bug going from 0.152.1 to 0.152.2

I'm not sure if this is the right place to report this, but I ran into an opacity issue earlier today. I have a plane with an opacity map that was working yesterday and this morning, but stopped working at some point in the day. I tracked it down to the PlayCanvas version getting bumped from 0.152.1 to 0.152.2 (exporting the pack and then using 0.152.1 instead makes to opacity work correctly).

Basically, it's not blending correctly except at certain angles. I've got a scene set up with a "Clouds" plane above a city. See this album

Light layers

We need a way to say that a given light lights a given set of models. This could be automated based on a lights bounding volume or specifiable in the Designer interface (create layer and add models to it and specify the layer on the light).

Exception or Not Exception

Currently if something slightly goes a bit off planned, it throws exceptions, for example:

  • Texture is not size power of 2.
  • mp3 is not supported.
  • material pointed by model mapping is not available.
  • shader failed to compile.
  • script exception.
    And many others.

The reaction currently it is throwing internal exceptions and very unclear messages to console, that people perceive as engine bug, then it fails to load or work at all.

Desirable behaviour:
Console dev friendly messages with identifiers of error source and explanation of what to look at. Then apply default material, texture, etc just to keep game working even with black textures / blank materials etc.

Scripting
When scripting fails, it starts spawning crazy messages on every update, should it in development mode follow this behaviour: Console dev friendly message with identifiers of error source and pointer to script file + line number, then disable script, and keep going.
That will allow artists to still work with project even if coder is breaking stuff around.

Specific Cases

  1. Sending not valid value type to shader uniforms, throws exceptions. Should prevent uploading to WebGL value unless it is valid, and console.warn uniform name and material name that tries to set invalid value to.
  2. Material unavailable asset is referenced but asset is not available from resources. Should not throw exception, but console.warn ID of unavailable asset, entity name and index of sub-model, that material was referenced in.

Keybindings don't seem to work in Chromium

I am unable perform keyboard shortcuts (ie. alt+middle-click to pan) in the IDE, or navigate via the WASD keys in an FPS template project. I am using Chromium version 37.0.2030.0 (Developer Build 274814).

Post Effects on camera affects canvas resizing.

Having FXAA shader as post effect on Camera, screws up resizing of canvas, adding weird stretching and delay before resize applies. Try resizing window running the demo, or changing orientation on mobile.

Script causing issue: http://code.playcanvas.com/posteffects/posteffect_fxaa.js
Demo to replicate: http://playcanvas.com/max/post-effect-resize-issue/designer/bootstrap?e=d996a0e2-7fbf-11e4-9f8e-12313b0a5ec6

If you disable scripts on camera, or remove fxaa shader, issue vanishes.
Other shaders seems not suffering of such symptoms.

Rotational Difference between two Vec3s

I would say it's useful to have a rotational difference between two vectors(eulerAngles). E.g. when applying an angular velocity to rotate an entity into a specific rotation.

sub2rotational: function(lhs, rhs){
    var diff = new pc.Vec3();
    for(var i=0; i<3; i++){
        var tmp = lhs.data[i] - rhs.data[i];
        if(tmp > 180) diff.data[i] = -360 + Math.abs(tmp);
        else if(tmp < -180) diff.data[i] = 360 - Math.abs(tmp);
        else diff.data[i] = tmp;
    }
    return diff;
}

EDIT:
Hm I've just met a special case where this doesn't work..

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.