Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GeometryModel

The GeometryModel implements a client-side model that can handle a large number of parts efficiently.

The model can be created and modified in the client application and is not dependent on a server (unlike ug.RemoteModel).

Each view can contain many GeometryModels. A GeometryModel is a collection of parts. Each Part is defined by its Mesh, which describes the triangles, lines and points, and by its PartSettings, which specify how the part is rendered.

A GeometryModel can have a transformation matrix (setTransformationMatrix()) useful for scene composition or for doing rigid body animations.

Picking is supported via rayIntersect() which returns a HitItem containing the intersection point, part index and primitive index within that part, and regionIntersect() which returns an array of parts (partially) within a given rectangle in screen coordinates.

Here is a simple example that creates a geometry model with one part and one triangle and adds it to the current view

   var geoModel = new cee.geo.GeometryModel();

   // Create a simple one triangle one part model
   var indices = [0, 1, 2];
   var triangleVertices = [0,0,0,  1,0,0,  0,1,0];

   let part = geoModel.addPart();
   let mesh = new cee.geo.MeshIndexedTriangles(triangleVertices, indices);
   part.mesh = mesh;

   part.settings.color = new cee.Color3(0, 1, 0);

   var view = myViewer.getViewAt(0);
   view.addModel(geoModel);
   view.requestRedraw();

Hierarchy

Index

Constructors

constructor

Accessors

name

name: string

The name of the geometry model. Mainly used for debugging.

Readonly partCount

partCount: number

The number of parts in the model.

transformationMatrix

transformationMatrix: Mat4

The transformation matrix to use for this model.

If specified, all parts in the model will be transformed by this matrix. This can be useful for scene composition and for rigid body type animations. The default is null.

Methods

addPart

  • Creates a new part and adds it to the model.

    Returns the newly created part.

    Returns Part

deleteAllParts

  • deleteAllParts(): void
  • Deletes all parts in model

    Returns void

deletePartAt

  • deletePartAt(partIndex: number): void
  • Deletes the part at the given (zero based) index.

    Parameters

    • partIndex: number

    Returns void

deletePartsAt

  • deletePartsAt(partIndicesArr: number[]): void
  • Deletes the parts at the given indices.

    Parameters

    • partIndicesArr: number[]

    Returns void

getBoundingBox

getPartArray

  • getPartArray(): ReadonlyArray<Part>
  • Returns a read only array with all parts

    Returns ReadonlyArray<Part>

getPartAt

  • getPartAt(partIndex: number): Part
  • Returns an active reference to the part at the given (zero based) index.

    Parameters

    • partIndex: number

    Returns Part

rayIntersect

  • Performs picking on the model.

    If something was hit, returns a HitItem containing information about the part and primitive that was hit.

    If nothing was hit, returns null.

    Parameters

    Returns HitItem

regionIntersect

  • regionIntersect(x: number, y: number, width: number, height: number, view: View, acceptPartiallyContainedParts: boolean): Part[]
  • Returns the parts that are (partially) inside the given region.

    The returned list of parts will contain all parts that are inside the given region. If acceptPartiallyContainedParts is set to true, parts will be considered inside if they are partially inside (at least one pixel of one item) the region. If false, the entire part needs to be completely inside the region.

    The x and y coordinates must be specified in OpenGL style coordinates, which means a right handed coordinate system with the origin in the lower left corner of the window. The HTML coordinate system is with origin in top left, so if this is your input (e.g. MouseEvent.offsetY, clientY, pageY, etc.) you will have to flip the Y coordinate. The x and y are specified in native pixels, so you will have to adjust the input for the current devicePixelRatio (window.devicePixelRatio).

    The width and height are specified in native pixels. So you will have to adjust the input for the current devicePixelRatio (window.devicePixelRatio).

    Example: Change the color of all parts within the rectangle defined by a rubber band

    
       // this.m_startX/this.m_startY is the event.offsetX/event.offsetY at the
       // start of the region definition
       endRegionSelection(event: MouseEvent) {
           this.m_regionSelectActive = false;
    
           let pixelScaleFactor = window.devicePixelRatio || 1;
           let startXPixels = this.m_startX * pixelScaleFactor;
           let startYPixels = this.m_startY * pixelScaleFactor;
           let endXPixels = event.offsetX * pixelScaleFactor;
           let endYPixels = event.offsetY * pixelScaleFactor;
    
           // Note: Canvas height is in native pixels, so no scaling with pixelScaleFactor
           let canvasHeightPixels = this.m_canvas.height;
    
           let leftPixels = Math.min(startXPixels, endXPixels);
           let rightPixels = Math.max(startXPixels, endXPixels);
           let topPixels = Math.max(canvasHeightPixels - startYPixels,
                                    canvasHeightPixels - endYPixels);
           let bottomPixels = Math.min(canvasHeightPixels - startYPixels,
                                    canvasHeightPixels - endYPixels);
           let widthPixels = (rightPixels - leftPixels);
           let heightPixels = (topPixels - bottomPixels);
    
           let parts = this.m_model.regionIntersect(leftPixels, bottomPixels,
                                         widthPixels, heightPixels, this.m_view, true);
    
           let selectColor = new cee.Color3(1,0,1);
           for(let part of parts) {
               part.settings.color = selectColor;
           }
    
           this.m_regionSelectionDiv.hidden = true;
       }

    Parameters

    • x: number
    • y: number
    • width: number
    • height: number
    • view: View
    • acceptPartiallyContainedParts: boolean

    Returns Part[]

setColorPerPartFromMapper

  • setColorPerPartFromMapper(scalarMapper: ScalarMapper, perPartResult: ArrayLike<number>): void
  • Sets the color of the parts in the model based on the given scalarMapper and a scalar per part.

    This is useful for showing per-part scalar results on a GeometryModel.

    To show a color legend representing the scalar mapper in a View, use the View.overlay.addCustomColorLegendForScalarMapper() method.

    This method is just a helper for doing the following:

       const partCount = this.partCount;
       for (let i = 0; i < partCount; ++i) {
           let color = scalarMapper.mapToColor(perPartResult[i]);
           let part = this.getPartAt(i);
           part.settings.color = color.toColor3();
           part.settings.opacity = color.a;
       }

    Parameters

    • scalarMapper: ScalarMapper
    • perPartResult: ArrayLike<number>

    Returns void

Generated using TypeDoc