-
Notifications
You must be signed in to change notification settings - Fork 32
/
sample_physical.htm
108 lines (96 loc) · 4.26 KB
/
sample_physical.htm
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html>
<head>
<title>Sample Rendering with Physical Properties</title>
<link href="css/index.css" rel="stylesheet" type="text/css">
<style>
#canvas_holder{position:relative;top:0}
#loading_text{display:block;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);color:white;}
.dg.main{position:absolute;top:0;right:0;text-align:left;}
</style>
<meta name="viewport" content="width=device-width" />
</head>
<body>
<div id="canvas_holder">
<canvas id="canvas"></canvas>
<p id="loading_text">Loading...</p>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/three.min.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/dat.gui.min.js"></script>
<script src="js/CopyShader.js"></script>
<script src="js/Pass.js"></script>
<script src="js/OutlinePass.js"></script>
<script src="js/ShaderPass.js"></script>
<script src="js/RenderPass.js"></script>
<script src="js/MaskPass.js"></script>
<script src="js/EffectComposer.js"></script>
<script src="js/colors.js"></script>
<script src="js/Scene.js"></script>
<script src="js/LDROptions.js"></script>
<script src="js/LDRShaders.js"></script>
<script src="js/LDRColorMaterials.js"></script>
<script src="js/LDRGeometries.js"></script>
<script src="js/LDRLoader.js"></script>
<script src="js/LDRStuds.js"></script>
<script src="js/StudioTexmap.js"></script>
<script src="js/LDRGenerator.js"></script>
<script>
let startTime = new Date();
let color = 16;
// Test models:
let model = 'models/corvette_full.mpd';
//let model = 'models/tnl.mpd'; // Has glow in the dark elements.
//let model = '6091.dat'; // Has overlap of line and conditional line causing trouble for the normal calculation.
//let model = '85080.dat'; // Has conditional lines partially overlapping with hard corners, also causing issues for normal calculation.
// Materials:
//let model = 'models/luminance.ldr';
//let model = 'models/chrome.ldr';
//let model = 'models/rubber.ldr';
//let model = 'models/speckle.ldr';
//let model = 'models/metal.ldr';
//let model = 'models/glitter.ldr';
//let model = 'models/pearlescent.ldr';
//let model = 'models/trans.ldr';
let canvas = document.getElementById('canvas');
let scene = new ENV.Scene(canvas, color);
let onWindowResize = () => scene.onChange(window.innerWidth, window.innerHeight);
window.addEventListener('resize', onWindowResize, false);
let ldrLoader; // Three.js loader for LDraw models
let onLoad = function() {
document.getElementById('loading_text').style.display = 'none';
console.log("Data loaded after " + (new Date()-startTime) + "ms.");
let taskList = [];
ldrLoader.generate(color, scene.mc, taskList);
console.log("Animation info constructed after " + (new Date()-startTime) + "ms.");
scene.build();
scene.buildFloor();
console.log("Scene built after " + (new Date()-startTime) + "ms.");
let taskListIdx = 0;
function animateConstruction() {
animationID = requestAnimationFrame(animateConstruction);
if(taskListIdx >= taskList.length) {
//scene.mc.updateMeshVisibility(); // Hide lines
LDR.Colors.loadTextures(() => scene.render()); // Ensure that we repaint when textures are loaded.
cancelAnimationFrame(animationID);
scene.setUpGui(onWindowResize);
console.log("Model built after " + (new Date()-startTime) + "ms.");
onWindowResize(); // Render
return; // Done.
}
let animationStartTime = new Date();
while((new Date()-animationStartTime) < 20 && taskListIdx < taskList.length) {
taskList[taskListIdx++]();
}
scene.repositionFloor(0.001); // Ensure the floor is placed just below the model - in case it has increased in size since previous frame.
}
onWindowResize(); // Render
animateConstruction();
}
LDR.Studs.makeGenerators('', 0, 2); // 0 for lines is ignored. 2 for logo on texture.
ldrLoader = new THREE.LDRLoader(onLoad, null, {physicalRenderingAge:20});
ldrLoader.load(model);
</script>
</body>
</html>