Change canvas background color #85

Option to set default material for meshes with no material information #45
This commit is contained in:
kovacsv 2021-08-14 11:12:41 +02:00
parent 8d53fe94b3
commit 8493391517
17 changed files with 151 additions and 152 deletions

View File

@ -62,4 +62,4 @@ The repository is separated into two parts. See more information in the [Develop
## External Libraries
Online 3D Viewer uses these wonderful libraries: [jquery](https://github.com/jquery/jquery), [three.js](https://github.com/mrdoob/three.js), [draco](https://github.com/google/draco), [rhino3dm](https://github.com/mcneel/rhino3dm), [web-ifc](https://github.com/tomvandig/web-ifc).
Online 3D Viewer uses these wonderful libraries: [jquery](https://github.com/jquery/jquery), [pickr](https://github.com/Simonwep/pickr), [three.js](https://github.com/mrdoob/three.js), [draco](https://github.com/google/draco), [rhino3dm](https://github.com/mcneel/rhino3dm), [web-ifc](https://github.com/tomvandig/web-ifc).

File diff suppressed because one or more lines are too long

21
libs/pickr.license.md Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 - 2021 Simon Reinisch
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3
libs/pickr.min-1.8.2.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -29,6 +29,7 @@
"globals": {
"OV": "writable",
"$": "readonly",
"Pickr": "readonly",
"THREE": "readonly",
"DracoDecoderModule": "readonly",
"rhino3dm": "readonly",

View File

@ -254,6 +254,17 @@ OV.IsSolid = function (element)
return true;
};
OV.HasDefaultMaterial = function (model)
{
for (let i = 0; i < model.MaterialCount (); i++) {
let material = model.GetMaterial (i);
if (material.isDefault) {
return true;
}
}
return false;
};
OV.ReplaceDefaultMaterialColor = function (model, color)
{
for (let i = 0; i < model.MaterialCount (); i++) {

View File

@ -1,6 +1,8 @@
{
"lib_files" : [
"libs/jquery-3.5.1.min.js",
"libs/pickr.monolith.min-1.8.2.css",
"libs/pickr.min-1.8.2.js",
"libs/three.min-129.js"
],
"engine_files" : [

View File

@ -1,59 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xml:space="preserve"
style="enable-background:new 0 0 18 18;"
viewBox="0 0 18 18"
y="0px"
x="0px"
id="Layer_1"
version="1.1"
sodipodi:docname="settings.svg"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1536"
inkscape:window-height="801"
id="namedview16"
showgrid="false"
inkscape:zoom="35.111111"
inkscape:cx="8.6439873"
inkscape:cy="9"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="Layer_1" /><metadata
id="metadata60"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs
id="defs58" />
<style
id="style49"
type="text/css">
.st0{fill:none;stroke:#263238;stroke-linecap:round;stroke-linejoin:round;}
.st1{fill:#FFFFFF;stroke:#263238;stroke-miterlimit:10;}
</style>
<path
id="path51"
d="M14.9,7.9L17,6.1l0,0c-0.2-0.5-0.4-0.9-0.6-1.4c-0.3-0.4-0.6-0.9-0.9-1.2l0,0l-2.6,1C12.4,4,11.7,3.6,11,3.3 l0,0l-0.4-2.7l0,0C10,0.5,9.5,0.5,9,0.5s-1,0-1.5,0.1l0,0L7,3.3C6.3,3.6,5.7,3.9,5.1,4.4l0,0l-2.6-1l0,0C2.2,3.9,1.9,4.3,1.6,4.8 C1.4,5.2,1.2,5.7,1,6.1l0,0l2.1,1.7C3,8.6,3,9.4,3.1,10.1l0,0L1,11.9l0,0c0.2,0.5,0.4,0.9,0.6,1.4c0.3,0.4,0.6,0.9,0.9,1.2l0,0 l2.6-1C5.6,14,6.3,14.4,7,14.7l0,0l0.4,2.7l0,0c0.5,0.1,1,0.1,1.5,0.1s1,0,1.5-0.1l0,0l0.4-2.7c0.7-0.2,1.4-0.6,1.9-1.1l0,0l2.6,1 l0,0c0.3-0.4,0.6-0.8,0.9-1.3c0.3-0.4,0.5-0.9,0.6-1.4l0,0l-2.1-1.7C15,9.4,15,8.6,14.9,7.9"
class="st0" />
<circle
id="circle53"
r="2.5"
cy="9"
cx="9"
class="st1"
style="fill:none" />
</svg>
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="enable-background:new 0 0 18 18" viewBox="0 0 18 18"><path d="M14.9 7.9 17 6.1h0c-.2-.5-.4-.9-.6-1.4-.3-.4-.6-.9-.9-1.2h0l-2.6 1c-.5-.5-1.2-.9-1.9-1.2h0L10.6.6h0C10 .5 9.5.5 9 .5s-1 0-1.5.1h0L7 3.3c-.7.3-1.3.6-1.9 1.1h0l-2.6-1h0c-.3.5-.6.9-.9 1.4-.2.4-.4.9-.6 1.3h0l2.1 1.7c-.1.8-.1 1.6 0 2.3h0L1 11.9h0c.2.5.4.9.6 1.4.3.4.6.9.9 1.2h0l2.6-1c.5.5 1.2.9 1.9 1.2h0l.4 2.7h0c.5.1 1 .1 1.5.1s1 0 1.5-.1h0l.4-2.7c.7-.2 1.4-.6 1.9-1.1h0l2.6 1h0c.3-.4.6-.8.9-1.3.3-.4.5-.9.6-1.4h0l-2.1-1.7c.3-.8.3-1.6.2-2.3" style="fill:none;stroke:#263238;stroke-linecap:round;stroke-linejoin:round"/><circle r="2.5" cy="9" cx="9" style="fill:none;stroke:#263238;stroke-miterlimit:10"/></svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 737 B

View File

@ -1,59 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xml:space="preserve"
style="enable-background:new 0 0 18 18;"
viewBox="0 0 18 18"
y="0px"
x="0px"
id="Layer_1"
version="1.1"
sodipodi:docname="settings_active.svg"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1536"
inkscape:window-height="801"
id="namedview24"
showgrid="false"
inkscape:zoom="13.111111"
inkscape:cx="8.0466102"
inkscape:cy="9"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="Layer_1" /><metadata
id="metadata86"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs
id="defs84" />
<style
id="style75"
type="text/css">
.st0{fill:none;stroke:#3393BD;stroke-linecap:round;stroke-linejoin:round;}
.st1{fill:#FFFFFF;stroke:#3393BD;stroke-miterlimit:10;}
</style>
<path
id="path77"
d="M14.9,7.9L17,6.1l0,0c-0.2-0.5-0.4-0.9-0.6-1.4c-0.3-0.4-0.6-0.9-0.9-1.2l0,0l-2.6,1C12.4,4,11.7,3.6,11,3.3 l0,0l-0.4-2.7l0,0C10,0.5,9.5,0.5,9,0.5s-1,0-1.5,0.1l0,0L7,3.3C6.3,3.6,5.7,3.9,5.1,4.4l0,0l-2.6-1l0,0C2.2,3.9,1.9,4.3,1.6,4.8 C1.4,5.2,1.2,5.7,1,6.1l0,0l2.1,1.7C3,8.6,3,9.4,3.1,10.1l0,0L1,11.9l0,0c0.2,0.5,0.4,0.9,0.6,1.4c0.3,0.4,0.6,0.9,0.9,1.2l0,0 l2.6-1C5.6,14,6.3,14.4,7,14.7l0,0l0.4,2.7l0,0c0.5,0.1,1,0.1,1.5,0.1s1,0,1.5-0.1l0,0l0.4-2.7c0.7-0.2,1.4-0.6,1.9-1.1l0,0l2.6,1 l0,0c0.3-0.4,0.6-0.8,0.9-1.3c0.3-0.4,0.5-0.9,0.6-1.4l0,0l-2.1-1.7C15,9.4,15,8.6,14.9,7.9"
class="st0" />
<circle
id="circle79"
r="2.5"
cy="9"
cx="9"
class="st1"
style="fill:none" />
</svg>
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="enable-background:new 0 0 18 18" viewBox="0 0 18 18"><path d="M14.9 7.9 17 6.1h0c-.2-.5-.4-.9-.6-1.4-.3-.4-.6-.9-.9-1.2h0l-2.6 1c-.5-.5-1.2-.9-1.9-1.2h0L10.6.6h0C10 .5 9.5.5 9 .5s-1 0-1.5.1h0L7 3.3c-.7.3-1.3.6-1.9 1.1h0l-2.6-1h0c-.3.5-.6.9-.9 1.4-.2.4-.4.9-.6 1.3h0l2.1 1.7c-.1.8-.1 1.6 0 2.3h0L1 11.9h0c.2.5.4.9.6 1.4.3.4.6.9.9 1.2h0l2.6-1c.5.5 1.2.9 1.9 1.2h0l.4 2.7h0c.5.1 1 .1 1.5.1s1 0 1.5-.1h0l.4-2.7c.7-.2 1.4-.6 1.9-1.1h0l2.6 1h0c.3-.4.6-.8.9-1.3.3-.4.5-.9.6-1.4h0l-2.1-1.7c.3-.8.3-1.6.2-2.3" style="fill:none;stroke:#3393bd;stroke-linecap:round;stroke-linejoin:round"/><circle r="2.5" cy="9" cx="9" style="fill:none;stroke:#3393bd;stroke-miterlimit:10"/></svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 737 B

View File

@ -13,6 +13,8 @@
<!-- libs start -->
<script type="text/javascript" src="../libs/jquery-3.5.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="../libs/pickr.monolith.min-1.8.2.css">
<script type="text/javascript" src="../libs/pickr.min-1.8.2.js"></script>
<script type="text/javascript" src="../libs/three.min-129.js"></script>
<!-- libs end -->

View File

@ -10,6 +10,8 @@
<!-- libs start -->
<script type="text/javascript" src="../libs/jquery-3.5.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="../libs/pickr.monolith.min-1.8.2.css">
<script type="text/javascript" src="../libs/pickr.min-1.8.2.js"></script>
<script type="text/javascript" src="../libs/three.min-129.js"></script>
<!-- libs end -->

View File

@ -287,7 +287,8 @@ div.ov_sidebar_title img.ov_sidebar_title_img
div.ov_sidebar_subtitle
{
font-weight: bold;
overflow: auto;
}
div.ov_sidebar_content
@ -297,33 +298,34 @@ div.ov_sidebar_content
div.ov_sidebar_content div.ov_sidebar_settings_content
{
margin: 10px 0px;
margin-bottom: 20px;
overflow: auto;
}
div.ov_sidebar_content div.ov_sidebar_small_column
div.ov_sidebar_content div.ov_sidebar_settings_description
{
width: 50px;
float: left;
color: #838383;
margin: 10px 0px 0px 43px;
}
div.ov_sidebar_content div.ov_sidebar_column
{
width: 250px;
float: left;
}
div.ov_sidebar_content input.ov_sidebar_color
div.ov_sidebar_content button.pcr-button
{
width: 30px;
height: 18px;
height: 15px;
margin: 3px 10px 3px 3px;
border: 1px solid #cccccc;
outline: none;
float: left;
}
div.ov_sidebar_content div.ov_sidebar_settings_button
{
color: #3393bd;
text-align: right;
margin-top: 25px;
background: transparent;
text-align: center;
padding: 3px;
border: 1px solid #3393bd;
border-radius: 5px;
cursor: pointer;
}

View File

@ -12,35 +12,81 @@ OV.SettingsSidebarPanel = class extends OV.SidebarPanel
return 'Settings';
}
HidePopups ()
{
this.backgroundColorInput.hide ();
this.defaultColorInput.hide ();
}
InitSettings (settings, defaultSettings, callbacks)
{
this.backgroundColorInput = this.AddColorParameters ('Background Color', 'Changing the background color affects only the visualization.', settings.backgroundColor, callbacks.onBackgroundColorChange);
this.defaultColorInput = this.AddColorParameters ('Default Color', 'Default color is used when no material was defined in the file.', settings.defaultColor, callbacks.onDefaultColorChange);
this.AddResetToDefaultsButton (defaultSettings, callbacks);
}
AddColorParameters (title, description, defaultValue, onChange)
{
$('<div>').addClass ('ov_sidebar_subtitle').html (title).appendTo (this.contentDiv);
let contentDiv = $('<div>').addClass ('ov_sidebar_settings_content').appendTo (this.contentDiv);
let colorColumn = $('<div>').addClass ('ov_sidebar_small_column').appendTo (contentDiv);
$('<div>').addClass ('ov_sidebar_column').html (description).appendTo (contentDiv);
let colorInput = $('<input>').attr ('type', 'color').addClass ('ov_sidebar_color').appendTo (colorColumn);
colorInput.val ('#' + OV.ColorToHexString (defaultValue));
colorInput.change (() => {
let colorStr = colorInput.val ().substr (1);
onChange (OV.HexStringToColor (colorStr));
let titleDiv = $('<div>').addClass ('ov_sidebar_subtitle').appendTo (contentDiv);
$('<div>').addClass ('ov_sidebar_settings_description').html (description).appendTo (contentDiv);
let colorInput = $('<div>').addClass ('color-picker').addClass ('ov_sidebar_color').appendTo (titleDiv);
$('<span>').html (title).appendTo (titleDiv);
const pickr = Pickr.create ({
el : colorInput.get (0),
theme : 'monolith',
appClass : 'ov_sidebar_color',
swatches : [
'#225588',
'#225588',
'#225588',
'#225588',
'#225588',
'#225588',
'#225588',
'#225588',
],
comparison : false,
default : '#' + OV.ColorToHexString (defaultValue),
components : {
preview : true,
opacity : false,
hue : true,
interaction: {
hex : false,
rgba : false,
hsla : false,
hsva : false,
cmyk : false,
input : true,
clear : false,
save : false
}
}
});
return colorInput;
let selectedColor = null;
pickr.on ('change', (color, source, instance) => {
selectedColor = color;
let rgbaColor = selectedColor.toRGBA ();
let color2 = new OV.Color (rgbaColor[0], rgbaColor[1], rgbaColor[2]);
onChange (color2);
}).on ('hide', instance => {
if (selectedColor !== null) {
let rgbaColor = selectedColor.toRGBA ();
let color = new OV.Color (rgbaColor[0], rgbaColor[1], rgbaColor[2]);
onChange (color);
}
console.log ('Event: "hide"', instance);
});
return pickr;
}
AddResetToDefaultsButton (defaultSettings, callbacks)
{
let resetToDefaultsButton = $('<div>').addClass ('ov_sidebar_settings_button').html ('Reset to Defaults').appendTo (this.contentDiv);
let resetToDefaultsButton = $('<div>').addClass ('ov_sidebar_settings_button').html ('Reset to Default').appendTo (this.contentDiv);
resetToDefaultsButton.click (() => {
this.backgroundColorInput.val ('#' + OV.ColorToHexString (defaultSettings.backgroundColor));
this.defaultColorInput.val ('#' + OV.ColorToHexString (defaultSettings.defaultColor));
this.backgroundColorInput.setColor ('#' + OV.ColorToHexString (defaultSettings.backgroundColor));
this.defaultColorInput.setColor ('#' + OV.ColorToHexString (defaultSettings.defaultColor));
callbacks.onBackgroundColorChange (defaultSettings.backgroundColor);
callbacks.onDefaultColorChange (defaultSettings.defaultColor);
});

View File

@ -57,6 +57,13 @@ OV.Sidebar = class
return null;
}
HidePopups ()
{
for (let id = 0; id < this.panels.length; id++) {
this.panels[id].HidePopups ();
}
}
Resize ()
{
for (let id = 0; id < this.panels.length; id++) {

View File

@ -51,4 +51,9 @@ OV.SidebarPanel = class
{
this.contentDiv.empty ();
}
HidePopups ()
{
}
};

View File

@ -106,16 +106,22 @@ OV.Website = class
ClearModel ()
{
if (this.dialog !== null) {
this.dialog.Hide ();
this.dialog = null;
}
this.HidePopups ();
this.model = null;
this.parameters.introDiv.hide ();
this.ShowViewer (false);
this.viewer.Clear ();
this.navigator.Clear ();
}
HidePopups ()
{
if (this.dialog !== null) {
this.dialog.Hide ();
this.dialog = null;
}
this.sidebar.HidePopups ();
}
OnModelFinished (importResult, threeMeshes)
{
@ -548,7 +554,7 @@ OV.Website = class
ShowSidebar (this.sidebar, this.cookieHandler, sidebarPanels, null);
this.Resize ();
}
});
});
}
let defaultSettings = new OV.WebsiteSettings ();