first working

This commit is contained in:
Harvey Fong 2025-04-17 12:11:16 -06:00
parent 39a1f7b443
commit 98001c955e
4 changed files with 278 additions and 2 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2025 oomer Copyright (c) 2025 Harvey Fong
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,2 +1,26 @@
# poomer-bella-sine # poomer-bella-sine
Prototype command line for creating a simple Bella scene with sine wave Learning prototype cross-platform command line for Bella scene creation with sine wave. Depends on https://github.com/oomer/oom
# Build
```
workdir/
├── build_engine_sdk/
├── oom/
└── poomer-bella-sine/
```
Download SDK for your OS and drag bella_engine_sdk into your workdir. On Windows rename unzipped folder by removing version ie bella_engine_sdk-24.6.0 -> bella_engine_sdk
- [bella_engine_sdk MacOS](https://downloads.bellarender.com/bella_engine_sdk-24.6.0.dmg)
- [bella_engine_sdk Linux](https://downloads.bellarender.com/bella_engine_sdk-24.6.0.tar.gz)
- [bella_engine_sdk Win](https://downloads.bellarender.com/bella_engine_sdk-24.6.0.zip)
```
mkdir workdir
cd workdir
git clone https://github.com/oomer/oom.git
git clone https://github.com/oomer/poomer-bella-sine.git
cd poomer-bella-sine
make all -j4
```

119
makefile Normal file
View File

@ -0,0 +1,119 @@
BELLA_SDK_NAME = bella_engine_sdk
EXECUTABLE_NAME = poomer-bella-sine
PLATFORM = $(shell uname)
BUILD_TYPE ?= release# Default to release build if not specified
# Common paths
BELLA_SDK_PATH = ../bella_engine_sdk
OBJ_DIR = obj/$(PLATFORM)/$(BUILD_TYPE)
BIN_DIR = bin/$(PLATFORM)/$(BUILD_TYPE)
OUTPUT_FILE = $(BIN_DIR)/$(EXECUTABLE_NAME)
# Platform-specific configuration
ifeq ($(PLATFORM), Darwin)
# macOS configuration
SDK_LIB_EXT = dylib
MACOS_SDK_PATH = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
# Compiler settings
CC = clang
CXX = clang++
# Architecture flags
ARCH_FLAGS = -arch arm64 -mmacosx-version-min=11.0 -isysroot $(MACOS_SDK_PATH)
# Linking flags - Use multiple rpath entries to look in executable directory
LINKER_FLAGS = $(ARCH_FLAGS) -framework Cocoa -framework IOKit -fvisibility=hidden -O5 \
-rpath @executable_path \
-rpath .
#-rpath @loader_path \
#-Xlinker -rpath -Xlinker @executable_path
else
# Linux configuration
SDK_LIB_EXT = so
# Compiler settings
CC = gcc
CXX = g++
# Architecture flags
ARCH_FLAGS = -m64 -D_FILE_OFFSET_BITS=64
# Linking flags
LINKER_FLAGS = $(ARCH_FLAGS) -fvisibility=hidden -O3 -Wl,-rpath,'$$ORIGIN' -Wl,-rpath,'$$ORIGIN/lib' -weak_library $(LIBDIR)/libvulkan.dylib
# Platform-specific libraries
#PLIST_LIB = -lplist
endif
# Common include and library paths
INCLUDE_PATHS = -I$(BELLA_SDK_PATH)/src -I$(LIBEFSW_PATH)/include -I$(LIBEFSW_PATH)/src
SDK_LIB_PATH = $(BELLA_SDK_PATH)/lib
SDK_LIB_FILE = lib$(BELLA_SDK_NAME).$(SDK_LIB_EXT)
# Library flags
LIB_PATHS = -L$(SDK_LIB_PATH)
LIBRARIES = -l$(BELLA_SDK_NAME) -lm -ldl
# Build type specific flags
ifeq ($(BUILD_TYPE), debug)
CPP_DEFINES = -D_DEBUG -DDL_USE_SHARED
COMMON_FLAGS = $(ARCH_FLAGS) -fvisibility=hidden -g -O0 $(INCLUDE_PATHS)
else
CPP_DEFINES = -DNDEBUG=1 -DDL_USE_SHARED
COMMON_FLAGS = $(ARCH_FLAGS) -fvisibility=hidden -O3 $(INCLUDE_PATHS)
endif
# Language-specific flags
C_FLAGS = $(COMMON_FLAGS) -std=c17
CXX_FLAGS = $(COMMON_FLAGS) -std=c++17 -Wno-deprecated-declarations
# Objects
OBJECTS = $(EXECUTABLE_NAME).o
OBJECT_FILES = $(patsubst %,$(OBJ_DIR)/%,$(OBJECTS))
# Build rules
$(OBJ_DIR)/$(EXECUTABLE_NAME).o: $(EXECUTABLE_NAME).cpp
@mkdir -p $(@D)
$(CXX) -c -o $@ $< $(CXX_FLAGS) $(CPP_DEFINES)
$(OUTPUT_FILE): $(OBJECT_FILES)
@mkdir -p $(@D)
$(CXX) -o $@ $(OBJECT_FILES) $(LINKER_FLAGS) $(LIB_PATHS) $(LIBRARIES)
@echo "Copying libraries to $(BIN_DIR)..."
@cp $(SDK_LIB_PATH)/$(SDK_LIB_FILE) $(BIN_DIR)/$(SDK_LIB_FILE)
@echo "Build complete: $(OUTPUT_FILE)"
# Add default target
all: $(OUTPUT_FILE)
.PHONY: clean cleanall all
clean:
rm -f $(OBJ_DIR)/$(EXECUTABLE_NAME).o
rm -f $(OUTPUT_FILE)
rm -f $(BIN_DIR)/$(SDK_LIB_FILE)
rm -f $(BIN_DIR)/*.dylib
rmdir $(OBJ_DIR) 2>/dev/null || true
rmdir $(BIN_DIR) 2>/dev/null || true
cleanall:
rm -f obj/*/release/*.o
rm -f obj/*/debug/*.o
rm -f bin/*/release/$(EXECUTABLE_NAME)
rm -f bin/*/debug/$(EXECUTABLE_NAME)
rm -f bin/*/release/$(SDK_LIB_FILE)
rm -f bin/*/debug/$(SDK_LIB_FILE)
rm -f bin/*/release/*.dylib
rm -f bin/*/debug/*.dylib
rmdir obj/*/release 2>/dev/null || true
rmdir obj/*/debug 2>/dev/null || true
rmdir bin/*/release 2>/dev/null || true
rmdir bin/*/debug 2>/dev/null || true
rmdir obj/* 2>/dev/null || true
rmdir bin/* 2>/dev/null || true
rmdir obj 2>/dev/null || true
rmdir bin 2>/dev/null || true

133
poomer-bella-sine.cpp Normal file
View File

@ -0,0 +1,133 @@
#include <iostream>
#include <thread>
#include <chrono>
#include <filesystem>
#include <string>
#include <atomic>
#include <signal.h>
#include <tuple>
#include <cmath>
#include "../bella_engine_sdk/src/bella_sdk/bella_engine.h" // For rendering and scene creation in Bella
#include "../bella_engine_sdk/src/dl_core/dl_main.inl" // Core functionality from the Diffuse Logic engine
#include "../oom/oom_license.h" // common misc code
#include "../oom/oom_bella_long.h" // common misc code
#include "../oom/oom_bella_engine.h" // common misc code
#include "../oom/oom_bella_premade.h" // common misc code
#include "../oom/oom_bella_misc.h" // common misc code
//==============================================================================
// GLOBAL VARIABLES AND FUNCTIONS
//==============================================================================
// Global flag to indicate program termination
std::atomic<bool> STOP(false);
// Signal handler for clean shutdown
void sigend(int) {
std::cout << std::endl << "Bye bye" << std::endl;
STOP = true;
// Give a short time for cleanup
std::this_thread::sleep_for(std::chrono::milliseconds(100));
exit(0); // Force exit after cleanup
}
//==============================================================================
// MAIN FUNCTION
//==============================================================================
int DL_main(dl::Args& args) {
int s_oomBellaLogContext = 0;
dl::subscribeLog(&s_oomBellaLogContext, oom::bella::log);
dl::flushStartupMessages();
args.add("tp", "thirdparty", "", "prints third party licenses");
args.add("li", "licenseinfo", "", "prints license info");
args.add("i", "input", "", "input bella file");
dl::bella_sdk::Engine engine;
engine.scene().loadDefs();
oom::bella::MyEngineObserver engineObserver;
engine.subscribe(&engineObserver);
auto belScene = engine.scene();
// use oom helper to populate the scene with default voxel objects
// this returns a tuple of the world node, the mesh voxel node, the liquid voxel node, and the voxel node
// The latter 3 are unparented, and the world node is parented to the scene root
auto [ belWorld,
belMeshVoxel,
belLiqVoxel,
belVoxel ] = oom::bella::defaultSceneVoxel(belScene);
auto belVoxelMat = belScene.createNode("quickMaterial", "belVoxelMat");
for (int i = 0; i < 500; i+=1) {
auto eachVoxel = belScene.createNode("xform", dl::String::format("eachVoxelXform%04d",i));
//auto eachVoxelMat = belScene.createNode("quickMaterial", dl::String::format("eachVoxelMat%04d",i));
/*eachVoxelMat["color"] = dl::Rgba{
(i%128+128)/255.0f,
0.0f,
0.0f,
1.0f};*/
eachVoxel.parentTo(belWorld);
belVoxel.parentTo(eachVoxel);
dl::Mat4 myXform = dl::Mat4::identity;
dl::Mat4 myTranslate = dl::Mat4::identity;
dl::Mat4 myScale = dl::Mat4::identity;
myTranslate = dl::math::makeTranslation( i*1.0,
0.0,
12.0 + 10.0 * sin(0.1 * i));
/*myScale = dl::math::makeScale<4>( (i%10+10)*0.1,
(i%10+10)*0.1,
(i%10+10)*0.1);*/
myXform = myTranslate * myScale * myXform;
dl::logCustom("\nXform %d", static_cast<int>(i));
dl::logInfo("Mat4: %f %f %f %f", myXform.m00, myXform.m01, myXform.m02, myXform.m03);
dl::logInfo("Mat4: %f %f %f %f", myXform.m10, myXform.m11, myXform.m12, myXform.m13);
dl::logInfo("Mat4: %f %f %f %f", myXform.m20, myXform.m21, myXform.m22, myXform.m23);
dl::logInfo("Mat4: %f %f %f %f", myXform.m30, myXform.m31, myXform.m32, myXform.m33);
eachVoxel["steps"][0]["xform"] = myXform;
eachVoxel["material"] = belVoxelMat;
}
if (args.helpRequested()) {
std::cout << args.help("poomer-efsw © 2025 Harvey Fong","", "1.0") << std::endl;
return 0;
}
if (args.have("--licenseinfo")) {
std::cout << "poomer-efsw © 2025 Harvey Fong" << std::endl;
std::cout << oom::license::printLicense() << std::endl;
return 0;
}
if (args.have("--thirdparty")) {
std::cout << oom::license::printBellaSDK() << "\n====\n" << std::endl;
return 0;
}
if (args.have("--input")) {
auto inputFile = args.value("--input");
if ( dl::fs::exists(inputFile) ) {
engine.loadScene(inputFile);
engine.scene().camera()["resolution"] = dl::Vec2{100, 100};
engine.start();
} else {
dl::logError("File '%s' does not exist", inputFile.buf());
return 1;
}
// Set up signal handler/callback for clean shutdown, global space of C standard library
signal(SIGINT, sigend);
while(engine.rendering()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
dl::logInfo("Writing scene to file");
belScene.write("poomer-bella-sine.bsa");
return 0;
}