From 27571942c9bb13f147fe3afc88c1be4e4ad74846 Mon Sep 17 00:00:00 2001 From: "qihao.gong@jikimo.com" Date: Tue, 29 Aug 2023 15:49:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E8=82=8COCC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/product_template.py | 32 ++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index 16e65e85..dbeb7814 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -1,8 +1,8 @@ from odoo import models, fields, api from odoo.exceptions import ValidationError from odoo.modules import get_resource_path -# from OCC.Extend.DataExchange import read_step_file -# from OCC.Extend.DataExchange import write_stl_file +from OCC.Extend.DataExchange import read_step_file +from OCC.Extend.DataExchange import write_stl_file import logging import base64 import hashlib @@ -566,20 +566,20 @@ class ResProductMo(models.Model): item.model_file = self.transition_glb_file(report_path, model_code) # 将attach的datas内容转为glb文件 - # def transition_glb_file(self, report_path, code): - # shapes = read_step_file(report_path) - # output_file = os.path.join('/tmp', str(code) + '.stl') - # write_stl_file(shapes, output_file, 'binary', 0.03, 0.5) - # # 转化为glb - # output_glb_file = os.path.join('/tmp', str(code) + '.glb') - # util_path = get_resource_path('sf_dlm', 'static/util') - # cmd = 'python3 %s/stl2gltf.py %s %s -b' % (util_path, output_file, output_glb_file) - # os.system(cmd) - # # 转base64 - # with open(output_glb_file, 'rb') as fileObj: - # image_data = fileObj.read() - # base64_data = base64.b64encode(image_data) - # return base64_data + def transition_glb_file(self, report_path, code): + shapes = read_step_file(report_path) + output_file = os.path.join('/tmp', str(code) + '.stl') + write_stl_file(shapes, output_file, 'binary', 0.03, 0.5) + # 转化为glb + output_glb_file = os.path.join('/tmp', str(code) + '.glb') + util_path = get_resource_path('sf_dlm', 'static/util') + cmd = 'python3 %s/stl2gltf.py %s %s -b' % (util_path, output_file, output_glb_file) + os.system(cmd) + # 转base64 + with open(output_glb_file, 'rb') as fileObj: + image_data = fileObj.read() + base64_data = base64.b64encode(image_data) + return base64_data class ResMrpBomMo(models.Model):