Interface PrimitiveManagerMaterialInterface

The PrimitiveManagerMaterialInterface is used to change the colors of 3D primitives : Points, lines and boxes.

The PrimitiveManagerMaterialInterface is accessed through the PrimitiveManagerInterface.getPrimitiveMaterialManager function (the PrimitiveManagerInterface is accessed through InfiniteEngineInterface.getPrimitiveManager).

The color is expressed as a Vector4, RGBA (Red, Green, Blue, Alpha), Red = pRGBAColor.x, etc...
Color values are expressed from 0 to 1. An alpha value of 1 means an opaque color, an alpha value of 0 means a transparent color.

Materials are expressed and manipulated as strictly positive ids : a primitive material id. A primitive material id of 0 is invalid. There is a limit on the number of materials that may be created. The getMaxAvailablePrimitiveMaterials tells the number of primitive materials that may be created.

Materials can be modified and removed. However materials used by 3D primitives are protected from removal until no primitive uses them.

WARNING : do not confuse the PrimitiveManagerMaterialInterface and the MaterialManagerInterface, these two interfaces are separated, do not use MaterialManagerInterface ids to draw 3D primitives !!!

point display
line display
box display
Changing material may be done with the following :
/** 
* Sample to change the colors of 3d points on top of the rendering (PrimitiveManagerMaterialInterface, PrimitiveManagerPointInterface).
*/
import {
InfiniteEngineInterface, InfiniteEngineInterfaceSignal, PrimitiveManagerMaterialInterface, PrimitiveManagerPointInterface,
Vector4, Vector3
} from 'generated_files/documentation/appinfiniteapi';

// created previously
let lInfiniteEngine : InfiniteEngineInterface;
// created previously, the point position
let lPointPos : Vector3;

// the material for the point, same material for inner and outer positions
let lPointMaterial : number = -1;
// the primitive material manager
const lPrimitiveMaterialManager : PrimitiveManagerMaterialInterface = lInfiniteEngine.getPrimitiveManager().getPrimitiveMaterialManager();
// the point manager
const lPointManager : PrimitiveManagerPointInterface = lInfiniteEngine.getPrimitiveManager().getPointManager();
// id of the point
let lPointId : number = -1;
// point color is white opaque (1 as last parameter)
const lPointColor : Vector4 = new Vector4(1, 1, 1, 1);
// the number of materials that may be created
const lNbAvailableMaterials = lPrimitiveMaterialManager.getMaxAvailablePrimitiveMaterials();

// when something is picked, change the material color and make some checks
const onPicked = () : void =>
{
if (lPointId === -1 || lPointMaterial === -1)
{
// do nothing if the point or material is incorrect
return;
}
const lCurColor : Vector4 = new Vector4();
console.assert(lPrimitiveMaterialManager.getPrimitiveMaterialsCount() === 1, 'bad number of materials');
console.assert(lPrimitiveMaterialManager.getMaxAvailablePrimitiveMaterials() === lNbAvailableMaterials, 'the number of available materials should not change');
// get the color of the material
console.assert(lPrimitiveMaterialManager.getPrimitiveMaterialColor(lPointMaterial, lCurColor));
// make sure no change
console.assert(lCurColor.x === lPointColor.x);
console.assert(lCurColor.y === lPointColor.y);
console.assert(lCurColor.z === lPointColor.z);
console.assert(lCurColor.w === lPointColor.w);
// set yellow as color
lCurColor.set(0, 1, 1, 1);
// and change material color
lPrimitiveMaterialManager.setPrimitiveMaterialColor(lPointMaterial, lCurColor);
};
// bind the listener to the signal
lInfiniteEngine.addEventListener(InfiniteEngineInterfaceSignal.Picked, onPicked);

// create material
lPointMaterial = lPrimitiveMaterialManager.createPrimitiveMaterial(lPointColor);

// and create the point
lPointId = lPointManager.createPoint(
// center,
lPointPos,
// point sizes
20,
10,
// same material for inner and outer areas
lPointMaterial,
lPointMaterial
);
// some fancy output
console.log('Point id is ' + lPointId);

You may create boxes, points, etc with PrimitiveManagerBoxInterface, PrimitiveManagerPointInterface, etc.
3D Primitives

interface PrimitiveManagerMaterialInterface {
    createPrimitiveMaterial(pRGBAColor): number;
    getMaxAvailablePrimitiveMaterials(): number;
    getPrimitiveMaterialColor(pMaterialID, pRGBAColorOut): boolean;
    getPrimitiveMaterialIds(): number[];
    getPrimitiveMaterialsCount(): number;
    removeAllPrimitiveMaterials(): void;
    removePrimitiveMaterial(pMaterialId): boolean;
    setPrimitiveMaterialColor(pMaterialID, pRGBAColor): boolean;
}

Methods

  • Creates a new material to be used by 3D primitive items (points, lines, boxes).

    The color is expressed as a Vector4, RGBA (Red, Green, Blue, Alpha), Red = pRGBAColor.x, etc...
    Color values are expressed from 0 to 1. An alpha value of 1 means an opaque color, an alpha value of 0 means a transparent color.

    Parameters

    • pRGBAColor: Vector4
      in
      The color to set for the drawing of the primitives items.

    Returns number

    The primitive material id of the newly created material.

  • Tells the maximum number of materials that can be created.

    This number is not updated when new materials are created. This value is constant : 65535.

    Returns number

    The number of materials that may be created.

  • Gets the color of an existing material.

    If found, pRGBAColorOut is updated. Returns true if the primitive material is found and therefore pRGBAColorOut is updated.

    Parameters

    • pMaterialID: number
      in
      The primitive material id of the material to query.
    • pRGBAColorOut: Vector4
      out
      The color of the given material.

    Returns boolean

    true if pRGBAColorOut was updated.

  • Get a copy of the list of primitive material ids in use.

    Returns number[]

    A copy of the primitive material ids in use.

  • Tells the number of materials in use.

    This number is updated when new materials are created or removed.

    Returns number

    The number of created materials.

  • Removes the given material.

    The primitive material id pMaterialId should be valid and should not be currently used by any other primitive.
    If pMaterialId is in use, then the function returns false and the material is not removed.

    Parameters

    • pMaterialId: number
      in
      The id of the material to remove.

    Returns boolean

    true if the material has been removed.

  • Updates the color of an existing material.

    Returns true if a primitive material with the given primitive material id exists.

    Parameters

    • pMaterialID: number
      in
      The primitive material id of the material to update.
    • pRGBAColor: Vector4
      in
      The new color to set for this material.

    Returns boolean

    true if the material exists and is therefore updated.