Skip to content

Commit 5d4d0ed

Browse files
committed
showLightPosition Done!
SVG
1 parent d96b58d commit 5d4d0ed

9 files changed

Lines changed: 191 additions & 83 deletions

File tree

addLight.js

Lines changed: 111 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,39 @@ $(function() {
7676

7777
var view = {
7878
init: function() {
79+
80+
// mouse event
81+
82+
var canvas = document.getElementById( "gl-canvas" );
83+
canvas.addEventListener("mousedown", function(evt){
84+
mouseFlag = 1;
85+
}, false);
86+
canvas.addEventListener("mousemove", function(evt){
87+
if(mouseFlag === 1){
88+
setMousePos(canvas, evt, 0);//add default light event;
89+
}
90+
}, false);
91+
canvas.addEventListener("mouseup", function(){
92+
mouseFlag = 0;
93+
//mouseFlag = (mouseFlag ==0)?1:0;
94+
}, false);
95+
96+
97+
// show light Position event
98+
99+
$('#lightsPositionSelect:checkbox').click(function() {
100+
var $this = $(this);
101+
// $this will contain a reference to the checkbox
102+
if ($this.is(':checked')) {
103+
$('#lightPosition_container').css("display", "block");
104+
} else {
105+
$('#lightPosition_container').css("display", "none");
106+
}
107+
});
108+
109+
110+
111+
// "Add light" button event
79112
var addLightBtn = $('#btn_addLight');
80113
addLightBtn.click(function() {
81114
octopus.addLight();
@@ -85,7 +118,7 @@ $(function() {
85118
this.$lightList = $('ul#accordion_Lights');
86119
this.defaultLightTemplate = $('script[data-template="defaultLight"]').html();
87120
this.lightTemplate = $('script[data-template="light"]').html();
88-
121+
this.$lightMarkList = $('#lightPosition_container');
89122

90123
// Delegated event to listen for removal clicks
91124
this.$lightList.on('click', '.myLightsTitle .destroy', function(e) {
@@ -100,24 +133,29 @@ $(function() {
100133
render: function() {
101134
// Cache vars for use in forEach() callback (performance)
102135
var $lightList = this.$lightList,
136+
$lightMarkList = this.$lightMarkList,
103137
lightTemplate = this.lightTemplate;
104138

105139
var defaultLightTemplate = lightTemplate.replace(/{{id}}/g, 0).replace("LIGHT0","DEFAULT LIGHT");
106140

107141
// Clear and render
108142
$lightList.html('');
143+
$lightMarkList.html('');
109144
$lightList.append(defaultLightTemplate);
110145

111-
$("#lightPanel0 .destroy").remove();
146+
$("#lightPanel0 .destroy").remove();//can not be deleted
112147

113-
setupLightFunctions(0);//for default light
148+
//for default light
149+
setupLightFunctions(0);//sliderbar checkbox etc, function in sliders.js
150+
drawLightMarkPosition(0);
114151

115152
octopus.getExistLights().forEach(function(light) {
116153

117154
// Replace template markers with data
118155
var thisTemplate = lightTemplate.replace(/{{id}}/g, light.id);
119156
$lightList.append(thisTemplate);
120157
setupLightFunctions(light.id);
158+
drawLightMarkPosition(light.id);
121159
});
122160

123161

@@ -130,6 +168,13 @@ $(function() {
130168
$(lightContentName).addClass('in');
131169

132170
}
171+
172+
//for show lights position
173+
//init default point
174+
175+
176+
177+
133178
}
134179
};
135180

@@ -141,18 +186,78 @@ $(function() {
141186
function addLightParameters(index){
142187
//init parameter
143188
mouseXY[index] = [Math.random()-0.5, Math.random()-0.5];
144-
lightColor[index] =[Math.random()/2+0.5, Math.random()/2+0.5, Math.random()/2+0.5];
189+
lightColor[index] =[Math.random(), Math.random(), Math.random()];
145190
lightIntensity[index] = 0.5;
146191
pointLightDis[index] = 0.5;
147192
showDiffuse[index] = 1;
148193
showSpec[index] = 1;
149194

150-
//mouse stuff
195+
//mouse
151196
var canvas = document.getElementById( "gl-canvas" );
152197
canvas.addEventListener("mousemove", function(evt){
153198
if(mouseFlag === 1){
154-
setMousePos(canvas, evt, index);//this function in "cube.js"
199+
setMousePos(canvas, evt, index);
155200
}
156201
}, false);
157202

158203
}
204+
205+
206+
//for show lights position
207+
208+
function setLightMarkFill(index)
209+
{
210+
var colorString = color2hex(lightColor[index]);
211+
var lightMarkName = '#lightMark'+index;
212+
$(lightMarkName).attr('fill', colorString);
213+
}
214+
215+
function setLightMarkPosition(index)
216+
{
217+
var lightPx = (mouseXY[index][0] + 0.5)*100 + "%";
218+
var lightPy = (mouseXY[index][1] + 0.5)*100 + "%";
219+
220+
var lightMarkName = '#lightMark'+index;
221+
$(lightMarkName).attr('cx', lightPx).attr('cy', lightPy);
222+
223+
console.log("inMark");
224+
}
225+
226+
function drawLightMarkPosition(index){
227+
var lightPx = (mouseXY[index][0] + 0.5)*100 + "%";
228+
var lightPy = (mouseXY[index][1] + 0.5)*100 + "%";
229+
var colorString = color2hex(lightColor[index]);
230+
var lightMark = "lightMark" + index;
231+
var circle= makeSVG('circle', {id:lightMark, cx: lightPx, cy: lightPy, fill: colorString, r:8, stroke: 'white', 'stroke-width': 1,});
232+
document.getElementById('lightPosition_container').appendChild(circle);
233+
}
234+
235+
function makeSVG(tag, attrs) {
236+
var el= document.createElementNS('http://www.w3.org/2000/svg', tag);
237+
for (var k in attrs)
238+
el.setAttribute(k, attrs[k]);
239+
return el;
240+
}
241+
242+
//mouse functions
243+
244+
function setMousePos(canvas, evt, i){
245+
246+
if (currentLight == i)
247+
{
248+
mouseXY[i][0] = getMousePos(canvas, evt).x;
249+
mouseXY[i][1] = getMousePos(canvas, evt).y;
250+
setLightMarkPosition(i);
251+
console.log(i+": "+mouseXY[i][0]+" "+mouseXY[i][1]);
252+
}
253+
254+
}
255+
256+
function getMousePos(canvas, evt) {
257+
var rect = canvas.getBoundingClientRect();
258+
return {
259+
x: (evt.clientX - rect.left)/(rect.right - rect.left) - 0.5,
260+
y: (evt.clientY - rect.top)/(rect.bottom - rect.top) - 0.5
261+
};
262+
}
263+

css/mock3d.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,26 @@ label{margin-bottom:0;}
309309

310310
}
311311

312-
313312
#gl-canvas {
314313
position: relative;
315314
top: 50%;
316315
transform: translateY(-50%);
317316
}
318317

318+
#lightPosition_container{
319+
margin:0 auto;
320+
left: 0;
321+
right: 0;
322+
position:absolute;
323+
display: block;
324+
z-index: 100;
325+
top: 50%;
326+
transform: translateY(-50%);
327+
328+
pointer-events:none;
329+
/*background: rgba(255, 0, 0, 0.5);*/
330+
}
331+
319332

320333

321334

@@ -354,6 +367,9 @@ label{margin-bottom:0;}
354367
text-align: center;
355368
position: relative;
356369
}
370+
.imgThumb {
371+
background-image: url("../img/transparentBG.jpg");
372+
}
357373

358374
.btn-file {
359375
position: absolute;

cube.js

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var lightNum = 1;
66
var mouseXY = [];
77
mouseXY[0] = [0.3, -0.3]; //default light
88

9-
9+
var lightsPosition = 0;
1010
var lightsOnly = 0;
1111

1212
var lightColor = [];
@@ -44,11 +44,11 @@ var FGdis = 0.5;
4444
var FGshiftLR = 0;
4545

4646

47-
47+
//Locs
4848

4949
var currentLightLoc;
5050
var lightNumLoc;
51-
var mouseLoc;;//, mouse1Loc, mouse2Loc;
51+
var mouseLoc;
5252

5353
var lightsOnlyLoc;
5454
var lightColorLoc;
@@ -93,24 +93,10 @@ window.onload = function init()
9393
gl = WebGLUtils.setupWebGL( canvas );
9494
if ( !gl ) { alert( "WebGL isn't available" ); }
9595

96-
/* MOUSE STUFF */
97-
98-
var context = canvas.getContext('2d');
9996

100-
canvas.addEventListener("mousedown", function(evt){
101-
mouseFlag = 1;
102-
}, false);
103-
canvas.addEventListener("mousemove", function(evt){
104-
if(mouseFlag === 1){
105-
setMousePos(canvas, evt, 0);//add default light event;
106-
}
107-
108-
}, false);
109-
canvas.addEventListener("mouseup", function(){
110-
mouseFlag = 0;
111-
//mouseFlag = (mouseFlag ==0)?1:0;
112-
}, false);
97+
var context = canvas.getContext('2d');
11398

99+
114100
/***************/
115101

116102

@@ -286,25 +272,6 @@ function handleTextureLoaded(image, texture) {
286272
}
287273

288274

289-
function setMousePos(canvas, evt, i){
290-
291-
if (currentLight == i)
292-
{
293-
mouseXY[i][0] = getMousePos(canvas, evt).x;
294-
mouseXY[i][1] = getMousePos(canvas, evt).y;
295-
console.log(i+": "+mouseXY[i][0]+" "+mouseXY[i][1]);
296-
}
297-
298-
}
299-
300-
function getMousePos(canvas, evt) {
301-
var rect = canvas.getBoundingClientRect();
302-
return {
303-
x: (evt.clientX - rect.left)/(rect.right - rect.left) - 0.5,
304-
y: (evt.clientY - rect.top)/(rect.bottom - rect.top) - 0.5
305-
};
306-
}
307-
308275
function render() {
309276
gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT );
310277

dragndrop.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ UPLOADinit = function()
6262
//image3.src = "images/bottle/shape.png"
6363
//image5.src = "images/bottle/bg.png"
6464
//image6.src = "images/eye/eye_alpha.jpg";
65-
image6.src = "images/Holmer/Holmer_alphaControl.jpg";
65+
image6.src = "images/Holmer/Holmer_new_alphaControl.png";
6666

6767

6868

@@ -339,19 +339,33 @@ function updateCanvasSizeandStyle(_image)
339339
var canvasContainer = $('.canvas_container');
340340
var ratioImage = _image.width / _image.height;
341341
var ratioContainer = canvasContainer.width() / canvasContainer.height();
342-
342+
343+
var lightPostionContainer = $('#lightPosition_container');
344+
343345
if(ratioImage>=ratioContainer){
344346
canvas.width = canvasContainer.width();
345347
canvas.height = canvas.width * _image.height / _image.width;
346348
canvas.style.width = "100%";
347349
canvas.style.height = "auto";
350+
$(lightPostionContainer).css("width", "100%");
351+
$(lightPostionContainer).css("height", "auto");
352+
353+
348354
}else{
349355
canvas.height = canvasContainer.height() ;
350356
canvas.width = canvas.height * _image.width / _image.height;
351357
canvas.style.height = "100%";
352358
canvas.style.width = "auto";
359+
$(lightPostionContainer).css("height", "100%");
360+
$(lightPostionContainer).css("width", "auto");
361+
353362
}
354363

364+
$(lightPostionContainer).attr("width", canvas.width) ;
365+
$(lightPostionContainer).attr("height", canvas.height);
366+
var viewbox = "0 0 " + canvas.width + " " + canvas.height;
367+
$(lightPostionContainer).attr("viewBox", viewbox);
368+
355369
gl = WebGLUtils.setupWebGL( canvas );
356370
gl.viewport( 0, 0, canvas.width, canvas.height );
357371
gl.clearColor( 0.05, 0.05, 0.05, 1.0 );
105 KB
Loading
221 KB
Loading

img/transparentBG.jpg

41.4 KB
Loading

0 commit comments

Comments
 (0)