GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
triangle_soup_mesh_builder.h
Go to the documentation of this file.
1// Copyright 2016 The Draco Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15#ifndef DRACO_MESH_TRIANGLE_SOUP_MESH_BUILDER_H_
16#define DRACO_MESH_TRIANGLE_SOUP_MESH_BUILDER_H_
17
18#include <utility>
19#include <vector>
20
22
23#ifdef DRACO_TRANSCODER_SUPPORTED
24#include "draco/core/status.h"
25#endif
26#include "draco/mesh/mesh.h"
27
28namespace draco {
29
30// Class for building meshes directly from attribute values that can be
31// specified for each face corner. All attributes are automatically
32// deduplicated.
34 public:
35 // Index type of the inserted element.
37
38 // Starts mesh building for a given number of faces.
39 // TODO(ostava): Currently it's necessary to select the correct number of
40 // faces upfront. This should be generalized, but it will require us to
41 // rewrite our attribute resizing functions.
42 void Start(int num_faces);
43
44#ifdef DRACO_TRANSCODER_SUPPORTED
45 // Sets mesh name.
46 void SetName(const std::string &name);
47#endif // DRACO_TRANSCODER_SUPPORTED
48
49 // Adds an empty attribute to the mesh. Returns the new attribute's id.
50 int AddAttribute(GeometryAttribute::Type attribute_type,
51 int8_t num_components, DataType data_type);
52 int AddAttribute(GeometryAttribute::Type attribute_type,
53 int8_t num_components, DataType data_type, bool normalized);
54
55 // Sets values for a given attribute on all corners of a given face.
56 void SetAttributeValuesForFace(int att_id, FaceIndex face_id,
57 const void *corner_value_0,
58 const void *corner_value_1,
59 const void *corner_value_2);
60
61#ifdef DRACO_TRANSCODER_SUPPORTED
62 // Converts input values of type T into internal representation used by
63 // |att_id|. Each input value needs to have |input_num_components| entries.
64 template <typename T>
65 Status ConvertAndSetAttributeValuesForFace(int att_id, FaceIndex face_id,
66 int input_num_components,
67 const T *corner_value_0,
68 const T *corner_value_1,
69 const T *corner_value_2);
70#endif
71
72 // Sets value for a per-face attribute. If all faces of a given attribute are
73 // set with this method, the attribute will be marked as per-face, otherwise
74 // it will be marked as per-corner attribute.
75 void SetPerFaceAttributeValueForFace(int att_id, FaceIndex face_id,
76 const void *value);
77
78 // Add metadata.
79 void AddMetadata(std::unique_ptr<GeometryMetadata> metadata) {
80 mesh_->AddMetadata(std::move(metadata));
81 }
82
83 // Add metadata for an attribute.
84 void AddAttributeMetadata(int32_t att_id,
85 std::unique_ptr<AttributeMetadata> metadata) {
86 mesh_->AddAttributeMetadata(att_id, std::move(metadata));
87 }
88
89 // Finalizes the mesh or returns nullptr on error.
90 // Once this function is called, the builder becomes invalid and cannot be
91 // used until the method Start() is called again.
92 std::unique_ptr<Mesh> Finalize();
93
94 private:
95 std::vector<int8_t> attribute_element_types_;
96
97 std::unique_ptr<Mesh> mesh_;
98};
99
100#ifdef DRACO_TRANSCODER_SUPPORTED
101template <typename T>
102Status TriangleSoupMeshBuilder::ConvertAndSetAttributeValuesForFace(
103 int att_id, FaceIndex face_id, int input_num_components,
104 const T *corner_value_0, const T *corner_value_1, const T *corner_value_2) {
105 const int start_index = 3 * face_id.value();
106 PointAttribute *const att = mesh_->attribute(att_id);
108 att->ConvertAndSetAttributeValue(AttributeValueIndex(start_index + 0),
109 input_num_components, corner_value_0));
111 att->ConvertAndSetAttributeValue(AttributeValueIndex(start_index + 1),
112 input_num_components, corner_value_1));
114 att->ConvertAndSetAttributeValue(AttributeValueIndex(start_index + 2),
115 input_num_components, corner_value_2));
116 mesh_->SetFace(face_id,
117 {{PointIndex(start_index), PointIndex(start_index + 1),
118 PointIndex(start_index + 2)}});
119 attribute_element_types_[att_id] = MESH_CORNER_ATTRIBUTE;
120 return OkStatus();
121}
122#endif // DRACO_TRANSCODER_SUPPORTED
123
124} // namespace draco
125
126#endif // DRACO_MESH_TRIANGLE_SOUP_MESH_BUILDER_H_
Definition ShaderExpr.hh:118
Type
Definition geometry_attribute.h:46
Definition status.h:25
Definition triangle_soup_mesh_builder.h:33
void AddAttributeMetadata(int32_t att_id, std::unique_ptr< AttributeMetadata > metadata)
Definition triangle_soup_mesh_builder.h:84
void SetPerFaceAttributeValueForFace(int att_id, FaceIndex face_id, const void *value)
Definition triangle_soup_mesh_builder.cc:62
FaceIndex ElementIndex
Definition triangle_soup_mesh_builder.h:36
std::unique_ptr< Mesh > Finalize()
Definition triangle_soup_mesh_builder.cc:78
void AddMetadata(std::unique_ptr< GeometryMetadata > metadata)
Definition triangle_soup_mesh_builder.h:79
int AddAttribute(GeometryAttribute::Type attribute_type, int8_t num_components, DataType data_type)
Definition triangle_soup_mesh_builder.cc:32
void SetAttributeValuesForFace(int att_id, FaceIndex face_id, const void *corner_value_0, const void *corner_value_1, const void *corner_value_2)
Definition triangle_soup_mesh_builder.cc:48
void Start(int num_faces)
Definition triangle_soup_mesh_builder.cc:19
iVBORw0KGgoAAAANSUhEUgAAANcAAAB5CAMAAACdtUQZAAAA51BMVEX</div ></div >< div style="padding: 0px 0px; width: 1324px;">< div style="height: 400px; width: 1324px;"></div >< div itemscope itemtype="https: </div><div itemscope itemtype="https:</div >< div itemscope itemtype="https: </div></div><p><div style="padding:0px 0px;width:1324px;"><div></div><div itemscope itemtype="https:< ul >< li >< b > Application name
8AkrcAgqgAs9wqQ0ey2tkAo8gAuuQfeI4hPUH09fXHy8z4+fng4uNKXF/Lz9BzfoAcgpkQMTUAKjAbOT4Qr9AXhJ8Rl7ktMCwTosA...
Definition meshpage.php:1610
Definition attribute_octahedron_transform.cc:21
@ MESH_CORNER_ATTRIBUTE
Definition mesh.h:44
Status OkStatus()
Definition status.h:66
DataType
Definition draco_types.h:26
FaceIndex FaceIndex
Definition mesh_edgebreaker_encoder_impl.cc:36
#define DRACO_RETURN_IF_ERROR(expression)
Definition status.h:73
Definition Triangle.hh:15
Definition GameApi_pl.cc:29382
Definition GameApi.h:42