Procedural tree 3d module initial setup.

This commit is contained in:
Relintai 2024-09-08 10:19:20 +02:00
parent 673414d913
commit 76ae9d4c09
10 changed files with 1370 additions and 0 deletions

View File

@ -0,0 +1,44 @@
# Exhaustive licensing information for files in the Godot Engine repository
# =========================================================================
#
# This file aims at documenting the copyright and license for every source
# file in the Godot Engine repository, and especially outline the files
# whose license differs from the MIT/Expat license used by Godot Engine.
#
# It is written as a machine-readable format following the debian/copyright
# specification. Globbing patterns (e.g. "Files: *") mean that they affect
# all corresponding files (also recursively in subfolders), apart from those
# with a more explicit copyright statement.
#
# Licenses are given with their debian/copyright short name (or SPDX identifier
# if no standard short name exists) and are all included in plain text at the
# end of this file (in alphabetical order).
#
# Disclaimer for thirdparty libraries:
# ------------------------------------
#
# Licensing details for thirdparty libraries in the 'thirdparty/' directory
# are given in summarized form, i.e. with only the "main" license described
# in the library's license statement. Different licenses of single files or
# code snippets in thirdparty libraries are not documented here.
# For example:
# Files: ./thirdparty/zlib/
# Copyright: 1995-2017, Jean-loup Gailly and Mark Adler
# License: Zlib
# The exact copyright for each file in that library *may* differ, and some
# files or code snippets might be distributed under other compatible licenses
# (e.g. a public domain dedication), but as far as Godot Engine is concerned
# the library is considered as a whole under the Zlib license.
#
# Nota: When linking dynamically against thirdparty libraries instead of
# building them into the Godot binary, you may remove the corresponding
# license details from this file.
-----------------------------------------------------------------------
Files: modules/procedural_tree_3d/proctree/*
Comment: Procedural tree mesh generator
Copyright: c++ port Copyright (c) 2015, Jari Komppa
proctree.js Copyright (c) 2012, Paul Brunt
License: BSD-3-clause

View File

@ -0,0 +1,25 @@
import os
Import('env')
module_env = env.Clone()
sources = [
"register_types.cpp",
"proctree/proctree.cpp",
"procedural_tree_3d.cpp",
]
if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes':
# Shared lib compilation
module_env.Append(CCFLAGS=['-fPIC'])
module_env['LIBS'] = []
shared_lib = module_env.SharedLibrary(target='#bin/procedural_tree_3d', source=sources)
shared_lib_shim = shared_lib[0].name.rsplit('.', 1)[0]
env.Append(LIBS=[shared_lib_shim])
env.Append(LIBPATH=['#bin'])
else:
# Static compilation
module_env.add_source_files(env.modules_sources, sources)

View File

@ -0,0 +1,20 @@
def can_build(env, platform):
return True
#return False
def configure(env):
pass
def get_doc_classes():
return [
"ProceduralTree3D",
]
def get_doc_path():
return "doc_classes"
def get_license_file():
return "COPYRIGHT.txt"

View File

@ -0,0 +1,34 @@
#include "procedural_tree_3d.h"
ProceduralTree3D::ProceduralTree3D() {
}
ProceduralTree3D::~ProceduralTree3D() {
}
void ProceduralTree3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_PROCESS: {
} break;
case NOTIFICATION_ENTER_TREE: {
} break;
case NOTIFICATION_EXIT_TREE: {
} break;
}
}
void ProceduralTree3D::_bind_methods() {
/*
ADD_SIGNAL(MethodInfo("error", PropertyInfo(Variant::DICTIONARY, "error")));
ClassDB::bind_method(D_METHOD("get_client_id"), &ProceduralTree3D::get_client_id);
ClassDB::bind_method(D_METHOD("set_client_id", "val"), &ProceduralTree3D::set_client_id);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "client_id"), "set_client_id", "get_client_id");
ClassDB::bind_method(D_METHOD("get_tls_method"), &ProceduralTree3D::get_tls_method);
ClassDB::bind_method(D_METHOD("set_tls_method", "val"), &ProceduralTree3D::set_tls_method);
ADD_PROPERTY(PropertyInfo(Variant::INT, "tls_method", PROPERTY_HINT_ENUM, "NONE,STARTTLS,SMTPS"), "set_tls_method", "get_tls_method");
ClassDB::bind_method(D_METHOD("send_email", "email"), &ProceduralTree3D::send_email);
*/
}

View File

@ -0,0 +1,19 @@
#ifndef PROCEDURAL_TREE_3D
#define PROCEDURAL_TREE_3D
#include "scene/main/spatial.h"
class ProceduralTree3D : public Spatial {
GDCLASS(ProceduralTree3D, Spatial);
public:
ProceduralTree3D();
~ProceduralTree3D();
protected:
void _notification(int p_what);
static void _bind_methods();
};
#endif

View File

@ -0,0 +1,2 @@
https://github.com/jarikomppa/proctree
45baecbf7fbff295942648a89f801c102799b848

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,169 @@
/*
proctree.js Copyright (c) 2012, Paul Brunt
c++ port Copyright (c) 2015, Jari Komppa
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of proctree.js nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace Proctree
{
typedef struct
{
float x, y, z;
} fvec3;
typedef struct
{
float u, v;
} fvec2;
typedef struct
{
int x, y, z;
} ivec3;
class Properties
{
public:
float mClumpMax;
float mClumpMin;
float mLengthFalloffFactor;
float mLengthFalloffPower;
float mBranchFactor;
float mRadiusFalloffRate;
float mClimbRate;
float mTrunkKink;
float mMaxRadius;
int mTreeSteps;
float mTaperRate;
float mTwistRate;
int mSegments;
int mLevels;
float mSweepAmount;
float mInitialBranchLength;
float mTrunkLength;
float mDropAmount;
float mGrowAmount;
float mVMultiplier;
float mTwigScale;
int mSeed;
int mRseed;
Properties();
Properties(
float aClumpMax,
float aClumpMin,
float aLengthFalloffFactor,
float aLengthFalloffPower,
float aBranchFactor,
float aRadiusFalloffRate,
float aClimbRate,
float aTrunkKink,
float aMaxRadius,
int aTreeSteps,
float aTaperRate,
float aTwistRate,
int aSegments,
int aLevels,
float aSweepAmount,
float aInitialBranchLength,
float aTrunkLength,
float aDropAmount,
float aGrowAmount,
float aVMultiplier,
float aTwigScale,
int aSeed);
float random(float aFixed);
};
class Branch
{
public:
Branch *mChild0;
Branch *mChild1;
Branch *mParent;
fvec3 mHead;
fvec3 mTangent;
float mLength;
int mTrunktype;
int *mRing0, *mRing1, *mRing2;
int *mRootRing;
float mRadius;
int mEnd;
~Branch();
Branch();
Branch(fvec3 aHead, Branch *aParent);
void split(int aLevel, int aSteps, Properties &aProperties, int aL1 = 1, int aL2 = 1);
};
class Tree
{
Branch *mRoot;
void init();
void allocVertBuffers();
void allocFaceBuffers();
void calcVertSizes(Branch *aBranch);
void calcFaceSizes(Branch *aBranch);
void calcNormals();
void doFaces(Branch *aBranch);
void createTwigs(Branch *aBranch);
void createForks(Branch *aBranch, float aRadius);
void fixUVs();
public:
Properties mProperties;
int mVertCount;
int mTwigVertCount;
int mFaceCount;
int mTwigFaceCount;
fvec3 *mVert;
fvec3 *mNormal;
fvec2 *mUV;
fvec3 *mTwigVert;
fvec3 *mTwigNormal;
fvec2 *mTwigUV;
ivec3 *mFace;
ivec3 *mTwigFace;
Tree();
~Tree();
void generate();
};
fvec3 mirrorBranch(fvec3 aVec, fvec3 aNorm, Properties &aProperties);
fvec3 axisAngle(fvec3 aVec, fvec3 aAxis, float aAngle);
fvec3 scaleInDirection(fvec3 aVector, fvec3 aDirection, float aScale);
fvec3 scaleVec(fvec3 a, float b);
fvec3 add(fvec3 a, fvec3 b);
fvec3 sub(fvec3 a, fvec3 b);
float dot(fvec3 a, fvec3 b);
fvec3 cross(fvec3 a, fvec3 b);
fvec3 normalize(fvec3 a);
float length(fvec3 a);
}

View File

@ -0,0 +1,13 @@
#include "register_types.h"
#include "procedural_tree_3d.h"
void register_procedural_tree_3d_types(ModuleRegistrationLevel p_level) {
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
ClassDB::register_class<ProceduralTree3D >();
}
}
void unregister_procedural_tree_3d_types(ModuleRegistrationLevel p_level) {
}

View File

@ -0,0 +1,9 @@
#ifndef PROCEDURAL_TREE_3D_REGISTER_TYPES_H
#define PROCEDURAL_TREE_3D_REGISTER_TYPES_H
#include "modules/register_module_types.h"
void register_procedural_tree_3d_types(ModuleRegistrationLevel p_level);
void unregister_procedural_tree_3d_types(ModuleRegistrationLevel p_level);
#endif