Skip to content

Commit

Permalink
Merge pull request #9 from wangerzi/feat-support-nozip-nodraco
Browse files Browse the repository at this point in the history
feat: support no zip and no draco.
  • Loading branch information
wangerzi authored Jul 28, 2021
2 parents 126c652 + 134eb72 commit a179d92
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 148 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# docker build . -t wj2015/3d-model-convert-to-gltf:v1.4
# docker build . -t wj2015/3d-model-convert-to-gltf:v1.5
# startup docker by: docker run -d -p 8999:8999 wj2015/3d-model-convert-to-gltf:latest
# you can debug by: docker run -it --rm -v `pwd`:/opt/3d-model-convert-to-gltf/ wj2015/3d-model-convert-to-gltf:latest /bin/bash
# you can also execute `conda activate pythonocc` to enter the environment.
Expand Down
3 changes: 2 additions & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
- [ ] [bug] stp 转 gltf 最终文件太大
- [x] 支持以 grpc 形式调用
- [ ] rpc 接口优化,返回具体的错误信息
- [ ] rpc server 日志问题
- [ ] rpc 需支持不适用 draco
- [ ] [bug]rpc server 日志问题


## 项目用户
Expand Down
2 changes: 1 addition & 1 deletion convert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ outPath=$(
pwd
)
outFile=$outPath/`basename $3`
docker run -v $inputPath:$inputPath -v $outPath:$outPath wj2015/3d-model-convert-to-gltf:v1.4 /bin/bash -c "cd $inputPath && conda run -n pythonocc python /opt/3d-model-convert-to-gltf/server/convert.py $1 $inputFile $outFile"
docker run -v $inputPath:$inputPath -v $outPath:$outPath wj2015/3d-model-convert-to-gltf:v1.5 /bin/bash -c "cd $inputPath && conda run -n pythonocc python /opt/3d-model-convert-to-gltf/server/convert.py $1 $inputFile $outFile"
10 changes: 0 additions & 10 deletions server/db/redis.py

This file was deleted.

26 changes: 20 additions & 6 deletions server/examples/python/converter_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions server/examples/python/rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def get_stub(target):
return stub


def convert_file_and_save(target, t, source, dist, is_bin=False):
def convert_file_and_save(target, t, source, dist, is_bin=False, need_draco=True, no_zip=False):
stub = get_stub(target)
with open(source, 'rb') as f:
response = stub.convertToGltf(
converter_pb2.convertReq(type=t, isBin=is_bin, file=f.read())
converter_pb2.convertReq(type=t, isBin=is_bin, file=f.read(), needDraco=need_draco, noZip=no_zip)
)
if response.file == b'':
return False
Expand All @@ -36,7 +36,7 @@ def convert_file_and_save(target, t, source, dist, is_bin=False):
def run():
try:
start_time = time.time()
if convert_file_and_save("127.0.0.1:8999", 'stl', '../../../assets/test.stl', 'test.glb.zip', True):
if convert_file_and_save("127.0.0.1:8999", 'stl', '../../../assets/test.stl', 'test.glb.zip', False, True, True):
end_time = time.time()
print("convert success", str(end_time - start_time), 's')
else:
Expand Down
5 changes: 0 additions & 5 deletions server/exception/ValidateException.py

This file was deleted.

26 changes: 20 additions & 6 deletions server/rpc/converter_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/rpc/protos/converter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ message convertReq {
string type = 1;
bool isBin = 2;
bytes file = 3;
bool needDraco = 4;
bool noZip = 5;
}
message convertResp {
bytes file = 1;
Expand Down
30 changes: 24 additions & 6 deletions server/rpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from rpc import converter_pb2_grpc
from service import upload
from service import Convert
from exception.ConvertException import ConvertException


class ConverterService(converter_pb2_grpc.ConverterServicer):
Expand All @@ -20,7 +21,8 @@ def convertToGltf(self, request, context):
up_service = upload.Upload()

response = converter_pb2.convertResp(file=None)
print("receive request", request.type, request.isBin, ", size:", len(request.file) / 1024 / 1024, 'Mb')
print("receive request", request.type, request.isBin, ", need_draco: ", request.needDraco, ", no_zip: ",
request.noZip, " size:", len(request.file) / 1024 / 1024, 'Mb')
try:
# save and unzip
up_service.save(request.file).unzip_save_file_with_clear_source()
Expand All @@ -34,26 +36,42 @@ def convertToGltf(self, request, context):
if find_path and len(find_path) > 0:
# find first file
source_model_path = find_path[0]
else:
raise ConvertException("can't found match source model")

else:
source_model_path = up_service.get_save_path()

# convert and clear source_model, then zip and response
result = model.handler(source_model_path, request.isBin)
result = model.handler(source_model_path, request.isBin, request.needDraco)

# special logic, if convert to glb, only zip glb file
zip_source_ext = None
if request.isBin:
zip_source_ext = ['glb']
zip_path = up_service.clear_file(source_model_path).zip_source_dir(zip_source_ext).get_source_zip_path()

if request.isBin and request.noZip:
up_service.clear_file(source_model_path)
find_path = up_service.scan_ext_file(['glb'], True)
if find_path and len(find_path) > 0:
result_file_path = find_path[0]
else:
raise ConvertException("can't found glb result file")
else:
result_file_path = up_service.clear_file(source_model_path).zip_source_dir(
zip_source_ext).get_source_zip_path()

print("receive and handle ", request.type, up_service.get_save_path(), up_service.is_zip(),
'found source file', source_model_path, 'convert result', result, 'zip path', zip_path, "zip size:",
os.path.getsize(zip_path) / 1024 / 1024, "Mb")
'found source file', source_model_path, 'convert result', result, 'result path', result_file_path,
"zip size:",
((os.path.getsize(result_file_path) / 1024 / 1024) if os.path.exists(result_file_path) else 'None'),
"Mb")

with open(zip_path, 'rb') as f:
with open(result_file_path, 'rb') as f:
response = converter_pb2.convertResp(file=f.read())
except Exception as err:
print("convert error:", err)
raise err
finally:
up_service.clear_save_dir()
return response
Expand Down
Loading

0 comments on commit a179d92

Please sign in to comment.