Skip to content

Commit fe97f9e

Browse files
committed
update icon
1 parent 0bdff77 commit fe97f9e

File tree

5 files changed

+70
-12
lines changed

5 files changed

+70
-12
lines changed

demo/img/icon.jpg

152 KB
Loading

demo/img/originIcon.png

3.12 MB
Loading

demo/js/OrbitControls.js

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
this.enable();
5858
}
5959

60+
OrbitControls.prototype.reset = function(){
61+
tempEuler.set(0, 0, 0);
62+
};
6063
OrbitControls.prototype.enable = function(){
6164
if(!this.isEnabled){
6265
this.isEnabled = true;

demo/js/index.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ function initList(){
1212
models.forEach(function(modelInfo){
1313
var name = modelInfo.name;
1414
var id = modelInfo.id;
15+
var index = parseInt(id) - 1;
1516
var elem = document.createElement('div');
1617
var modelPath = `../models/${id}/`;
1718
elem.className = 'modelContainer';
1819
elem.setAttribute('data-id', id);
1920
elem.innerHTML = `
20-
<div data-id='${id}' class='modelIcon' style='background-size:74px 63px;background-image:url(./${modelPath}icon.png);width:74px;height:63px;'></div>
21+
<div data-id='${id}' class='modelIcon' style='background-position:${-(148 + 4)/2*(index%13)}px ${-(125 + 4)/2*(Math.floor(index/13)) + 0.5}px;background-size:988px 838px;background-image:url(//wx4.sinaimg.cn/mw1024/6a4fa2d0ly1fxo333fivdj20rg0na0wo.jpg);width:74px;height:63px;'></div>
2122
<div data-id='${id}' class='modelInfo'>${id} ${name}</div>
2223
`;
2324
listContainerElem.appendChild(elem);
@@ -55,42 +56,43 @@ function initStage(){
5556

5657
orbitControls = new OrbitControls(stage, {
5758
isLockMove:true,
58-
isLockZ:true
59+
isLockZ:true,
60+
rotationXLimit:true
5961
});
6062

6163
glTFLoader = new Hilo3d.GLTFLoader();
6264

6365
closeBtnElem.onclick = function(){
64-
hideStage();
66+
hideModel();
6567
}
6668
}
6769

68-
function hideStage(){
70+
function hideModel(){
6971
modelViewerContainerElem.style.display = 'none';
70-
mainContainerElem.appendChild(listContainerElem);
72+
listContainerElem.style.display = 'flex';
7173

7274
// reset resource
7375
Hilo3d.BasicLoader.cache.clear();
7476
stage.destroy();
7577
stage.matrix.identity();
78+
orbitControls.reset();
7679

7780
titleElem.innerHTML = 'Pokémon Viewer';
78-
}
79-
80-
function showStage(){
81-
modelViewerContainerElem.style.display = 'block';
82-
mainContainerElem.removeChild(listContainer);
81+
location.hash = '';
8382
}
8483

8584
function onShowModelError(){
8685
alert('Someting Error!');
87-
hideStage();
86+
hideModel();
8887
}
8988

9089
function showModel(id){
91-
showStage();
90+
modelViewerContainerElem.style.display = 'block';
91+
listContainerElem.style.display = 'none';
92+
9293
loadingElem.style.display = 'block';
9394
titleElem.innerHTML = `${id} ${modelDict[id].name}`;
95+
9496
var glTFUrl = `../models/${id}/glTF/model.gltf`;
9597
glTFLoader.load({
9698
src: glTFUrl,

tools/icon.html

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>icon</title>
6+
</head>
7+
<body>
8+
<canvas id='canvas'></canvas>
9+
<script>
10+
const canvasElem = document.querySelector('canvas');
11+
const ctx = canvasElem.getContext('2d');
12+
const createImage = async (src) => {
13+
return new Promise((resolve, reject) => {
14+
const img = new Image();
15+
img.onload = function(){
16+
resolve(img);
17+
};
18+
19+
img.onerror = function(e){
20+
reject(e);
21+
};
22+
23+
img.src = src;
24+
});
25+
};
26+
27+
const createImages = async () => {
28+
const w = 148;
29+
const h = 125;
30+
const gap = 4;
31+
canvasElem.width = (w + gap) * 13;
32+
canvasElem.height = (h + gap) * 13;
33+
ctx.fillStyle = '#aaa';
34+
ctx.fillRect(0, 0, canvasElem.width, canvasElem.height);
35+
for(let i = 1;i <= 151;i ++) {
36+
const col = (i-1) % 13;
37+
const row = Math.floor((i-1) / 13);
38+
const id = i < 10 ? ('00' + i) : i < 100 ? ('0' + i) : i;
39+
try{
40+
const img = await createImage(`../models/${id}/icon.png`);
41+
ctx.drawImage(img, col * (w + gap), row * (h + gap));
42+
} catch(e){
43+
console.warn(`${id} has no model!`);
44+
}
45+
}
46+
};
47+
48+
createImages().then(() => {
49+
console.log('haha~');
50+
});
51+
</script>
52+
</body>
53+
</html>

0 commit comments

Comments
 (0)