Panda3D
Loading...
Searching...
No Matches
cLwoPoints.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file cLwoPoints.cxx
10 * @author drose
11 * @date 2001-04-25
12 */
13
14#include "cLwoPoints.h"
15#include "lwoToEggConverter.h"
16#include "cLwoLayer.h"
17
18#include "pta_stdfloat.h"
19#include "lwoVertexMap.h"
20#include "string_utils.h"
21
22/**
23 * Associates the indicated VertexMap with the points set. This may define
24 * such niceties as UV coordinates or per-vertex color.
25 */
27add_vmap(const LwoVertexMap *lwo_vmap) {
28 IffId map_type = lwo_vmap->_map_type;
29 const std::string &name = lwo_vmap->_name;
30
31 bool inserted;
32 if (map_type == IffId("TXUV")) {
33 inserted =
34 _txuv.insert(VMap::value_type(name, lwo_vmap)).second;
35
36 } else if (map_type == IffId("PICK")) {
37 inserted =
38 _pick.insert(VMap::value_type(name, lwo_vmap)).second;
39
40 } else {
41 return;
42 }
43
44 if (!inserted) {
45 nout << "Multiple vertex maps on the same points of type "
46 << map_type << " named " << name << "\n";
47 }
48}
49
50/**
51 * Returns true if there is a UV of the indicated name associated with the
52 * given vertex, false otherwise. If true, fills in uv with the value.
53 */
55get_uv(const std::string &uv_name, int n, LPoint2 &uv) const {
56 VMap::const_iterator ni = _txuv.find(uv_name);
57 if (ni == _txuv.end()) {
58 return false;
59 }
60
61 const LwoVertexMap *vmap = (*ni).second;
62 if (vmap->_dimension != 2) {
63 nout << "Unexpected dimension of " << vmap->_dimension
64 << " for UV map " << uv_name << "\n";
65 return false;
66 }
67
68 if (!vmap->has_value(n)) {
69 return false;
70 }
71
72 PTA_stdfloat value = vmap->get_value(n);
73
74 uv.set(value[0], value[1]);
75 return true;
76}
77
78/**
79 * Creates the egg structures associated with this Lightwave object.
80 */
82make_egg() {
83 // Generate a vpool name based on the layer index, for lack of anything
84 // better.
85 std::string vpool_name = "layer" + format_string(_layer->get_number());
86 _egg_vpool = new EggVertexPool(vpool_name);
87}
88
89/**
90 * Connects all the egg structures together.
91 */
94 if (!_egg_vpool->empty()) {
95 _layer->_egg_group->add_child(_egg_vpool.p());
96 }
97}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_number() const
Returns the index number associated with this particular layer.
Definition cLwoLayer.I:29
void make_egg()
Creates the egg structures associated with this Lightwave object.
void add_vmap(const LwoVertexMap *lwo_vmap)
Associates the indicated VertexMap with the points set.
bool get_uv(const std::string &uv_name, int n, LPoint2 &uv) const
Returns true if there is a UV of the indicated name associated with the given vertex,...
void connect_egg()
Connects all the egg structures together.
A collection of vertices.
A four-byte chunk ID appearing in an "IFF" file.
Definition iffId.h:26
A mapping of floating-point values per integer index.
PTA_stdfloat get_value(int index) const
Returns the mapping value associated with the given index, or an empty PTA_stdfloat if there is no ma...
bool has_value(int index) const
Returns true if the map has a value associated with the given index, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.