Catalog npm
Back to packageRELEASE DETAILS

1.16.6

npm

3d-nft-viewer

Display 3D NFTs using ThreeJS to render model stored on arweave and minted on DeSo

3darweavenftthreejs
Published29 Jun 2023
Direct dependencies7
Transitive dependenciesNot calculated

README

Current package documentation

3D NFT Viewer

Description

The 3D NFT Viewer is used to display an interactive ThreeJS view of 3D models which have been minted as an NFT on the DeSo blockchain.

3D NFTs are essentials 3D model files which have been uploaded to a permanent decentralized storage network.

Metadata about the 3D model including the URL are stored in a Post transaction on the DeSo blockchain and minted to create a Non Fungible Token which can be bought and sold like any other NFT.

This repo contains front and back end code which can be used separately or in combination as in the demo.

NPM Installation

npm install 3d-nft-viewer

Back End NodeJS Module

Class: NFTReader

Functionality

  • Checks to see if the 3D model is already downloaded to your server.
  • Retrieves the NFT post data from the deso blockchain chain.
  • Downloads the model assets from arweave and extracts them.
  • Finds the local path of the glb or gltf model file.
  • Returns the URL of the extracted 3D model which you can then use to load the model into the Front End viewer or any other 3d app or metaverse experience.

Express JS Example

In the example below nftPostHashHex is the token that identifies the individual NFT You will see this during the minting process and on any DeSo node that displays your NFT.

https://docs.deso.org/for-developers/backend/blockchain-data/basics/data-types#postentryresponse

var express = require('express');
var router = express.Router();
var D3DNFT = require('3d-nft-viewer');

router.post('/:nftPostHashHex', (req, res) => {

  const nftPostHashHex = req.params.nftPostHashHex;

  let nftReader = new D3DNFT.NFTReader({
      nodeEndpoint: 'https://node.deso.org/api/v0/',  // DeSo API Endpoint (any node can be used)
      readerPublicKey: '<Your DeSo Public Key>',
      modelStorageDir: 'public/models/' // public directory to serve the model files
  });

  nftReader.retrieveNFT(nftPostHashHex)
  .then((responseJson)=>{
    res.send(responseJson);
  }).catch((responseJson)=>{
    console.log(responseJson);
    console.log('retrieveNFT error');
    res.send(responseJson);
  });
});

module.exports = router;

Front End Three JS Plugin

Class: Viewer

Functionality

  • Searches the DOM for elements with the nft-viewer css class name. For best results we recommend this is the container for a preview image showing a rotating gif of the 3D model (this is created automatically during the minting process - see How To Mint)
  • Sends an API request to the back end to fetch the URL for the 3D model file, downloading it from remote storage if necessary
  • When the 3D model URL is returned, a link with text "Click to View in 3D" is appended along with a click event handler
  • On click of the link the ThreeJS code replaces the image in the container element with a CANVAS tag and initializes the Three JS interactive view.

Example Front End Page Structure

  <head>
    <title>3D NFT Viewer</title>
    <link rel='stylesheet' href='/css/styles.css' />
  </head>
  <body>
    <div class="container">
		<img class="nft-preview" src="https://images.deso.org/746201e0167a8176c3c0ca2b141b4ed2c92442a1d16a55ab999a558e8a831a28.gif"/>
	</div>
	<p class="nft-viewer" data-nft="0b88277db8b3ddac74537b3f5b10897865e0fea5edcc47c86547a36fd5cf6693">Loading...</p>

  <script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
    <script type="importmap">
      {
        "imports": {
          "three": "https://cdn.skypack.dev/three"
        }
      }
    </script>
    <script type="module">
      // Find the latest version by visiting https://cdn.skypack.dev/three.
      import * as THREE from 'three';


      import { OrbitControls } from 'https://unpkg.com/three@0.139.1/examples/jsm/controls/OrbitControls.js';
      import { GLTFLoader } from 'https://unpkg.com/three@0.139.1/examples/jsm/loaders/GLTFLoader.js';
      import { XRControllerModelFactory } from '/js/webxr/XRControllerModelFactory.js';

      import { VRButton } from '/js/D3D_VRButton.js';

      import { D3DNFTViewer } from '/js/3dviewer.js'

            //initialize NFT viewer front end
        let nftViewer = new D3DNFTViewer({
            three: THREE,
            GLTFLoader: GLTFLoader,
            OrbitControls: OrbitControls,
            XRControllerModelFactory: XRControllerModelFactory,
            VRButton: VRButton,
            ctrClass: 'nft-viewer', // class of div which has posthashhex attribute
            nftDataAttr: 'data-nft', // Name of attribute of of div.ctrClass which contains posthashhex
            nftsRoute: 'nfts', // Back end route to initialize NFTs
            modelsRoute: 'models', // Back end route to load models
            linkText: 'View in 3D',
            previewCtrCls: 'container', //container element in which to create the preview
            skyboxes: true
        });
        nftViewer.initNFTs();

   </script>
  </body>
</html>

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 7

Native requirements
7 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
three
Environment
{
  "local_name": "three",
  "alias": false,
  "peer_metadata": null
}
^0.153.0runtime
animejs
Environment
{
  "local_name": "animejs",
  "alias": false,
  "peer_metadata": null
}
^3.2.1runtime
axios
Environment
{
  "local_name": "axios",
  "alias": false,
  "peer_metadata": null
}
^0.27.1runtime
cannon-es
Environment
{
  "local_name": "cannon-es",
  "alias": false,
  "peer_metadata": null
}
^0.20.0runtime
canvas-record
Environment
{
  "local_name": "canvas-record",
  "alias": false,
  "peer_metadata": null
}
^3.1.0runtime
dom-to-image
Environment
{
  "local_name": "dom-to-image",
  "alias": false,
  "peer_metadata": null
}
^2.6.0runtime
three-to-cannon
Environment
{
  "local_name": "three-to-cannon",
  "alias": false,
  "peer_metadata": null
}
^4.3.0runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-ECNv2L2SGrJZDYUj9iWZJF1FV4hG63LetAGjUb16saW1oza34ZuCq+ZOO2Hg/HFQzkZ8da3dYu3vfpfFMo0aVQ==",
  "shasum": "7b20e933892ebc1aabd479be5e5ea2df0915a453",
  "tarball": "https://registry.npmjs.org/3d-nft-viewer/-/3d-nft-viewer-1.16.6.tgz",
  "fileCount": 202,
  "unpackedSize": 27239190,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEYCIQDuLwW/HHKuk5ashD0qFy2QroEMK/5EXjFVaC00vbixYwIhAJRW0o0PcFOI3Qt1OVJrkvu3TPlv+LYQycpZxBX8MQj+"
    }
  ]
}

Repository

PENDING
3desocial/3d-nft-viewer-npm

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:36 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:80af5c8471b2ef446ac3dcf1cdbfdcd8d153a204cacced7edd4cc18dd59f61ff

Other collected versions

1.16.516 Jun1.16.415 Jun1.16.39 Jun1.16.21 Jun1.16.131 May1.16.031 MayView all collected versions →