Read meta data from glTF.

This commit is contained in:
kovacsv 2021-06-20 18:40:50 +02:00
parent c7f0d128a7
commit 89796d2971
4 changed files with 54 additions and 26 deletions

View File

@ -476,6 +476,8 @@ OV.ImporterGltf = class extends OV.ImporterBase
ProcessMainFile (gltf)
{
this.ImportModelProperties (gltf);
let unsupportedExtensions = this.gltfExtensions.GetUnsupportedExtensions (gltf.extensionsRequired);
if (unsupportedExtensions.length > 0) {
this.SetError ();
@ -504,6 +506,18 @@ OV.ImporterGltf = class extends OV.ImporterBase
}
}
ImportModelProperties (gltf)
{
for (let propertyName in gltf.asset) {
if (gltf.asset.hasOwnProperty (propertyName)) {
if (typeof gltf.asset[propertyName] === 'string') {
const property = new OV.Property (OV.PropertyType.Text, propertyName, gltf.asset[propertyName]);
this.model.AddProperty (property);
}
}
}
}
GetDefaultScene (gltf)
{
let defaultSceneIndex = gltf.scene || 0;

View File

@ -16,6 +16,7 @@
<li><a href="index.html#model=../test/testfiles/obj/hundred_cubes.obj,../test/testfiles/obj/hundred_cubes.mtl">hundred_cubes.obj</a></li>
<li><a href="index.html#model=../test/testfiles/obj/icosahedron.obj">icosahedron.obj</a></li>
<li><a href="index.html#model=../test/testfiles/obj/error.obj">error.obj</a></li>
<li><a href="index.html#model=../test/testfiles/gltf/Box/glTF-Binary/Box.glb">Box.glb</a></li>
</ul>
</body>

View File

@ -38,27 +38,20 @@ OV.Sidebar = class
return this.visible;
}
CreatePropertyTable ()
{
this.Clear ();
let table = $('<table>').addClass ('ov_property_table').appendTo (this.contentDiv);
return table;
}
AddProperty (table, property)
{
let row = $('<tr>').appendTo (table);
let nameColum = $('<td>').addClass ('ov_property_table_name').appendTo (row);
let valueColumn = $('<td>').addClass ('ov_property_table_value').appendTo (row);
let row = $('<div>').addClass ('ov_property_table_row').appendTo (table);
let nameColum = $('<div>').addClass ('ov_property_table_cell ov_property_table_name').appendTo (row);
let valueColumn = $('<div>').addClass ('ov_property_table_cell ov_property_table_value').appendTo (row);
nameColum.html (property.name + ':').attr ('title', property.name);
this.DisplayPropertyValue (property, valueColumn);
}
AddCalculatedProperty (table, name, calculateValue)
{
let row = $('<tr>').appendTo (table);
let nameColum = $('<td>').addClass ('ov_property_table_name').appendTo (row);
let valueColumn = $('<td>').addClass ('ov_property_table_value').appendTo (row);
let row = $('<div>').addClass ('ov_property_table_row').appendTo (table);
let nameColum = $('<div>').addClass ('ov_property_table_cell ov_property_table_name').appendTo (row);
let valueColumn = $('<div>').addClass ('ov_property_table_cell ov_property_table_value').appendTo (row);
nameColum.html (name + ':').attr ('title', name);
let obj = this;
@ -106,7 +99,7 @@ OV.Sidebar = class
AddElementProperties (element)
{
this.Clear ();
let table = this.CreatePropertyTable ();
let table = $('<div>').addClass ('ov_property_table').appendTo (this.contentDiv);
let boundingBox = OV.GetBoundingBox (element);
let size = OV.SubCoord3D (boundingBox.max, boundingBox.min);
this.AddProperty (table, new OV.Property (OV.PropertyType.Integer, 'Vertex Count', element.VertexCount ()));
@ -128,6 +121,13 @@ OV.Sidebar = class
}
return new OV.Property (OV.PropertyType.Number, null, volume);
});
if (element.PropertyCount () > 0) {
let customTable = $('<div>').addClass ('ov_property_table ov_property_table_custom').appendTo (this.contentDiv);
for (let i = 0; i < element.PropertyCount (); i++) {
const property = element.GetProperty (i);
this.AddProperty (customTable, property);
}
}
this.Resize ();
}
@ -143,7 +143,7 @@ OV.Sidebar = class
}
this.Clear ();
let table = this.CreatePropertyTable ();
let table = $('<div>').addClass ('ov_property_table').appendTo (this.contentDiv);
this.AddProperty (table, new OV.Property (OV.PropertyType.Color, 'Color', material.diffuse));
this.AddProperty (table, new OV.Property (OV.PropertyType.Percent, 'Opacity', material.opacity));
AddTextureMap (this, table, 'Diffuse Map', material.diffuseMap);

View File

@ -657,34 +657,47 @@ div.ov_progress div.ov_progress_text
text-align: center;
}
table.ov_property_table
div.ov_property_table
{
width: 100%;
border-collapse: collapse;
}
table.ov_property_table td
div.ov_property_table_custom
{
margin-top: 8px;
padding-top: 8px;
border-top: 1px solid #dddddd;
}
div.ov_property_table div.ov_property_table_row
{
overflow: auto;
}
div.ov_property_table div.ov_property_table_cell
{
padding: 4px 0px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
display: inline-block;
box-sizing: border-box;
}
table.ov_property_table td.ov_property_table_name
div.ov_property_table div.ov_property_table_name
{
width: 45%;
padding-right: 8%;
width: 49%;
padding-right: 2%;
float: left;
}
table.ov_property_table td.ov_property_table_value
div.ov_property_table div.ov_property_table_value
{
width: 45%;
width: 49%;
text-align: right;
float: left;
}
table.ov_property_table div.ov_property_table_button
div.ov_property_table div.ov_property_table_button
{
color: #3393bd;
cursor: pointer;