Socket
Socket
Sign inDemoInstall

@shapediver/sdk.sdtf-geometry

Package Overview
Dependencies
1
Maintainers
5
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @shapediver/sdk.sdtf-geometry

Extension containing sdTF geometry types


Version published
Weekly downloads
148
increased by15.63%
Maintainers
5
Created
Weekly downloads
 

Readme

Source

ShapeDiver

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 nameTypeScript typeType guard
"geometry.arc" or SdtfGeometryTypeHintName.GEOMETRY_ARCSdtfGeometryArcTypeSdtfGeometryTypeHintName.assertArc
SdtfGeometryTypeHintName.isArc
"geometry.boundingbox" or SdtfGeometryTypeHintName.GEOMETRY_BOUNDING_BOXSdtfGeometryBoundingBoxTypeSdtfGeometryTypeHintName.assertBoundingBox
SdtfGeometryTypeHintName.isBoundingBox
"geometry.box" or SdtfGeometryTypeHintName.GEOMETRY_BOXSdtfGeometryBoxTypeSdtfGeometryTypeHintName.assertBox
SdtfGeometryTypeHintName.isBox
"geometry.circle" or SdtfGeometryTypeHintName.GEOMETRY_CIRCLESdtfGeometryCircleTypeSdtfGeometryTypeHintName.assertCircle
SdtfGeometryTypeHintName.isCircle
"geometry.complex" or SdtfGeometryTypeHintName.GEOMETRY_COMPLEXSdtfGeometryComplexTypeSdtfGeometryTypeHintName.assertComplex
SdtfGeometryTypeHintName.isComplex
"geometry.cone" or SdtfGeometryTypeHintName.GEOMETRY_CONESdtfGeometryConeTypeSdtfGeometryTypeHintName.assertCone
SdtfGeometryTypeHintName.isCone
"geometry.cylinder" or SdtfGeometryTypeHintName.GEOMETRY_CYLINDERSdtfGeometryCylinderTypeSdtfGeometryTypeHintName.assertCylinder
SdtfGeometryTypeHintName.isCylinder
"geometry.ellipse" or SdtfGeometryTypeHintName.GEOMETRY_ELLIPSESdtfGeometryEllipseTypeSdtfGeometryTypeHintName.assertEllipse
SdtfGeometryTypeHintName.isEllipse
"geometry.interval" or SdtfGeometryTypeHintName.GEOMETRY_INTERVALSdtfGeometryIntervalTypeSdtfGeometryTypeHintName.assertInterval
SdtfGeometryTypeHintName.isInterval
"geometry.interval2" or SdtfGeometryTypeHintName.GEOMETRY_INTERVAL2SdtfGeometryInterval2TypeSdtfGeometryTypeHintName.assertInterval2
SdtfGeometryTypeHintName.isInterval2
"geometry.line" or SdtfGeometryTypeHintName.GEOMETRY_LINESdtfGeometryLineTypeSdtfGeometryTypeHintName.assertLine
SdtfGeometryTypeHintName.isLine
"geometry.matrix" or SdtfGeometryTypeHintName.GEOMETRY_MATRIXSdtfGeometryMatrixTypeSdtfGeometryTypeHintName.assertMatrix
SdtfGeometryTypeHintName.isMatrix
"geometry.plane" or SdtfGeometryTypeHintName.GEOMETRY_PLANESdtfGeometryPlaneTypeSdtfGeometryTypeHintName.assertPlane
SdtfGeometryTypeHintName.isPlane
"geometry.point" or SdtfGeometryTypeHintName.GEOMETRY_POINTSdtfGeometryPointTypeSdtfGeometryTypeHintName.assertPoint
SdtfGeometryTypeHintName.isPoint
"geometry.polyline" or SdtfGeometryTypeHintName.GEOMETRY_POLYLINESdtfGeometryPolylineTypeSdtfGeometryTypeHintName.assertPolyline
SdtfGeometryTypeHintName.isPolyline
"geometry.ray" or SdtfGeometryTypeHintName.GEOMETRY_RAYSdtfGeometryRayTypeSdtfGeometryTypeHintName.assertRay
SdtfGeometryTypeHintName.isRay
"geometry.rectangle" or SdtfGeometryTypeHintName.GEOMETRY_RECTANGLESdtfGeometryRectangleTypeSdtfGeometryTypeHintName.assertRectangle
SdtfGeometryTypeHintName.isRectangle
"geometry.sphere" or SdtfGeometryTypeHintName.GEOMETRY_SPHERESdtfGeometrySphereTypeSdtfGeometryTypeHintName.assertSphere
SdtfGeometryTypeHintName.assertSphere
"geometry.torus" or SdtfGeometryTypeHintName.GEOMETRY_TORUSSdtfGeometryTorusTypeSdtfGeometryTypeHintName.assertTorus
SdtfGeometryTypeHintName.isTorus
"geometry.transform" or SdtfGeometryTypeHintName.GEOMETRY_TRANSFORMSdtfGeometryTransformTypeSdtfGeometryTypeHintName.assertTransform
SdtfGeometryTypeHintName.isTransform
"geometry.vector" or SdtfGeometryTypeHintName.GEOMETRY_VECTORSdtfGeometryVectorTypeSdtfGeometryTypeHintName.assertVector
SdtfGeometryTypeHintName.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.

Keywords

FAQs

Last updated on 08 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc