npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mlightcad/graphic-interface

v3.1.3

Published

The graphic-interface package provides the graphics interface for controlling how AutoCAD entities are displayed on screen. This package offers a simplified API compared to AutoCAD ObjectARX's AcGi classes, making it more developer-friendly while maintain

Readme

@mlightcad/graphic-interface

The graphic-interface package provides the graphics interface for controlling how AutoCAD entities are displayed on screen. This package offers a simplified API compared to AutoCAD ObjectARX's AcGi classes, making it more developer-friendly while maintaining the core functionality needed for rendering CAD entities.

Overview

This package provides the graphics interface layer that bridges the gap between the data model and the rendering system. It handles the conversion of AutoCAD entities into drawable objects and provides customization options for how objects are displayed, including colors, layers, visibility, and various rendering styles.

Key Features

  • Entity Rendering: Convert AutoCAD entities to drawable objects
  • Style Customization: Control colors, line styles, text styles, and point styles
  • View Management: Handle different views and viewports
  • Arrow and Hatch Support: Custom arrow types and hatch pattern rendering
  • Image Rendering: Support for raster image display
  • Flexible Rendering: Extensible rendering system for different output formats

Installation

npm install @mlightcad/graphic-interface

Key Classes

Core Rendering Classes

  • AcGiRenderer: Main interface for rendering entities to drawable objects
  • AcGiEntity: Base class for drawable objects that can be rendered
  • AcGiView: Represents a view with camera and projection settings
  • AcGiViewport: Manages viewport settings and clipping

Style Classes

  • AcGiArrowType: Defines different arrow types for dimensions and leaders
  • AcGiHatchStyle: Controls hatch pattern rendering and appearance
  • AcGiImageStyle: Manages raster image display properties
  • AcGiLineStyle: Defines line styles including dash patterns and widths
  • AcGiPointStyle: Controls point entity display appearance
  • AcGiTextStyle: Manages text rendering properties and formatting

Usage Examples

Basic Entity Rendering

import { AcGiRenderer, AcGiEntity } from '@mlightcad/graphic-interface';
import { AcDbLine, AcGePoint3d } from '@mlightcad/data-model';

// Create a renderer
const renderer = new AcGiRenderer();

// Create an entity
const startPoint = new AcGePoint3d(0, 0, 0);
const endPoint = new AcGePoint3d(10, 10, 0);
const line = new AcDbLine(startPoint, endPoint);

// Render the entity
const drawableEntity = renderer.renderEntity(line);

Style Configuration

import { 
  AcGiLineStyle, 
  AcGiTextStyle, 
  AcGiPointStyle,
  AcGiArrowType 
} from '@mlightcad/graphic-interface';

// Configure line style
const lineStyle = new AcGiLineStyle();
lineStyle.setColor(1); // Red
lineStyle.setWidth(2.0);
lineStyle.setDashPattern([10, 5, 5, 5]); // Dashed line

// Configure text style
const textStyle = new AcGiTextStyle();
textStyle.setFont('Arial');
textStyle.setHeight(12);
textStyle.setColor(2); // Yellow
textStyle.setBold(true);

// Configure point style
const pointStyle = new AcGiPointStyle();
pointStyle.setSize(5);
pointStyle.setShape('Circle');
pointStyle.setColor(3); // Green

// Configure arrow style
const arrowStyle = new AcGiArrowType();
arrowStyle.setType('ClosedFilled');
arrowStyle.setSize(3);
arrowStyle.setColor(1); // Red

View and Viewport Management

import { AcGiView, AcGiViewport, AcGePoint3d } from '@mlightcad/graphic-interface';

// Create a view
const view = new AcGiView();
view.setEyePoint(new AcGePoint3d(0, 0, 100));
view.setTargetPoint(new AcGePoint3d(0, 0, 0));
view.setUpVector(new AcGeVector3d(0, 1, 0));

// Create a viewport
const viewport = new AcGiViewport();
viewport.setView(view);
viewport.setWidth(800);
viewport.setHeight(600);
viewport.setZoom(1.0);

// Set viewport properties
viewport.setClippingEnabled(true);
viewport.setClippingBounds(0, 0, 100, 100);

Hatch Pattern Rendering

import { AcGiHatchStyle } from '@mlightcad/graphic-interface';

// Configure hatch style
const hatchStyle = new AcGiHatchStyle();
hatchStyle.setPattern('ANSI31'); // Standard AutoCAD pattern
hatchStyle.setScale(1.0);
hatchStyle.setAngle(0);
hatchStyle.setColor(4); // Cyan
hatchStyle.setTransparency(0.5);

// Apply hatch to an entity
const hatchedEntity = renderer.renderEntityWithHatch(entity, hatchStyle);

Image Rendering

import { AcGiImageStyle } from '@mlightcad/graphic-interface';

// Configure image style
const imageStyle = new AcGiImageStyle();
imageStyle.setBrightness(1.0);
imageStyle.setContrast(1.0);
imageStyle.setFade(0.0);
imageStyle.setTransparency(0.0);
imageStyle.setClippingEnabled(false);

// Render image with style
const imageEntity = renderer.renderImage(imagePath, imageStyle);

Custom Rendering Pipeline

import { AcGiRenderer, AcGiEntity } from '@mlightcad/graphic-interface';

// Create a custom renderer
class CustomRenderer extends AcGiRenderer {
  renderEntity(entity: AcDbEntity): AcGiEntity {
    // Custom rendering logic
    const drawable = super.renderEntity(entity);
    
    // Apply custom styling
    if (entity.getLayer() === 'HIGHLIGHT') {
      drawable.setHighlighted(true);
    }
    
    return drawable;
  }
  
  renderToCanvas(canvas: HTMLCanvasElement, entities: AcGiEntity[]) {
    const ctx = canvas.getContext('2d');
    
    entities.forEach(entity => {
      // Custom canvas rendering
      this.renderEntityToCanvas(ctx, entity);
    });
  }
}

// Use custom renderer
const customRenderer = new CustomRenderer();
const drawableEntities = entities.map(entity => customRenderer.renderEntity(entity));
customRenderer.renderToCanvas(canvas, drawableEntities);

Batch Rendering

import { AcGiRenderer } from '@mlightcad/graphic-interface';

// Batch render multiple entities
const renderer = new AcGiRenderer();
const entities = [line1, circle1, polyline1, text1];

// Render all entities with consistent styling
const drawableEntities = renderer.renderEntities(entities, {
  defaultColor: 7, // White
  defaultLayer: '0',
  defaultLinetype: 'CONTINUOUS'
});

// Apply viewport transformations
viewport.applyTransformations(drawableEntities);

Dependencies

  • @mlightcad/geometry-engine: For geometric operations (peer dependency)

API Documentation

For detailed API documentation, visit the RealDWG-Web documentation.

Contributing

This package is part of the RealDWG-Web monorepo. Please refer to the main project README for contribution guidelines.