- git clone https://github.com/DBDeve/models-viewer-basic
- npm install
- npm create vite@latest test
- select vanilla
- select javascript
- npm install three
- cd test
- npm install
- npm run dev
- add import {viewer} from '../../lib/viewer.js'
- npm create vite@latest project-name
- select vanilla
- select javascript
- cd project-name
- npm install models-viewer-basic
- add this tag to index.html file:
<div id="canvasContainer"></div>
- add this code for default configuration
import { viewer } from 'models-viewer-basic';
const isProd = process.env.NODE_ENV === 'production';
const basePath = isProd ? '/dist' : '';
let model;
window.loadModel =async function () {
let config = {
"scene": {
"model": {"filePath": `${basePath}/file_model_name`},
//"noModel":{"Message":"message", "defaultPath":`${basePath}/file_model_name_default`},
"environment": {"hdrFilePath": `${basePath}/file_hdri_name`}
},
"renderer":{
"canvas": {
"insertIn": "canvasContainer",
},
"RenderSize": {
"mobile": { "width": 0 , "height": 0},
"tablet":{"width": 0 , "height": 0},
"computer": { "width": 0, "height": 0}
},
},
"camera":{
"basic": {
"angle": { "x": 3.7, "y": 1.5},
"distance": { "initial": 1.7, "min": 2, "max": 4 },
"position":{"x":0,"y":0,"z":0}
},
"controls": {
"rotate": { "vertical":{"min":0,"max":360}, "orizontal":{"min":-Infinity,"max":Infinity}},
"zoom": {},
"pan":{},
"effect":{
"damping":{ "factor": 0.05 }
}
},
},
};
model = await viewer.createInstance(config);
}
window.addEventListener('DOMContentLoaded', loadModel);