Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
My proposal patch for copperlicht.js

k.l.
Registered User
Quote
2011-02-10 13:30:46

Overview:
+ added LINES draw mode
+ refined AnimatorCameraModelViewer
+ added mouse wheel handler

--- https://klstrigo.svn.sourceforge.net/svnroot/klstrigo/WebSites/K.L.'s Trigo/tags/copperlicht 1.3.3/copperlicht.js
+++ https://klstrigo.svn.sourceforge.net/svnroot/klstrigo/WebSites/K.L.'s Trigo/trunk/Source/static/js/copperlicht.js
@@ -2056,6 +2056,7 @@
this.Indices = new Array();
this.Vertices = new Array();
this.RendererNativeArray = null;
+ this.DrawMode = CL3D.Renderer.DrawModes.TRIANGLES;
};
CL3D.MeshBuffer.prototype.Box = null;
CL3D.MeshBuffer.prototype.Mat = null;
@@ -2929,9 +2930,18 @@
this.Program2DDrawingColorOnly = null;
this.Program2DDrawingTextureOnly = null;
this.Program2DDrawingCanvasFontColor = null;
- this.Material = null;
+ //this.Material = null;
this.currentGLProgram = null;
};
+CL3D.Renderer.DrawModes = {
+ POINTS: 0x0000,
+ LINES: 0x0001,
+ LINE_LOOP: 0x0002,
+ LINE_STRIP: 0x0003,
+ TRIANGLES: 0x0004,
+ TRIANGLE_STRIP: 0x0005,
+ TRIANGLE_FAN: 0x0006,
+}
CL3D.Renderer.prototype.Material = null;
CL3D.Renderer.prototype.getWidth = function () {
return this.width;
@@ -3048,10 +3058,19 @@
}
var m = a.Indices.length;
var n = new WebGLUnsignedShortArray(m);
- for (var d = 0; d < m; d += 3) {
- n[d + 0] = a.Indices[d + 0];
- n[d + 1] = a.Indices[d + 2];
- n[d + 2] = a.Indices[d + 1];
+ switch(a.DrawMode)
+ {
+ case CL3D.Renderer.DrawModes.TRIANGLES:
+ for (var d = 0; d < m; d += 3) {
+ n[d + 0] = a.Indices[d + 0];
+ n[d + 1] = a.Indices[d + 2];
+ n[d + 2] = a.Indices[d + 1];
+ }
+
+ break;
+ default:
+ for (var d = 0; d < m; ++d)
+ n[d] = a.Indices[d];
}
f.positionBuffer = g.createBuffer();
g.bindBuffer(g.ARRAY_BUFFER, f.positionBuffer);
@@ -3071,6 +3090,7 @@
g.bufferData(g.ELEMENT_ARRAY_BUFFER, n, g.STATIC_DRAW);
f.indexCount = m;
g.bindBuffer(g.ELEMENT_ARRAY_BUFFER, null);
+ f.drawMode = a.DrawMode;
a.RendererNativeArray = f;
}
this.drawWebGlStaticGeometry(a.RendererNativeArray);
@@ -3111,7 +3131,7 @@
f = f.multiply(this.World);
g.uniformMatrix4fv(c.locModelViewMatrix, false, this.getMatrixAsWebGLFloatArray(f));
}
- g.drawElements(g.TRIANGLES, a.indexCount, g.UNSIGNED_SHORT, 0);
+ g.drawElements(a.drawMode, a.indexCount, g.UNSIGNED_SHORT, 0);
};
CL3D.Renderer.prototype.draw3DLine = function (b, a) {};
CL3D.Renderer.prototype.draw2DRectangle = function (k, h, a, p, b, e) {
@@ -5127,7 +5147,7 @@
};
CL3D.AnimatorCameraFPS.prototype. = function (a) {
CL3D.Animator.prototype..call(this, a);
- this.targetZoomValue += a.delta * zoomSpeed;
+ this.targetZoomValue += a.delta * this.zoomSpeed;
if (this.targetZoomValue < this.minZoom) {
this.targetZoomValue = this.minZoom;
}
@@ -5187,7 +5207,7 @@
};
CL3D.AnimatorCameraModelViewer = function (b, a) {
this.Type = -1;
- this.RotateSpeed = 0.06;
+ this.RotateSpeed = 16;
this.Radius = 100;
this.NoVerticalMovement = false;
this.lastAnimTime = CL3D.CLTimer.getTime();
@@ -5224,13 +5244,13 @@
l.Y = 0;
l.normalize();
if (!CL3D.iszero(f)) {
- l.multiplyThisWithScal(a * f);
+ l.multiplyThisWithScal(a * f * this.Radius);
o.addToThis(l);
}
if (!this.NoVerticalMovement && !CL3D.iszero(d)) {
var h = this.Camera.UpVector.clone();
h.normalize();
- var k = o.add(h.multiplyWithScal(a * d));
+ var k = o.add(h.multiplyWithScal(a * d * this.Radius));
var g = k.clone();
g.Y = j.Y;
var p = this.Radius / 10;
@@ -7306,6 +7326,18 @@
b.(a);
}
};
+CL3D.CopperLicht.prototype.handleMouseWheel = function (a) {
+ if (this.MouseIsInside) {
+ var c = this.getScene();
+ if (c == null) {
+ return;
+ }
+ var b = c.getActiveCamera();
+ if (b != null) {
+ b.(a);
+ }
+ }
+};
CL3D.CopperLicht.prototype.OnAnimate = null;
CL3D.CopperLicht.prototype.OnAfterDrawAll = null;



k.l.
Registered User
Quote
2011-02-10 13:39:28

The diff file's work base is a formatted version of copperlicht.js 1.3.3 release, view this via http://goo.gl/7OVtS

And this is the modified version: http://goo.gl/6kpAV

Beside that, I wrote an attached js file to enhance CopperLicht. One feature is storing shader parameters for material type in Renderer, another is mouse wheel zoom for AnimatorCameraModelViewer.

CL3D.Renderer.prototype.MaterialUniforms = {};

CL3D.Renderer.prototype.createMaterialTypeEx = function(vs, fs, uniforms, blendenabled, blendsfactor, blenddfactor) {
var type = this.createMaterialType(vs, fs, blendenabled, blendsfactor, blenddfactor);

this.MaterialUniforms[type] = uniforms;

return type;
};

CL3D.Renderer.prototype.On*ChangeMaterialMaterial = function(mattype) {
var uniforms = this.MaterialUniforms[mattype];
if (uniforms) {
var gl = this.getWebGL();
var program = this.getGLProgramFromMaterialType(mattype);
$.each(uniforms, function(key, uniform) {
var location = gl.getUniformLocation(program, key);

if (typeof (uniform) == "number")
gl.uniform1f(location, uniform);
else
switch (uniform.length) {
case 1:
gl.uniform1f(location, uniform[0]);
break;
case 2:
gl.uniform2f(location, uniform[0], uniform[1]);
break;
case 3:
gl.uniform3f(location, uniform[0], uniform[1], uniform[2]);
break;
case 4:
gl.uniform4f(location, uniform[0], uniform[1], uniform[2], uniform[3]);
break;
default:
throw "invalid uniform length: " + uniform.length;
}
});
}
};

CL3D.AnimatorCameraModelViewer.prototype.onMouse*Wheel = function (event) {
CL3D.Animator.prototype.onMouse*Wheel.call(this, event);

this.Radius *= Math.exp(-event.wheelDelta / 600);
this.Radius = Math.max(this.Radius, 0.9);
this.Radius = Math.min(this.Radius, 300);
}


PS: It's strange, word of 'onMouse*Wheel' and 'On*Change' may disappered after submitted, so I added a star symbol between letters.


niko
Moderator
Quote
2011-02-11 07:48:30

Thanks for posting, I'll consider adding someting like that. :)


kingkohle
Registered User
Quote
2011-02-12 22:25:50

+1


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact