Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

5.3 KB
Raw Blame
// SculptForge - open source digital sculpting
// SPDX-License-Identifier: GPL-3.0-or-later
//
// A studio profile (studio.json, docs/studios.md "Your studio build"): what a custom studio build bakes in and how
// it reaches the network. Release tooling (tools/studio/check_profile.py, -DSCULPTFORGE_STUDIO_PROFILE=...) checks
// the profile, compiles it into the binaries and installs its folder (packs, preferences, logo) next to the
// assets. A studio build is in studio mode whatever happens to the files: offline, with only its own update
// channel or mirror allowed (core/NetworkPolicy.h).
//
// Where the profile comes from, first found wins:
//   1. --studio FILE (app and CLI) or SF_STUDIO_PROFILE=FILE (IT testing a profile on a public build);
//   2. the profile compiled into a studio build;
//   3. studio/studio.json next to the installed assets (share/sculptforge/studio, Resources/studio);
// and --offline (or SF_OFFLINE=1) turns studio mode on with nothing allowed when no profile is found.
//
// {
//   "format": "sculptforge-studio", "version": 1,
//   "id": "acme", "name": "Acme Animation",
//   "offline": true,                          // always true in a studio build
//   "updates": {"feed": "https://sw.acme.internal/sculptforge/latest.json", "mirror": "/mnt/sw/sculptforge/latest.json"},
//   "allow": ["https://comfy.acme.internal/"],  // more URL prefixes, if the studio wants them
//   "localNetwork": false,                    // Unreal link and phone capture on the studio LAN
//   "ai": false,                              // AI features (they may reach only allowed URLs)
//   "packs": ["packs/acme.sfpack"],           // brushes, alphas, Lit Spheres, keymaps, macros (core/Pack.h)
//   "brushPaths": ["/studio/brushes"],        // read-only brush shares (as SCULPTFORGE_BRUSH_PATH)
//   "preferences": "ui.json",                 // the first-start interface settings (layout, keys, scale)
//   "branding": {"logo": "logo.png", "title": "Acme"}
// }
// Paths are relative to the profile's folder. The profile is data: nothing in it runs.
#pragma once

#include "core/NetworkPolicy.h"

#include <string>
#include <vector>

namespace sf {

constexpr const char* kStudioProfileFormat = "sculptforge-studio";
constexpr int kStudioProfileVersion = 1;

struct StudioProfile {
    std::string id, name;
    std::string dir;           // the folder relative paths resolve against ("" for a compiled-in profile: the installed one)
    std::string source;        // where it came from, for messages ("--studio /x/studio.json", "built in", ...)
    bool offline = true;
    bool ai = false;
    bool localNetwork = false;
    std::string updateFeed, updateMirror; // a URL (http/https) or a local file
    std::vector<std::string> allow;
    std::vector<std::string> packs, brushPaths; // resolved (absolute when dir is set)
    std::string preferences;
    std::string logo, title;
};

// Reads and checks a profile: format, id (lower-case letters, digits, '-', '_'), name, URLs (http/https only, no user
// info), and no path that climbs out of DIR. Unknown keys are errors, so a typo never quietly drops a setting.
bool parseStudioProfile(const std::string& text, const std::string& dir, StudioProfile& out, std::string& error);
bool loadStudioProfile(const std::string& path, StudioProfile& out, std::string& error);

// What the profile allows: offline, the update channel and mirror (when they are URLs) plus its allow list.
net::NetworkPolicy studioNetworkPolicy(const StudioProfile& p);

// POLICY with a studio's managed policy applied (core/ManagedPolicy.h): network features off is studio mode, with
// what the managed policy names reachable (its allow list, AI endpoints, the identity provider, its update feed).
namespace policy { struct Policy; }
net::NetworkPolicy withManagedPolicy(net::NetworkPolicy policy, const policy::Policy& managed);

// The profile compiled into this build ("" in public builds; core/StudioBuild.cpp, generated by CMake).
const char* builtInStudioProfile();
bool isStudioBuild();

struct StudioStart {
    bool active = false;       // studio mode is on
    StudioProfile profile;     // when one was found
    std::vector<std::string> messages; // what to log (a broken profile, a pack that didn't install)
};

// Finds the profile (see the order above), applies the network policy and the brush shares, and returns it. A studio
// build whose profile is missing or broken still starts offline, with nothing allowed (it fails closed).
// EXE_DIR is where the binary is (for the installed studio folder); OVERRIDE_PATH is --studio's file.
StudioStart startStudioMode(const std::string& exeDir, const std::string& overridePath, bool forceOffline);
// Installs the profile's packs that aren't installed at their version yet (core/Pack.h: the same checks as any pack).
void installStudioPacks(const StudioProfile& p, std::vector<std::string>& messages);
// The studio folder next to the installed assets, or "".
std::string findInstalledStudioDir(const std::string& exeDir);
// The process's studio state (what startStudioMode found).
const StudioStart& studioMode();

// The update feed to read: the profile's channel in studio mode ("" = no automatic check, nothing to ask), otherwise
// SF_UPDATE_FEED or the public feed. FALLBACK gets the mirror to try when the first answer isn't 200.
std::string updateFeedSource(const StudioStart& s, const char* envFeed, std::string& fallback);

} // namespace sf