From 5184fe93468e37b9ac26d85069f20b653a532d9b Mon Sep 17 00:00:00 2001 From: Viktor Kovacs Date: Fri, 21 May 2021 09:38:09 +0200 Subject: [PATCH] Move material and triangle to a separate file. --- sandbox/embed_selfhost_fullscreen.html | 3 +- sandbox/embed_selfhost_multiple.html | 3 +- sandbox/embed_selfhost_single.html | 3 +- sandbox/embed_selfhost_single_scroll.html | 3 +- .../model/{modelentities.js => material.js} | 106 ++---------------- source/model/triangle.js | 81 +++++++++++++ tools/config.json | 3 +- website/embed.html | 3 +- website/index.html | 3 +- 9 files changed, 107 insertions(+), 101 deletions(-) rename source/model/{modelentities.js => material.js} (75%) create mode 100644 source/model/triangle.js diff --git a/sandbox/embed_selfhost_fullscreen.html b/sandbox/embed_selfhost_fullscreen.html index b59abd0..79ce964 100644 --- a/sandbox/embed_selfhost_fullscreen.html +++ b/sandbox/embed_selfhost_fullscreen.html @@ -24,7 +24,8 @@ - + + diff --git a/sandbox/embed_selfhost_multiple.html b/sandbox/embed_selfhost_multiple.html index c52f992..7bb646e 100644 --- a/sandbox/embed_selfhost_multiple.html +++ b/sandbox/embed_selfhost_multiple.html @@ -25,7 +25,8 @@ - + + diff --git a/sandbox/embed_selfhost_single.html b/sandbox/embed_selfhost_single.html index 473a3ba..f6a0b73 100644 --- a/sandbox/embed_selfhost_single.html +++ b/sandbox/embed_selfhost_single.html @@ -24,7 +24,8 @@ - + + diff --git a/sandbox/embed_selfhost_single_scroll.html b/sandbox/embed_selfhost_single_scroll.html index 60c4193..3616919 100644 --- a/sandbox/embed_selfhost_single_scroll.html +++ b/sandbox/embed_selfhost_single_scroll.html @@ -24,7 +24,8 @@ - + + diff --git a/source/model/modelentities.js b/source/model/material.js similarity index 75% rename from source/model/modelentities.js rename to source/model/material.js index e4b873e..f10af99 100644 --- a/source/model/modelentities.js +++ b/source/model/material.js @@ -1,21 +1,3 @@ -OV.SRGBToLinear = function (component) -{ - if (component < 0.04045) { - return component * 0.0773993808; - } else { - return Math.pow (component * 0.9478672986 + 0.0521327014, 2.4); - } -}; - -OV.LinearToSRGB = function (component) -{ - if (component < 0.0031308) { - return component * 12.92; - } else { - return 1.055 * (Math.pow (component, 0.41666)) - 0.055; - } -}; - OV.Color = class { constructor (r, g, b) @@ -162,85 +144,21 @@ OV.Material = class } }; -OV.Triangle = class +OV.SRGBToLinear = function (component) { - constructor (v0, v1, v2) - { - this.v0 = v0; - this.v1 = v1; - this.v2 = v2; - - this.n0 = null; - this.n1 = null; - this.n2 = null; - - this.u0 = null; - this.u1 = null; - this.u2 = null; - - this.mat = null; - this.curve = null; + if (component < 0.04045) { + return component * 0.0773993808; + } else { + return Math.pow (component * 0.9478672986 + 0.0521327014, 2.4); } +}; - HasVertices () - { - return this.v0 !== null && this.v1 !== null && this.v2 !== null; - } - - HasNormals () - { - return this.n0 !== null && this.n1 !== null && this.n2 !== null; - } - - HasTextureUVs () - { - return this.u0 !== null && this.u1 !== null && this.u2 !== null; - } - - SetVertices (v0, v1, v2) - { - this.v0 = v0; - this.v1 = v1; - this.v2 = v2; - return this; - } - - SetNormals (n0, n1, n2) - { - this.n0 = n0; - this.n1 = n1; - this.n2 = n2; - return this; - } - - SetTextureUVs (u0, u1, u2) - { - this.u0 = u0; - this.u1 = u1; - this.u2 = u2; - return this; - } - - SetMaterial (mat) - { - this.mat = mat; - return this; - } - - SetCurve (curve) - { - this.curve = curve; - return this; - } - - Clone () - { - let cloned = new OV.Triangle (this.v0, this.v1, this.v2); - cloned.SetNormals (this.n0, this.n1, this.n2); - cloned.SetTextureUVs (this.u0, this.u1, this.u2); - cloned.SetMaterial (this.mat); - cloned.SetCurve (this.curve); - return cloned; +OV.LinearToSRGB = function (component) +{ + if (component < 0.0031308) { + return component * 12.92; + } else { + return 1.055 * (Math.pow (component, 0.41666)) - 0.055; } }; diff --git a/source/model/triangle.js b/source/model/triangle.js new file mode 100644 index 0000000..25543c5 --- /dev/null +++ b/source/model/triangle.js @@ -0,0 +1,81 @@ +OV.Triangle = class +{ + constructor (v0, v1, v2) + { + this.v0 = v0; + this.v1 = v1; + this.v2 = v2; + + this.n0 = null; + this.n1 = null; + this.n2 = null; + + this.u0 = null; + this.u1 = null; + this.u2 = null; + + this.mat = null; + this.curve = null; + } + + HasVertices () + { + return this.v0 !== null && this.v1 !== null && this.v2 !== null; + } + + HasNormals () + { + return this.n0 !== null && this.n1 !== null && this.n2 !== null; + } + + HasTextureUVs () + { + return this.u0 !== null && this.u1 !== null && this.u2 !== null; + } + + SetVertices (v0, v1, v2) + { + this.v0 = v0; + this.v1 = v1; + this.v2 = v2; + return this; + } + + SetNormals (n0, n1, n2) + { + this.n0 = n0; + this.n1 = n1; + this.n2 = n2; + return this; + } + + SetTextureUVs (u0, u1, u2) + { + this.u0 = u0; + this.u1 = u1; + this.u2 = u2; + return this; + } + + SetMaterial (mat) + { + this.mat = mat; + return this; + } + + SetCurve (curve) + { + this.curve = curve; + return this; + } + + Clone () + { + let cloned = new OV.Triangle (this.v0, this.v1, this.v2); + cloned.SetNormals (this.n0, this.n1, this.n2); + cloned.SetTextureUVs (this.u0, this.u1, this.u2); + cloned.SetMaterial (this.mat); + cloned.SetCurve (this.curve); + return cloned; + } +}; diff --git a/tools/config.json b/tools/config.json index 6540c85..d8db6e1 100644 --- a/tools/config.json +++ b/tools/config.json @@ -20,7 +20,8 @@ "source/io/textwriter.js", "source/io/bufferutils.js", "source/io/fileutils.js", - "source/model/modelentities.js", + "source/model/material.js", + "source/model/triangle.js", "source/model/element.js", "source/model/mesh.js", "source/model/meshbuffer.js", diff --git a/website/embed.html b/website/embed.html index d3eb546..f0f950a 100644 --- a/website/embed.html +++ b/website/embed.html @@ -33,7 +33,8 @@ - + + diff --git a/website/index.html b/website/index.html index b035413..70b1935 100644 --- a/website/index.html +++ b/website/index.html @@ -33,7 +33,8 @@ - + +