MoveFacesCommand::MoveFacesCommand(Model::MapDocument& document, const wxString& name, VertexHandleManager& handleManager, const Vec3f& delta) :
        SnapshotCommand(Command::MoveVertices, document, name),
        m_handleManager(handleManager),
        m_delta(delta) {
            const Model::VertexToFacesMap& brushFaces = m_handleManager.selectedFaceHandles();
            Model::VertexToFacesMap::const_iterator mapIt, mapEnd;
            for (mapIt = brushFaces.begin(), mapEnd = brushFaces.end(); mapIt != mapEnd; ++mapIt) {
                const Model::FaceList& faces = mapIt->second;
                Model::FaceList::const_iterator faceIt, faceEnd;
                for (faceIt = faces.begin(), faceEnd = faces.end(); faceIt != faceEnd; ++faceIt) {
                    Model::Face* face = *faceIt;
                    Model::Brush* brush = face->brush();
                    const Model::FaceInfo faceInfo = face->faceInfo();

                    Model::BrushFacesMapInsertResult result = m_brushFaces.insert(Model::BrushFacesMapEntry(brush, Model::FaceInfoList()));
                    if (result.second)
                        m_brushes.push_back(brush);
                    result.first->second.push_back(faceInfo);
                    m_facesBefore.push_back(faceInfo);
                }
            }

            assert(!m_brushes.empty());
            assert(m_brushes.size() == m_brushFaces.size());
        }
 FaceSnapshot::FaceSnapshot(const Model::Face& face) {
     m_faceId = face.faceId();
     m_xOffset = face.xOffset();
     m_yOffset = face.yOffset();
     m_xScale = face.xScale();
     m_yScale = face.yScale();
     m_rotation = face.rotation();
     m_texture = face.texture();
     m_textureName = face.textureName();
 }
 void FaceSnapshot::restore(Model::Face& face) {
     face.setXOffset(m_xOffset);
     face.setYOffset(m_yOffset);
     face.setRotation(m_rotation);
     face.setXScale(m_xScale);
     face.setYScale(m_yScale);
     face.setTexture(m_texture);
     if (m_texture == NULL)
         face.setTextureName(m_textureName);
 }
Exemple #4
0
 Vec3f Grid::moveDeltaForBounds(const Model::Face& face, const BBoxf& bounds, const BBoxf& worldBounds, const Rayf& ray, const Vec3f& position) const {
     const Planef dragPlane = Planef::alignedOrthogonalDragPlane(position, face.boundary().normal);
     
     const Vec3f halfSize = bounds.size() * 0.5f;
     float offsetLength = halfSize.dot(dragPlane.normal);
     if (offsetLength < 0.0f)
         offsetLength *= -1.0f;
     const Vec3f offset = dragPlane.normal * offsetLength;
     
     const float dist = dragPlane.intersectWithRay(ray);
     const Vec3f newPos = ray.pointAtDistance(dist);
     Vec3f delta = moveDeltaForPoint(bounds.center(), worldBounds, newPos - (bounds.center() - offset));
     
     Axis::Type a = dragPlane.normal.firstComponent();
     if (dragPlane.normal[a] > 0.0f) delta[a] = position[a] - bounds.min[a];
     else delta[a] = position[a] - bounds.max[a];
     
     return delta;
 }
Exemple #5
0
        size_t MapWriter::writeFace(Model::Face& face, const size_t lineNumber, FILE* stream) {
            const String textureName = Utility::isBlank(face.textureName()) ? Model::Texture::Empty : face.textureName();

            std::fprintf(stream, FaceFormat.c_str(),
                    face.point(0).x(),
                    face.point(0).y(),
                    face.point(0).z(),
                    face.point(1).x(),
                    face.point(1).y(),
                    face.point(1).z(),
                    face.point(2).x(),
                    face.point(2).y(),
                    face.point(2).z(),
                    textureName.c_str(),
                    face.xOffset(),
                    face.yOffset(),
                    face.rotation(),
                    face.xScale(),
                    face.yScale());
            face.setFilePosition(lineNumber);
            return 1;
        }
Exemple #6
0
        void MapWriter::writeFace(const Model::Face& face, std::ostream& stream) {
            const String textureName = Utility::isBlank(face.textureName()) ? Model::Texture::Empty : face.textureName();
            
            stream.precision(FloatPrecision);
            stream <<
            "( " <<
            face.point(0).x() << " " <<
            face.point(0).y() << " " <<
            face.point(0).z() <<
            " ) ( "           <<
            face.point(1).x() << " " <<
            face.point(1).y() << " " <<
            face.point(1).z() <<
            " ) ( "           <<
            face.point(2).x() << " " <<
            face.point(2).y() << " " <<
            face.point(2).z() <<
            " ) ";

            stream.precision(6);
            stream <<
            textureName     << " " <<
            face.xOffset()  << " " <<
            face.yOffset()  << " " <<
            face.rotation() << " " <<
            face.xScale()   << " " <<
            face.yScale()   << "\n";
        }
Exemple #7
0
 Model::Face* MapParser::parseFace(const BBox& worldBounds) {
     Vec3f p1, p2, p3;
     float xOffset, yOffset, rotation, xScale, yScale;
     Token token = m_tokenizer.nextToken();
     if (token.type() == TokenType::Eof)
         return NULL;
     
     expect(TokenType::OParenthesis, token);
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     p1.x = token.toFloat();
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     p1.y = token.toFloat();
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     p1.z = token.toFloat();
     expect(TokenType::CParenthesis, token = m_tokenizer.nextToken());
     expect(TokenType::OParenthesis, token = m_tokenizer.nextToken());
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     p2.x = token.toFloat();
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     p2.y = token.toFloat();
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     p2.z = token.toFloat();
     expect(TokenType::CParenthesis, token = m_tokenizer.nextToken());
     expect(TokenType::OParenthesis, token = m_tokenizer.nextToken());
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     p3.x = token.toFloat();
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     p3.y = token.toFloat();
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     p3.z = token.toFloat();
     expect(TokenType::CParenthesis, token = m_tokenizer.nextToken());
     
     expect(TokenType::String, token = m_tokenizer.nextToken());
     String textureName = token.data();
     
     token = m_tokenizer.nextToken();
     if (m_format == Undefined) {
         expect(TokenType::Integer | TokenType::Decimal | TokenType::OBracket, token);
         m_format = token.type() == TokenType::OBracket ? Valve : Standard;
         if (m_format == Valve)
             m_console.warn("Loading unsupported map Valve 220 map format");
     }
     
     if (m_format == Standard) {
         expect(TokenType::Integer | TokenType::Decimal, token);
         xOffset = token.toFloat();
         expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
         yOffset = token.toFloat();
     } else { // Valve 220 format
         expect(TokenType::OBracket, token);
         expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken()); // X texture axis x
         expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken()); // X texture axis y
         expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken()); // X texture axis z
         expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken()); // X texture axis offset
         xOffset = token.toFloat();
         expect(TokenType::CBracket, token = m_tokenizer.nextToken());
         expect(TokenType::OBracket, token = m_tokenizer.nextToken());
         expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken()); // Y texture axis x
         expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken()); // Y texture axis y
         expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken()); // Y texture axis z
         expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken()); // Y texture axis offset
         yOffset = token.toFloat();
         expect(TokenType::CBracket, token = m_tokenizer.nextToken());
     }
     
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     rotation = token.toFloat();
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     xScale = token.toFloat();
     expect(TokenType::Integer | TokenType::Decimal, token = m_tokenizer.nextToken());
     yScale = token.toFloat();
     
     if (((p3 - p1).crossed(p2 - p1)).null()) {
         m_console.warn("Skipping face with colinear points in line %i", token.line());
         return NULL;
     }
     
     if (textureName == Model::Texture::Empty)
         textureName = "";
     
     Model::Face* face = new Model::Face(worldBounds, p1, p2, p3, textureName);
     face->setXOffset(xOffset);
     face->setYOffset(yOffset);
     face->setRotation(rotation);
     face->setXScale(xScale);
     face->setYScale(yScale);
     face->setFilePosition(token.line());
     return face;
 }