Finish documentation

This commit is contained in:
schmelczerandras 2020-09-28 16:26:55 +02:00
parent 49473bf905
commit 31fcfd3d6b
86 changed files with 1383 additions and 8485 deletions

View file

@ -1,13 +1,63 @@
import { Drawable } from './drawable';
/**
* Used for containing the required information to compile drawables into
* shader code.
*
* Each [[Drawable]] must have a static property of this type, called descriptor.
*
* For more information on how to create your own DrawableDescriptor-s, look at the
* code of [[Circle]] or [[InvertedTunnel]].
*/
export interface DrawableDescriptor {
/**
* An object describing the relationship between the object returned by a [[Drawable]]'s
* getObjectToSerialize and the name of the arrays used in the GLSL code.
*/
propertyUniformMapping: { [property: string]: string };
/**
* The name of the uniform int used in the code to refer to the
* number of drawables of this type.
*/
uniformCountMacroName: string;
/**
* Required property for shapes having physical dimensions.
*/
sdf?: {
/**
* The actual GLSL code for observing the drawables represented by this descriptor.
*
* Your code should work with both version 100 and version 300 es
*/
shader: string;
isInverted?: boolean;
/**
* The name of the function defined in the value of `shader`.
* Its signature should look like this:
* ```glsl
* float (in vec2 target, out float colorIndex)
* ```
*/
distanceFunctionName: string;
/**
* By default, drawables are not inverted.
*/
isInverted?: boolean;
};
/**
* Number of possible drawables around each tile.
*
* For each step, a shader will be generated. And at runtime the closes matching
* shader will be used to render a given part of the scene.
*/
shaderCombinationSteps: Array<number>;
/**
* When no shaderCombinationStep matches the current number of drawables exactly,
* the value of `empty` is used to pad out arrays.
*/
readonly empty: Drawable;
}

View file

@ -1,11 +1,36 @@
import { mat2d, vec2 } from 'gl-matrix';
import { DrawableDescriptor } from './drawable-descriptor';
/**
* Base class of every drawable object.
*
* To create your own drawables, you need to subclass from this.
*
* > Although lights are also subclasses of Drawable, you cannot create your own light sources.
*/
export abstract class Drawable {
// This should be overriden by inherited classes
/**
* This should be defined in inherited classes.
*/
public static readonly descriptor: DrawableDescriptor;
/**
* The lower bound of the distance between the target and the object.
*
* It can return 0 by default, the only consequence of this, is a reduced performance.
* Because this object won't benefit from tile-based rendering.
* @param target
*/
public abstract minDistance(target: vec2): number;
/**
* Return the values that should be given to the shaders through uniform inputs.
*
* @param transform2d position-like properties should be transformed by this matrix
* before being returned.
* @param transform1d scalar properties should be transformed by this number
* before being returned.
*/
protected abstract getObjectToSerialize(transform2d: mat2d, transform1d: number): any;
public serializeToUniforms(

View file

@ -2,6 +2,9 @@ import { vec2, vec3 } from 'gl-matrix';
import { DrawableDescriptor } from '../drawable-descriptor';
import { LightDrawable } from './light-drawable';
/**
* @category Drawable
*/
export class CircleLight extends LightDrawable {
public static readonly descriptor: DrawableDescriptor = {
propertyUniformMapping: {

View file

@ -2,6 +2,9 @@ import { mat2d, vec2, vec3 } from 'gl-matrix';
import { DrawableDescriptor } from '../drawable-descriptor';
import { LightDrawable } from './light-drawable';
/**
* @category Drawable
*/
export class Flashlight extends LightDrawable {
public static readonly descriptor: DrawableDescriptor = {
propertyUniformMapping: {

View file

@ -1,6 +1,7 @@
import { mat2d, vec2, vec3 } from 'gl-matrix';
import { Drawable } from '../../main';
/** @internal */
export class LightDrawable extends Drawable {
protected lightnessRatio = 1;

View file

@ -2,6 +2,9 @@ import { mat2d, vec2 } from 'gl-matrix';
import { Drawable } from '../drawable';
import { DrawableDescriptor } from '../drawable-descriptor';
/**
* @category Drawable
*/
export class Circle extends Drawable {
public static descriptor: DrawableDescriptor = {
sdf: {

View file

@ -4,6 +4,9 @@ import { mix } from '../../helper/mix';
import { Drawable } from '../drawable';
import { DrawableDescriptor } from '../drawable-descriptor';
/**
* @category Drawable
*/
export class InvertedTunnel extends Drawable {
public static descriptor: DrawableDescriptor = {
sdf: {

View file

@ -4,6 +4,9 @@ import { mix } from '../../helper/mix';
import { Drawable } from '../drawable';
import { DrawableDescriptor } from '../drawable-descriptor';
/**
* @category Drawable
*/
export class Tunnel extends Drawable {
public static descriptor: DrawableDescriptor = {
sdf: {