New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@twoavy/gltf-viewer

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@twoavy/gltf-viewer

Vue component to view 3D-Models in .gltf-format

latest
Source
npmnpm
Version
0.2.6
Version published
Maintainers
2
Created
Source

gltf-viewer

A Vue component to view GLTF-3D-Models, incl. OrbitControls and v-model position

Installation

npm i @twoavy/gltf-viewer
OR
yarn add @twoavy/gltf-viewer
import GltfViewer from 'gltf-viewer';

Usage

Once installed, it can be used in a template as simply as:

<gltf-viewer url="path/to/model.gltf" 
             :options="options"
             :points="points"
              @point-clicked="onClick($event)"/>

or with multiple Models:

<gltf-viewer :urls="['path/to/model1.gltf', 'path/to/model2.gltf']" 
              @object-loaded="onLoaded" />

Options

{
    bgColor: 0xcccccc,
    maxClickAngle: 25,
    lights: {
        exposure: 1.0,
        textureEncoding: 'sRGB',
        ambientIntensity: 0.3,
        ambientColor: 0xFFFFFF,
        directIntensity: 0.8 * Math.PI,
        directColor: 0xFFFFFF
    },
    controls: {
        enabled: true,
        minPolarAngle: 0,
        maxPolarAngle: Math.PI,
        minAzimuthAngle: -Infinity,
        maxAzimuthAngle: Infinity,
        minDistance: 0,
        maxDistance: Infinity,
        autoRotate: false,
        autoRotateSpeed: -10,
        enableZoom: true,
        zoom: 1 // note that zoom and min/max distance affect each other!
    }
}

Points

[
    {
        id: 0,
        position: { x: 1, y: 1, z: 1 },
        rotation: { x: 0, y: 0, z: 0 },
        // payload can be anything (e.g. target camera position)
        payload: {
            x: -0.9,
            y: 0.5,
            z: -1.1
        }
    },
    {
        id: 1,
        position: { x: 2, y: 4, z: -1 },
        rotation: { x: 1, y: 2, z: 0 },
        // payload can be anything
        payload: {
            x: -0.9,
            y: 0.5,
            z: -1.1
        }
    }
]

v-model

Animate positoin with e.g. Greensock:

<gltf-viewer url="path/to/model.gltf" 
             v-model="position" />
data() {
    return {
        position: {}
    }
},
methods: {
    tweenPosition() {
        let formPos = { ...this.position }
        let targetPos = { x: 1, y: 2, z: 3 }
        TweenLite.to(fromPos, 0.6, {
            ...targetPos,
            onUpdate: () => {
                this.position = fromPos
            }
        })
    }
}

Note that you cannot change the camera position via v-model if autoRotate is true!

Events

NamePayload
start-drag-
end-drag-
point-clickedPoint
object-loadad{ url: String, gltf: Object }

Point

ProperyTypeDefault
idNumber-
positionObject{ x: 0, y: 0, z: 0 }
rotationObjectnull
colorHex0xffffff
opacityNumber0.5
radiusNumber0.1
scaleNumber0.5
objectObjectnull
onClickFunctionnull
payloadanynull
doubleSideBooleantrue

FAQs

Package last updated on 21 Oct 2019

Did you know?

Socket

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