forked from remik2212/logo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
30 lines (25 loc) · 911 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const foxJson = require('./fox.json')
const {
calculateSizingOptions,
createLogoViewer,
loadModelFromJson,
createModelRenderer,
createNode,
setAttribute,
} = require('./util.js')
module.exports = createLogo
function createLogo (options = {}) {
const cameraDistance = options.cameraDistance || 400
const { height, width } = calculateSizingOptions(options)
const container = createNode('svg')
setAttribute(container, 'width', `${width}px`)
setAttribute(container, 'height', `${height}px`)
document.body.appendChild(container)
const modelObj = loadModelFromJson(foxJson)
const renderFox = createModelRenderer(container, cameraDistance, modelObj)
const renderScene = (lookCurrent, slowDrift) => {
const rect = container.getBoundingClientRect()
renderFox(rect, lookCurrent, slowDrift)
}
return createLogoViewer(container, renderScene, { cameraDistance, ...options })
}