-void Brush_ConstructSphere(Brush& brush, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection)
-{
- if(sides < c_brushSphere_minSides)
- {
- globalErrorStream() << c_brushSphere_name << ": sides " << Unsigned(sides) << ": too few sides, minimum is " << Unsigned(c_brushSphere_minSides) << "\n";
- return;
- }
- if(sides > c_brushSphere_maxSides)
- {
- globalErrorStream() << c_brushSphere_name << ": sides " << Unsigned(sides) << ": too many sides, maximum is " << Unsigned(c_brushSphere_maxSides) << "\n";
- return;
- }
-
- brush.clear();
- brush.reserve(sides*sides);
-
- float radius = max_extent(bounds.extents);
- const Vector3& mid = bounds.origin;
- Vector3 planepts[3];
-
- double dt = 2 * c_pi / sides;
- double dp = c_pi / sides;
- for(std::size_t i=0; i < sides; i++)
- {
- for(std::size_t j=0;j < sides-1; j++)
- {
- double t = i * dt;
- double p = float(j * dp - c_pi / 2);
-
- planepts[0] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t, p), radius));
- planepts[1] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t, p + dp), radius));
- planepts[2] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t + dt, p + dp), radius));
-
- brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection);
- }
- }
-
- {
- double p = (sides - 1) * dp - c_pi / 2;
- for(std::size_t i = 0; i < sides; i++)
- {
- double t = i * dt;
-
- planepts[0] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t, p), radius));
- planepts[1] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t + dt, p + dp), radius));
- planepts[2] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t + dt, p), radius));
-
- brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection);
- }
- }
-}
-
-int GetViewAxis()
-{
- switch(GlobalXYWnd_getCurrentViewType())
- {
- case XY:
- return 2;
- case XZ:
- return 1;
- case YZ:
- return 0;
- }
- return 2;
-}
-
-void Brush_ConstructPrefab(Brush& brush, EBrushPrefab type, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection)
-{
- switch(type)
- {
- case eBrushCuboid:
- {
- UndoableCommand undo("brushCuboid");
-
- Brush_ConstructCuboid(brush, bounds, shader, projection);
- }
- break;
- case eBrushPrism:
- {
- int axis = GetViewAxis();
- StringOutputStream command;
- command << c_brushPrism_name << " -sides " << Unsigned(sides) << " -axis " << axis;
- UndoableCommand undo(command.c_str());
-
- Brush_ConstructPrism(brush, bounds, sides, axis, shader, projection);
- }
- break;
- case eBrushCone:
- {
- StringOutputStream command;
- command << c_brushCone_name << " -sides " << Unsigned(sides);
- UndoableCommand undo(command.c_str());
-
- Brush_ConstructCone(brush, bounds, sides, shader, projection);
- }
- break;
- case eBrushSphere:
- {
- StringOutputStream command;
- command << c_brushSphere_name << " -sides " << Unsigned(sides);
- UndoableCommand undo(command.c_str());
-
- Brush_ConstructSphere(brush, bounds, sides, shader, projection);
- }
- break;
- }
-}
-
-
-void ConstructRegionBrushes(scene::Node* brushes[6], const Vector3& region_mins, const Vector3& region_maxs)
-{
- {
- // set mins
- Vector3 mins(region_mins[0]-32, region_mins[1]-32, region_mins[2]-32);
-
- // vary maxs
- for(std::size_t i=0; i<3; i++)
- {
- Vector3 maxs(region_maxs[0]+32, region_maxs[1]+32, region_maxs[2]+32);
- maxs[i] = region_mins[i];
- Brush_ConstructCuboid(*Node_getBrush(*brushes[i]), aabb_for_minmax(mins, maxs), texdef_name_default(), TextureProjection());
- }
- }
-
- {
- // set maxs
- Vector3 maxs(region_maxs[0]+32, region_maxs[1]+32, region_maxs[2]+32);
-
- // vary mins
- for(std::size_t i=0; i<3; i++)
- {
- Vector3 mins(region_mins[0]-32, region_mins[1]-32, region_mins[2]-32);
- mins[i] = region_maxs[i];
- Brush_ConstructCuboid(*Node_getBrush(*brushes[i+3]), aabb_for_minmax(mins, maxs), texdef_name_default(), TextureProjection());
- }
- }
-}
-
-
-class FaceSetTexdef
-{
- const TextureProjection& m_projection;
-public:
- FaceSetTexdef(const TextureProjection& projection) : m_projection(projection)
- {
- }
- void operator()(Face& face) const
- {
- face.SetTexdef(m_projection);
- }
-};
-
-void Scene_BrushSetTexdef_Selected(scene::Graph& graph, const TextureProjection& projection)
-{
- Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetTexdef(projection));
- SceneChangeNotify();
+void Brush_ConstructSphere( Brush& brush, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection ){
+ if ( sides < c_brushSphere_minSides ) {
+ globalErrorStream() << c_brushSphere_name << ": sides " << Unsigned( sides ) << ": too few sides, minimum is " << Unsigned( c_brushSphere_minSides ) << "\n";
+ return;
+ }
+ if ( sides > c_brushSphere_maxSides ) {
+ globalErrorStream() << c_brushSphere_name << ": sides " << Unsigned( sides ) << ": too many sides, maximum is " << Unsigned( c_brushSphere_maxSides ) << "\n";
+ return;
+ }
+
+ brush.clear();
+ brush.reserve( sides * sides );
+
+ float radius = max_extent( bounds.extents );
+ const Vector3& mid = bounds.origin;
+ Vector3 planepts[3];
+
+ double dt = 2 * c_pi / sides;
+ double dp = c_pi / sides;
+ for ( std::size_t i = 0; i < sides; i++ )
+ {
+ for ( std::size_t j = 0; j < sides - 1; j++ )
+ {
+ double t = i * dt;
+ double p = float(j * dp - c_pi / 2);
+
+ planepts[0] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t, p ), radius ) );
+ planepts[1] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t, p + dp ), radius ) );
+ planepts[2] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t + dt, p + dp ), radius ) );
+
+ brush.addPlane( planepts[0], planepts[1], planepts[2], shader, projection );
+ }
+ }
+
+ {
+ double p = ( sides - 1 ) * dp - c_pi / 2;
+ for ( std::size_t i = 0; i < sides; i++ )
+ {
+ double t = i * dt;
+
+ planepts[0] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t, p ), radius ) );
+ planepts[1] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t + dt, p + dp ), radius ) );
+ planepts[2] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t + dt, p ), radius ) );
+
+ brush.addPlane( planepts[0], planepts[1], planepts[2], shader, projection );
+ }
+ }