Skip to content

Commit

Permalink
IMP: 3d model render on glb file
Browse files Browse the repository at this point in the history
now it's possibile olso to render the tree
  • Loading branch information
mboscolo committed Oct 7, 2024
1 parent 3f0043b commit 406c9a9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
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
38 changes: 25 additions & 13 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 @@ -103,11 +106,11 @@ class OdooCAD{
for (let i = 0; i < object.children.length; i++) {
if (object.children[i].type=='Group' || object.children[i].name!=''){
const [inner_html, children_found] = self.get_li_structure(object.children[i], true);
var obj_name=object.children[i].name;
var obj_name = object.children[i].name;
var internal_obj_name = guid()
var span_lable = "<span class='document_tree_span' webgl_ref_name='" + internal_obj_name + "'>" + obj_name + "</span>";
if(children_found || object.children[i].name!=''){
self.tree_ref_elements[internal_obj_name]=object.children[i]
self.tree_ref_elements[internal_obj_name] = object.children[i]
out_lis += "<li class='document_tree_line' webgl_ref_name="+ internal_obj_name +"><i class='tree_item_visibility fa fa-eye' aria-hidden='true'></i><span class='caret'>" + span_lable + "</span>" + inner_html + "</li>";
}
else{
Expand Down Expand Up @@ -164,20 +167,15 @@ 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')
li_document_tree[0].innerHTML=html_out;
var toggler = document.getElementsByClassName("caret");
var toggler = document.getElementsByClassName("caret");
var i;

for (i = 0; i < toggler.length; i++) {
Expand Down Expand Up @@ -233,6 +231,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

0 comments on commit 406c9a9

Please sign in to comment.