-
Notifications
You must be signed in to change notification settings - Fork 0
/
multimodelviewer.html
93 lines (89 loc) · 3.74 KB
/
multimodelviewer.html
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!doctype html>
<html lang="en">
<head>
<title><model-viewer> template</title>
<meta charset="utf-8">
<meta name="description" content="<model-viewer> template">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link type="text/css" href="./styles.css" rel="stylesheet"/>
<!-- OPTIONAL: The :focus-visible polyfill removes the focus ring for some input types -->
<script src="https://unpkg.com/[email protected]/dist/focus-visible.js" defer></script>
</head>
<style>
input {
margin: .8rem;
}
.controls1 {
position: absolute;
display: flex;
flex-direction: column;
align-items: left;
bottom: 0px;
left: 1px;
}
</style>
<body>
<model-viewer id="gagukok_tulipchair_tablechair" camera-controls src="https://xr-box.s3.ap-northeast-2.amazonaws.com/shop_file/GoogleModelviewer_20211213/webXR_test/gagukok_tulipchair_tablechair_dfdf.gltf" ar ar-modes="webxr scene-viewer quick-look" alt="A 3D model of a Shoe">
<model-viewer id="hi" camera-controls src="Astronaut.glb" ar ar-modes="webxr scene-viewer quick-look" alt="A 3D model of a Shoe" style="width:30%; height: 20%; top: 200; background-color: transparent; transform: translate(-50%, -50%);">
</model-viewer>
<div class="controls1">
<div>Colorpicker : <input type="color" id="colorWell" name="head"
value="#e66465"></div>
</div>
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
<script>
//3번째 컬러피커..
const modelViewerColor = document.querySelector("model-viewer#gagukok_tulipchair_tablechair");
var colorWell;
var defaultColor = "#ffffff";
window.addEventListener("load", startup, false);
function startup() {
colorWell = document.querySelector("#colorWell");
colorWell.value = defaultColor;
colorWell.addEventListener("input", updateFirst, false);
colorWell.addEventListener("change", updateAll, false);
colorWell.select();}
function hexToRgbA(hex){
var c;
if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
c= hex.substring(1).split('');
if(c.length== 3){
c= [c[0], c[0], c[1], c[1], c[2], c[2]];
}
c= '0x'+c.join('');
one=(c>>16)&255
two=(c>>8)&255
three=c&255
return [((c>>16)&255)/255, ((c>>8)&255)/255, (c&255)/255].join(',')+',1';
}
throw new Error('Bad Hex');
};
function hexToDec(hexString){
return parseInt(hexString, 16);
}
function updateFirst(event) {
var p = document.querySelector("#color-controls1");
const colorString = event.target.value;
const hextodemi=colorString.split('#')
a=hexToRgbA(colorString)
const color = a.split(',')
.map(numberString => parseFloat(numberString));
console.log('Changing color to: ', color);
const [material] = modelViewerColor.model.materials;
material.pbrMetallicRoughness.setBaseColorFactor(color);
};
</script>
<script>
const modelViewerVariants = document.querySelector("model-viewer#hi");
document.addEventListener("dblclick", (e) => {
const mouseX = e.clientX;
const mouseY = e.clientY;
console.log(e.clientX);
console.log(e.clientY);
modelViewerVariants.style.left = mouseX + 'px';
modelViewerVariants.style.top = mouseY + 'px';
});
</script>
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
</body>
</html>