Set background color when using the viewer on your website #92

This commit is contained in:
kovacsv 2021-06-24 19:36:15 +02:00
parent f4b8ca18c6
commit 14d11a0c41
3 changed files with 20 additions and 4 deletions

View File

@ -110,7 +110,8 @@
<div class="online_3d_viewer"
style="width: 360px; height: 240px;"
model="../../test/testfiles/obj/hundred_cubes.obj"
color="200,0,0">
color="200,0,0"
background="200,200,200">
</div>
<div class="online_3d_viewer"
style="width: 360px; height: 240px;"

View File

@ -55,6 +55,14 @@ OV.Init3DViewerElements = function (onReady)
},
});
let backgroundParam = element.getAttribute ('background');
if (backgroundParam) {
let color = OV.ParameterConverter.StringToColor (backgroundParam);
if (color !== null) {
viewer.SetBackgroundColor (color);
}
}
let modelParams = element.getAttribute ('model');
if (!modelParams) {
return;
@ -66,9 +74,9 @@ OV.Init3DViewerElements = function (onReady)
}
let settings = new OV.ImportSettings ();
let colorParams = element.getAttribute ('color');
if (colorParams) {
let color = OV.ParameterConverter.StringToColor (colorParams);
let colorParam = element.getAttribute ('color');
if (colorParam) {
let color = OV.ParameterConverter.StringToColor (colorParam);
if (color !== null) {
settings.defaultColor = color;
}

View File

@ -180,6 +180,13 @@ OV.Viewer = class
this.navigation.SetClickHandler (onClick);
}
SetBackgroundColor (color)
{
let hexColor = '#' + OV.ColorToHexString (color);
this.renderer.setClearColor (hexColor, 1.0);
this.Render ();
}
GetCamera ()
{
return this.navigation.GetCamera ();