Skip to content

Commit

Permalink
imp: 3d web model view
Browse files Browse the repository at this point in the history
  • Loading branch information
mboscolo committed Nov 22, 2024
1 parent 074843c commit d6a943c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
10 changes: 8 additions & 2 deletions plm_web_3d/static/src/js/OdooCADApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function init() {
* Inizialize tree view search
*/
var input_document_tree = document.getElementById('input_search_document_tree');
input_document_tree.addEventListener("keyup", OdooCad.search_document_tree);
//input_document_tree.addEventListener("keyup", OdooCad.search_document_tree);
/*
* function to hide show all components
*/
Expand Down Expand Up @@ -346,8 +346,10 @@ function epsilon( value ) {
function initcommand(){
var element = document.getElementById("fit_view");
element.onclick = function(event) {
fitCameraToSelection(OdooCad.tree_ref_elements,
fitCameraToSelectionEvent();
/* fitCameraToSelection(OdooCad.tree_ref_elements,
1.1);
*/
}
var selector = document.getElementById("webgl_background");
selector.onchange = function(event){
Expand Down Expand Up @@ -500,7 +502,11 @@ var change_object_explosion = function(event){
}

var fitCameraToSelectionEvent = function(e){
if (Object.values(OdooCad.tree_ref_elements).length>0){
fitCameraToSelection(OdooCad.tree_ref_elements,1.1);
return
}
fitCameraToSelection(OdooCad.items,1.1);
}

/**
Expand Down
25 changes: 6 additions & 19 deletions plm_web_3d/static/src/js/lib/odoocad/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ class Loader {
gLTFLoader.load( url, function ( gltf ) {
var children = gltf.scene.children;
var i;
var out_html_structure;
for (i = 0; i < children.length; i++) {
self.odooCad.addItemToScene(children[i]);
out_html_structure+=self.odooCad.addItemToScene(children[i]);
}
self.odooCad.create_tree_structure(out_html_structure)
},
function ( xhr ) {
var percentage = (xhr.loaded / xhr.total) * 100;
Expand All @@ -121,31 +123,16 @@ class Loader {
}

load3mf(document_name, url){

var load3emfObj = function(args){
if(args.type=="Group"){
var i;
var children = args.children;
for (i = 0; i < children.length; i++) {
if(children[i].type=="Mesh"){
self.odooCad.addItemToScene(args);
break;
}
else {
load3emfObj(children[i]);
}
}
}
}

var self=this;
threeMFLoader.load( url,
//load
function ( mfArgs ) {
mfArgs.traverse( function ( child ) {
child.castShadow = true;
} );
self.odooCad.addItemToScene(mfArgs, false);
const out_html_structure = self.odooCad.addItemToScene(mfArgs, false);
self.odooCad.create_tree_structure(out_html_structure)

},
//progress
function ( xhr ) {
Expand Down
31 changes: 22 additions & 9 deletions plm_web_3d/static/src/js/lib/odoocad/odoocad.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ class OdooCAD{
});
object.material=material;
}
//
this.scene.add(object);
this.items.push(object);
this.create_relation_structure(object);
//
const out_htm_structure = this.create_relation_structure(object);
// Center the object
// fit item
progress.display = 'none';
var fitItem = new CustomEvent("OdooCAD_fit_items");
html_canvas.dispatchEvent(fitItem);
// recompute the bounding box
this.active_bbox=this.getBBox();
return out_htm_structure;
}
//

Expand Down Expand Up @@ -164,15 +167,11 @@ class OdooCAD{
}
}
}
create_relation_structure(object){
var self = this;
//
create_tree_structure(out_html_structure){
const self = this;
var html_out = "<div class='tree_structure' style='overflow-y: scroll;min-height: 1px;max-height: 400px;'>";
for (let i = 0; i < object.children.length; i++) {
if (object.children[i].type=='Group'){
const [inner_html, _children] = self.get_li_structure(object.children[i]);
html_out += inner_html;
}
}
html_out += out_html_structure
html_out += "</div>";

var li_document_tree = document.querySelectorAll('#document_tree')
Expand Down Expand Up @@ -233,6 +232,20 @@ class OdooCAD{
this.set_str_name(tree_item_visibility[i])
}
}
//
create_relation_structure(object){
const grp_types = ["Group", "Object3D"];
var self = this;

var html_out = "";
for (let i = 0; i < object.children.length; i++) {
if (grp_types.includes(object.children[i].type)){
const [inner_html, _children] = self.get_li_structure(object.children[i]);
html_out += inner_html;
}
}
return html_out;
}

removeItemToSeen(object){
/* TODO: make the remove operation */
Expand Down
Binary file added plm_web_3d/static/src/models/V6_engine.3mf
Binary file not shown.

0 comments on commit d6a943c

Please sign in to comment.