|
| 1 | +// Filename: dnaAnimBuilding.cxx |
| 2 | +// Created by: gjeon (12Nov09) |
| 3 | +// |
| 4 | +//////////////////////////////////////////////////////////////////// |
| 5 | + |
| 6 | +#include "dnaAnimBuilding.h" |
| 7 | +#include "sceneGraphReducer.h" |
| 8 | +#include "modelNode.h" |
| 9 | +#include "config_linmath.h" |
| 10 | + |
| 11 | +//////////////////////////////////////////////////////////////////// |
| 12 | +// Static variables |
| 13 | +//////////////////////////////////////////////////////////////////// |
| 14 | +TypeHandle DNAAnimBuilding::_type_handle; |
| 15 | + |
| 16 | + |
| 17 | +//////////////////////////////////////////////////////////////////// |
| 18 | +// Function: DNAAnimBuilding::Constructor |
| 19 | +// Access: Public |
| 20 | +// Description: |
| 21 | +//////////////////////////////////////////////////////////////////// |
| 22 | +DNAAnimBuilding::DNAAnimBuilding(const std::string &initial_name) : |
| 23 | + DNALandmarkBuilding(initial_name) |
| 24 | +{ |
| 25 | + _anim = ""; |
| 26 | +} |
| 27 | + |
| 28 | +//////////////////////////////////////////////////////////////////// |
| 29 | +// Function: DNAAnimBuilding::Copy Constructor |
| 30 | +// Access: Public |
| 31 | +// Description: |
| 32 | +//////////////////////////////////////////////////////////////////// |
| 33 | +DNAAnimBuilding::DNAAnimBuilding(const DNAAnimBuilding &anim_building) : |
| 34 | + DNALandmarkBuilding(anim_building) |
| 35 | +{ |
| 36 | + _code = anim_building.get_code(); |
| 37 | + _building_type = anim_building.get_building_type(); |
| 38 | + _wall_color = anim_building.get_wall_color(); |
| 39 | + _title = anim_building.get_title(); |
| 40 | + _article = anim_building.get_article(); |
| 41 | + _anim = anim_building.get_anim(); |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +//////////////////////////////////////////////////////////////////// |
| 46 | +// Function: DNAAnimBuilding::traverse |
| 47 | +// Access: Public |
| 48 | +// Description: |
| 49 | +//////////////////////////////////////////////////////////////////// |
| 50 | +NodePath DNAAnimBuilding::traverse(NodePath &parent, DNAStorage *store, int editing) { |
| 51 | + // Try to find this building in the node map |
| 52 | + NodePath building_node_path = (store->find_node(_code)).copy_to(parent); |
| 53 | + |
| 54 | + // Retain the name from the dna |
| 55 | + building_node_path.node()->set_name(get_name()); |
| 56 | + |
| 57 | + // Do not set the color until we can blend |
| 58 | + // Actually we can blend now, but nobody is using color now |
| 59 | + // building_walls_node_path.set_color(_wall_color); |
| 60 | + |
| 61 | + // Set the building position |
| 62 | + building_node_path.set_pos_hpr_scale(_pos, _hpr, _scale); |
| 63 | + building_node_path.set_tag("DNAAnim", _anim); |
| 64 | + |
| 65 | + // Remember the article and title of the building, for later: |
| 66 | + std::string block=store->get_block(get_name()); |
| 67 | + store->store_block_title(block, _title); |
| 68 | + store->store_block_article(block, _article); |
| 69 | + |
| 70 | + // Copy the suit building origin to the parent: |
| 71 | + // our type is animbldg,we must have this |
| 72 | + setup_suit_building_origin(parent, building_node_path); |
| 73 | + |
| 74 | + // Traverse each node in our vector |
| 75 | + pvector<PT(DNAGroup)>::iterator i = _group_vector.begin(); |
| 76 | + for(; i != _group_vector.end(); ++i) { |
| 77 | + PT(DNAGroup) group = *i; |
| 78 | + group->traverse(building_node_path, store, editing); |
| 79 | + } |
| 80 | + |
| 81 | + if (editing) { |
| 82 | + // Remember that this nodepath is associated with this dna group |
| 83 | + store->store_DNAGroup(building_node_path.node(), this); |
| 84 | + } |
| 85 | + else { |
| 86 | + SceneGraphReducer gr; |
| 87 | + // Get rid of the transitions |
| 88 | + gr.apply_attribs(building_node_path.node()); |
| 89 | + gr.flatten(building_node_path.node(), ~0); |
| 90 | + |
| 91 | + // We do not have dna doors too |
| 92 | + // HQs need the door_origins around because they do not have dnaDoors |
| 93 | + //if (get_building_type() != string("hq")) { |
| 94 | + // Get rid of these placement origins since we do not need them anymore |
| 95 | + // NodePath door_origin = building_node_path.find("**/*door_origin"); |
| 96 | + // if (!door_origin.is_empty()) { |
| 97 | + // door_origin.remove_node(); |
| 98 | + // } |
| 99 | + //} |
| 100 | + // We need the sign_origin locator too |
| 101 | + //NodePath sign_origin = building_node_path.find("**/*sign_origin"); |
| 102 | + //if (!sign_origin.is_empty()) { |
| 103 | + // sign_origin.remove_node(); |
| 104 | + //} |
| 105 | + } |
| 106 | + return building_node_path; |
| 107 | +} |
| 108 | + |
| 109 | + |
| 110 | +//////////////////////////////////////////////////////////////////// |
| 111 | +// Function: DNAAnimBuilding::write |
| 112 | +// Access: Public |
| 113 | +// Description: Writes the group and all children to output |
| 114 | +//////////////////////////////////////////////////////////////////// |
| 115 | +void DNAAnimBuilding::write(std::ostream &out, DNAStorage *store, int indent_level) const { |
| 116 | + indent(out, indent_level) << "anim_building "; |
| 117 | + out << '"' << get_name() << '"' << " [\n"; |
| 118 | + |
| 119 | + // Write out all properties |
| 120 | + indent(out, indent_level + 1) << "code [ " << |
| 121 | + '"' << _code << '"' << " ]\n"; |
| 122 | + if (!get_building_type().empty()) { |
| 123 | + indent(out, indent_level + 1) << "building_type [ " << '"' << get_building_type() << '"' << " ]\n"; |
| 124 | + } |
| 125 | + |
| 126 | + // Whoops, the titles were entered as iso8859 and we need to convert them to utf8 |
| 127 | + // We only want to run this when we need to fix an improper encoding |
| 128 | + // Note - you need to change the indent function below too |
| 129 | + // string utf8title = TextNode::reencode_text(_title, TextNode::E_iso8859, TextNode::E_utf8); |
| 130 | + if (!_article.empty()) { |
| 131 | + indent(out, indent_level + 1) << "article [ " << '"' << |
| 132 | + _article << '"' << " ]\n"; |
| 133 | + } |
| 134 | + indent(out, indent_level + 1) << "title [ " << '"' << |
| 135 | + _title << '"' << " ]\n"; |
| 136 | + indent(out, indent_level + 1) << "anim [ " << |
| 137 | + '"' << _anim << '"' << " ]\n"; |
| 138 | + indent(out, indent_level + 1) << "pos [ " << |
| 139 | + _pos[0] << " " << _pos[1] << " " << _pos[2] << " ]\n"; |
| 140 | + if (temp_hpr_fix) { |
| 141 | + indent(out, indent_level + 1) << "nhpr [ " << |
| 142 | + _hpr[0] << " " << _hpr[1] << " " << _hpr[2] << " ]\n"; |
| 143 | + } else { |
| 144 | + indent(out, indent_level + 1) << "hpr [ " << |
| 145 | + _hpr[0] << " " << _hpr[1] << " " << _hpr[2] << " ]\n"; |
| 146 | + } |
| 147 | + |
| 148 | + // Do not write out color if it is white to save work |
| 149 | + if (!_wall_color.almost_equal(LVecBase4f(1.0, 1.0, 1.0, 1.0))) { |
| 150 | + indent(out, indent_level + 1) << "color [ " << |
| 151 | + _wall_color[0] << " " << _wall_color[1] << " " << _wall_color[2] << " " << _wall_color[3] << |
| 152 | + " ]\n"; |
| 153 | + } |
| 154 | + // Write all the children |
| 155 | + pvector<PT(DNAGroup)>::const_iterator i = _group_vector.begin(); |
| 156 | + for(; i != _group_vector.end(); ++i) { |
| 157 | + // Traverse each node in our vector |
| 158 | + PT(DNAGroup) group = *i; |
| 159 | + group->write(out, store, indent_level + 1); |
| 160 | + } |
| 161 | + indent(out, indent_level) << "]\n"; |
| 162 | +} |
| 163 | + |
| 164 | + |
| 165 | +//////////////////////////////////////////////////////////////////// |
| 166 | +// Function: DNAAnimBuilding::make_copy |
| 167 | +// Access: Public |
| 168 | +// Description: Copies all the children into our own vector |
| 169 | +//////////////////////////////////////////////////////////////////// |
| 170 | +DNAGroup* DNAAnimBuilding::make_copy() { |
| 171 | + return new DNAAnimBuilding(*this); |
| 172 | +} |
0 commit comments