-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
index.js
40 lines (34 loc) · 1.15 KB
/
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
31
32
33
34
35
36
37
38
39
40
const foxJson = require('./fox.json');
const {
calculateSizingOptions,
createLogoViewer,
loadModelFromJson,
createModelRenderer,
createNode,
setAttribute,
setGradientDefinitions,
setMaskDefinitions,
} = require('./util');
module.exports = createLogo;
function createLogo(options = {}) {
const cameraDistance = options.cameraDistance || 400;
const { height, width } = calculateSizingOptions(options);
const meshJson = options.meshJson || foxJson;
const container = createNode('svg');
setAttribute(container, 'width', `${width}px`);
setAttribute(container, 'height', `${height}px`);
document.body.appendChild(container);
setGradientDefinitions(container, meshJson.gradients);
setMaskDefinitions({ container, masks: meshJson.masks, height, width });
const modelObj = loadModelFromJson(meshJson);
const renderFox = createModelRenderer(container, cameraDistance, modelObj);
const renderScene = (lookCurrent, slowDrift) => {
const rect = container.getBoundingClientRect();
renderFox(rect, lookCurrent, slowDrift);
};
return createLogoViewer(
container,
renderScene,
Object.assign({ cameraDistance }, options),
);
}