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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shapediver/sdk.sdtf-geometry

v1.5.3

Published

Extension containing sdTF geometry types

Downloads

2,457

Readme

Structured Data Transfer Format - Integration for geometry types

The Structured Data Transfer Format (sdTF) is an API-neutral exchange and storage format for trees of data items as used by parametric 3D modeling software like Grasshopper®. This open, efficient, and easily extensible data format enables the exchange of complex data structures, independent of software vendors. See the sdTF documentation for more details.

The aim of this package is to extend the sdTF-v1 module to provide processing and typing functionality for geometric data.

It can be used in Node.js and modern Browsers, and exposes the respective TypeScript declarations.

Installation

npm i @shapediver/sdk.sdtf-v1 @shapediver/sdk.sdtf-geometry

This package is a plugin for the sdTF-v1 module and cannot be used by itself.

Usage

This code initializes the SDK and registers the integration for geometry types. After this step, the integration is fully included in all reading and writing processes of the SDK instance.

// index.ts
import { create, SdtfSdk } from "@shapediver/sdk.sdtf-v1"
import { SdtfGeometryTypeIntegration } from "@shapediver/sdk.sdtf-geometry"

(async () => {
    const sdk: SdtfSdk = await create({
        integrations: [ new SdtfGeometryTypeIntegration() ]
    })

    // Use the sdk here
})()

Supported types

The following table lists all type hints that are supported by this integration, their specific TypeScript types, and the provided type guard functions that can be used to infer a data content type.

| Type hint name | TypeScript type | Type guard | |------------------------------------------------------------------------------|----------------------------------|-------------------------------------------------------------------------------------------| | "geometry.arc" or SdtfGeometryTypeHintName.GEOMETRY_ARC | SdtfGeometryArcType | SdtfGeometryTypeHintName.assertArcSdtfGeometryTypeHintName.isArc | | "geometry.boundingbox" or SdtfGeometryTypeHintName.GEOMETRY_BOUNDING_BOX | SdtfGeometryBoundingBoxType | SdtfGeometryTypeHintName.assertBoundingBoxSdtfGeometryTypeHintName.isBoundingBox | | "geometry.box" or SdtfGeometryTypeHintName.GEOMETRY_BOX | SdtfGeometryBoxType | SdtfGeometryTypeHintName.assertBoxSdtfGeometryTypeHintName.isBox | | "geometry.circle" or SdtfGeometryTypeHintName.GEOMETRY_CIRCLE | SdtfGeometryCircleType | SdtfGeometryTypeHintName.assertCircleSdtfGeometryTypeHintName.isCircle | | "geometry.complex" or SdtfGeometryTypeHintName.GEOMETRY_COMPLEX | SdtfGeometryComplexType | SdtfGeometryTypeHintName.assertComplexSdtfGeometryTypeHintName.isComplex | | "geometry.cone" or SdtfGeometryTypeHintName.GEOMETRY_CONE | SdtfGeometryConeType | SdtfGeometryTypeHintName.assertConeSdtfGeometryTypeHintName.isCone | | "geometry.cylinder" or SdtfGeometryTypeHintName.GEOMETRY_CYLINDER | SdtfGeometryCylinderType | SdtfGeometryTypeHintName.assertCylinderSdtfGeometryTypeHintName.isCylinder | | "geometry.ellipse" or SdtfGeometryTypeHintName.GEOMETRY_ELLIPSE | SdtfGeometryEllipseType | SdtfGeometryTypeHintName.assertEllipseSdtfGeometryTypeHintName.isEllipse | | "geometry.interval" or SdtfGeometryTypeHintName.GEOMETRY_INTERVAL | SdtfGeometryIntervalType | SdtfGeometryTypeHintName.assertIntervalSdtfGeometryTypeHintName.isInterval | | "geometry.interval2" or SdtfGeometryTypeHintName.GEOMETRY_INTERVAL2 | SdtfGeometryInterval2Type | SdtfGeometryTypeHintName.assertInterval2SdtfGeometryTypeHintName.isInterval2 | | "geometry.line" or SdtfGeometryTypeHintName.GEOMETRY_LINE | SdtfGeometryLineType | SdtfGeometryTypeHintName.assertLineSdtfGeometryTypeHintName.isLine | | "geometry.matrix" or SdtfGeometryTypeHintName.GEOMETRY_MATRIX | SdtfGeometryMatrixType | SdtfGeometryTypeHintName.assertMatrixSdtfGeometryTypeHintName.isMatrix | | "geometry.plane" or SdtfGeometryTypeHintName.GEOMETRY_PLANE | SdtfGeometryPlaneType | SdtfGeometryTypeHintName.assertPlaneSdtfGeometryTypeHintName.isPlane | | "geometry.point" or SdtfGeometryTypeHintName.GEOMETRY_POINT | SdtfGeometryPointType | SdtfGeometryTypeHintName.assertPointSdtfGeometryTypeHintName.isPoint | | "geometry.polyline" or SdtfGeometryTypeHintName.GEOMETRY_POLYLINE | SdtfGeometryPolylineType | SdtfGeometryTypeHintName.assertPolylineSdtfGeometryTypeHintName.isPolyline | | "geometry.ray" or SdtfGeometryTypeHintName.GEOMETRY_RAY | SdtfGeometryRayType | SdtfGeometryTypeHintName.assertRaySdtfGeometryTypeHintName.isRay | | "geometry.rectangle" or SdtfGeometryTypeHintName.GEOMETRY_RECTANGLE | SdtfGeometryRectangleType | SdtfGeometryTypeHintName.assertRectangleSdtfGeometryTypeHintName.isRectangle | | "geometry.sphere" or SdtfGeometryTypeHintName.GEOMETRY_SPHERE | SdtfGeometrySphereType | SdtfGeometryTypeHintName.assertSphereSdtfGeometryTypeHintName.assertSphere | | "geometry.torus" or SdtfGeometryTypeHintName.GEOMETRY_TORUS | SdtfGeometryTorusType | SdtfGeometryTypeHintName.assertTorusSdtfGeometryTypeHintName.isTorus | | "geometry.transform" or SdtfGeometryTypeHintName.GEOMETRY_TRANSFORM | SdtfGeometryTransformType | SdtfGeometryTypeHintName.assertTransformSdtfGeometryTypeHintName.isTransform | | "geometry.vector" or SdtfGeometryTypeHintName.GEOMETRY_VECTOR | SdtfGeometryVectorType | SdtfGeometryTypeHintName.assertVectorSdtfGeometryTypeHintName.isVector |

Additionally, the type guard SdtfGeometryTypeHintName provides functions to infer subtypes of SdtfGeometryPointType and SdtfGeometryVectorType:

typeGuard.assertPoint2d and typeGuard.isPoint2d:
Infer the subtype SdtfGeometryPoint2d of SdtfGeometryPointType.

typeGuard.assertPoint3d and typeGuard.isPoint3d:
Infer the subtype SdtfGeometryPoint3d of SdtfGeometryPointType.

typeGuard.assertPoint4d and typeGuard.isPoint4d:
Infer the subtype SdtfGeometryPoint4d of SdtfGeometryPointType.

typeGuard.assertVector2d and typeGuard.isVector2d:
Infer the subtype SdtfGeometryVector2d of SdtfGeometryVectorType.

typeGuard.assertVector3d and typeGuard.isVector3d:
Infer the subtype SdtfGeometryVector3d of SdtfGeometryVectorType.

Example

This simple example reads a sdTF file and extracts the content of all data items. Every content data that is of a cylindrical or spherical type is scaled up and shown on the console.

// index.ts
import { create, SdtfSdk } from "@shapediver/sdk.sdtf-v1"
import { SdtfGeometryTypeIntegration, SdtfGeometryTypeGuard } from "@shapediver/sdk.sdtf-geometry"

(async () => {
    const sdk: SdtfSdk = await create({
        integrations: [ new SdtfGeometryTypeIntegration() ]
    })

    // Reads a sdTF file
    const asset = await sdk.createParser().readFromFile("./test.sdtf")

    // Process all data items with a cylindrical or spherical content
    for (const dataItem of asset.items) {
        const geometry = await dataItem.getContent()            // load data content of type `unknown`

        if (SdtfGeometryTypeGuard.isCylinder(geometry)) {       // checks and infers the type to `SdtfGeometryCylinderType`
            geometry.baseCircle.radius *= 5
        }
        else if (SdtfGeometryTypeGuard.isSphere(geometry)) {    // checks and infers the type to `SdtfGeometrySphereType`
            geometry.radius *= 7
        }
        else {
            continue
        }

        console.log("The scaled geometry is", geometry)         // Print out the scaled geometry information
    }
})()

Support

If you have questions, please use the ShapeDiver Help Center.

You can find out more about ShapeDiver right here.

Licensing

This project is released under the MIT License.