From 0f69ddffb17c08321ae48c3e4eada8d7f80adf10 Mon Sep 17 00:00:00 2001 From: Federico De Felici Date: Fri, 11 May 2018 11:27:27 +0200 Subject: [PATCH] Partial cleaning on cc files --- src/draco/maya/draco_maya_plugin.cc | 56 ++++++++++++++------------- src/draco/maya/draco_maya_plugin.h | 60 ++++------------------------- 2 files changed, 38 insertions(+), 78 deletions(-) diff --git a/src/draco/maya/draco_maya_plugin.cc b/src/draco/maya/draco_maya_plugin.cc index 2a3b0e6..c0d7bf2 100644 --- a/src/draco/maya/draco_maya_plugin.cc +++ b/src/draco/maya/draco_maya_plugin.cc @@ -1,5 +1,3 @@ -// Copyright 2017 The Draco Authors. -// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -51,26 +49,34 @@ namespace draco { } } + static void decode_normals(std::unique_ptr &drc_mesh, Drc2PyMesh* out_mesh) { + const auto normal_att = drc_mesh->GetNamedAttribute(draco::GeometryAttribute::NORMAL); + if (normal_att == nullptr) { + out_mesh->normals = new float[0]; + out_mesh->normals_num = 0; + return; + } + + int num_normals = drc_mesh->num_points(); + out_mesh->normals = new float[num_normals]; + out_mesh->normals_num = num_normals; + //out_mesh->has_normals = true; + + for (int i = 0; i < num_normals; i++) { + draco::PointIndex pi(i); + const draco::AttributeValueIndex val_index = normal_att->mapped_index(pi); + + float out_normal[3]; + bool is_ok = normal_att->ConvertValue(val_index, out_normal); + if (!is_ok) return; + + out_mesh->normals[i * 3 + 0] = out_normal[0]; + out_mesh->normals[i * 3 + 1] = out_normal[1]; + out_mesh->normals[i * 3 + 2] = out_normal[2]; + } - int hello() { - return 20; } - - void fill_int(int *num) { - *num = 1982; - } - - MyStruct* fill_mystruct() { - MyStruct* my = new MyStruct(); - my->num_faces = 500; - return my; - } - - void fill_mystruct2(MyStruct** my) { - *my = new MyStruct(); - (*my)->num_faces = 900; - } - +/* void ReleaseMayaMesh(DracoToMayaMesh **mesh_ptr) { DracoToMayaMesh *mesh = *mesh_ptr; if (!mesh) @@ -101,7 +107,7 @@ namespace draco { delete mesh; *mesh_ptr = nullptr; } - + */ int drc2py_decode(char *data, unsigned int length, Drc2PyMesh **res_mesh) { draco::DecoderBuffer buffer; buffer.Init(data, length); @@ -123,14 +129,12 @@ namespace draco { std::unique_ptr drc_mesh = std::move(statusor).value(); *res_mesh = new Drc2PyMesh(); - //(*res_mesh)->faces_num = drc_mesh->num_faces(); - //(*res_mesh)->vertices_num = drc_mesh->num_points(); decode_faces(drc_mesh, *res_mesh); decode_vertices(drc_mesh, *res_mesh); - + decode_normals(drc_mesh, *res_mesh); return 0; } - +/* int DecodeMeshForMaya(char *data, unsigned int length, DracoToMayaMesh **tmp_mesh) { draco::DecoderBuffer buffer; buffer.Init(data, length); @@ -224,7 +228,7 @@ namespace draco { return in_mesh->num_faces(); } - +*/ } // namespace maya } // namespace draco diff --git a/src/draco/maya/draco_maya_plugin.h b/src/draco/maya/draco_maya_plugin.h index db2d051..dca90ae 100644 --- a/src/draco/maya/draco_maya_plugin.h +++ b/src/draco/maya/draco_maya_plugin.h @@ -1,5 +1,3 @@ -// Copyright 2017 The Draco Authors. -// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -30,68 +28,26 @@ namespace draco { namespace maya { - extern "C" { - struct EXPORT_API DracoToMayaMesh { - DracoToMayaMesh() - : num_faces(0), - indices(nullptr), - num_vertices(0), - position(nullptr), - has_normal(false), - normal(nullptr), - has_texcoord(false), - texcoord(nullptr), - has_color(false), - color(nullptr) {} - - int num_faces; - int *indices; - int num_vertices; - float *position; - bool has_normal; - float *normal; - bool has_texcoord; - float *texcoord; - bool has_color; - float *color; - }; - - void ReleaseMayaMesh(DracoToMayaMesh **mesh_ptr); - - /* To use this function, you do not allocate memory for |tmp_mesh|, just - * define and pass a null pointer. Otherwise there will be memory leak. - */ - int EXPORT_API DecodeMeshForMaya(char *data, unsigned int length, DracoToMayaMesh **tmp_mesh); - + //void ReleaseMayaMesh(DracoToMayaMesh **mesh_ptr); struct EXPORT_API Drc2PyMesh { Drc2PyMesh() : faces_num(0), - vertices_num(0) {} + faces(nullptr), + vertices_num(0), + vertices(nullptr), + normals_num(0), + normals(nullptr) {} int faces_num; int* faces; int vertices_num; float* vertices; + int normals_num; + float* normals; }; EXPORT_API int drc2py_decode(char *data, unsigned int length, Drc2PyMesh **res_mesh); - - - - struct EXPORT_API MyStruct { - MyStruct() - : num_faces(0) {} - //indices(nullptr) {} - int num_faces; - //int *indices; - }; - int EXPORT_API hello(); - void EXPORT_API fill_int(int *num); - - EXPORT_API MyStruct* fill_mystruct(); - EXPORT_API void fill_mystruct2(MyStruct** my); - } // extern "C" } // namespace maya