Revision: 532
http://python-ogre.svn.sourceforge.net/python-ogre/?rev=532&view=rev
Author: andy_miller
Date: 2008-01-07 18:45:30 -0800 (Mon, 07 Jan 2008)
Log Message:
-----------
And the library source for cadunetree
Added Paths:
-----------
trunk/python-ogre/ThirdParty/cadunetree/
trunk/python-ogre/ThirdParty/cadunetree/CTParameters.cpp
trunk/python-ogre/ThirdParty/cadunetree/CTParameters.h
trunk/python-ogre/ThirdParty/cadunetree/CTPrerequisites.h
trunk/python-ogre/ThirdParty/cadunetree/CTSection.cpp
trunk/python-ogre/ThirdParty/cadunetree/CTSection.h
trunk/python-ogre/ThirdParty/cadunetree/CTSerializer.cpp
trunk/python-ogre/ThirdParty/cadunetree/CTSerializer.h
trunk/python-ogre/ThirdParty/cadunetree/CTStem.cpp
trunk/python-ogre/ThirdParty/cadunetree/CTStem.h
trunk/python-ogre/ThirdParty/cadunetree/CaduneTree.h
Added: trunk/python-ogre/ThirdParty/cadunetree/CTParameters.cpp
===================================================================
--- trunk/python-ogre/ThirdParty/cadunetree/CTParameters.cpp (rev 0)
+++ trunk/python-ogre/ThirdParty/cadunetree/CTParameters.cpp 2008-01-08 02:45:30 UTC (rev 532)
@@ -0,0 +1,398 @@
+/*
+This file is a part of the CaduneTree project,
+library used to generate and render trees with OGRE.
+
+License:
+Copyright (c) 2007 Wojciech Cierpucha
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "CTParameters.h"
+
+namespace CaduneTree {
+
+ const unsigned int Parameters::mMaxLevels = 4; // 4 is a reasonable number, official in v0.6
+
+ Parameters::Parameters() : mTaper( 1.0f ) {
+ // First allocate memory for arrays, + 1 because there is an additional root level
+ mNumVertices = new unsigned char[ mMaxLevels + 1 ];
+ mNumBranches = new unsigned char[ mMaxLevels + 1];
+ mDownAngle = new float[ mMaxLevels + 1];
+ mDownAngleV = new float[ mMaxLevels + 1];
+ mRotate = new float[ mMaxLevels + 1];
+ mRotateV = new float[ mMaxLevels + 1];
+ mLength = new float[ mMaxLevels + 1];
+ mLengthV = new float[ mMaxLevels + 1];
+ mCurve = new float[ mMaxLevels + 1];
+ mCurveBack = new float[ mMaxLevels + 1];
+ mCurveV = new float[ mMaxLevels + 1];
+ mCurveRes = new unsigned char[ mMaxLevels + 1];
+
+ // Always set params to default
+ setDefault();
+ }
+
+ Parameters::Parameters( const Parameters& params ) : mTaper( 1.0f ) {
+ // First allocate memory for arrays
+ mNumVertices = new unsigned char[ mMaxLevels + 1];
+ mNumBranches = new unsigned char[ mMaxLevels + 1];
+ mDownAngle = new float[ mMaxLevels + 1];
+ mDownAngleV = new float[ mMaxLevels + 1];
+ mRotate = new float[ mMaxLevels + 1];
+ mRotateV = new float[ mMaxLevels + 1];
+ mLength = new float[ mMaxLevels + 1];
+ mLengthV = new float[ mMaxLevels + 1];
+ mCurve = new float[ mMaxLevels + 1];
+ mCurveBack = new float[ mMaxLevels + 1];
+ mCurveV = new float[ mMaxLevels + 1];
+ mCurveRes = new unsigned char[ mMaxLevels + 1];
+
+ // General
+ mShape = params.mShape;
+ mBaseSize = params.mBaseSize;
+ mScale = params.mScale;
+ mScaleV = params.mScaleV;
+ mNumLevels = params.mNumLevels;
+ mRatio = params.mRatio;
+ mRatioPower = params.mRatioPower;
+ mNumLobes = params.mNumLobes;
+ mLobeDepth = params.mLobeDepth;
+ mFlare = params.mFlare;
+ mScale0 = params.mScale0;
+ mScale0V = params.mScale0V;
+ mBarkMaterial = params.mBarkMaterial;
+ // Leaves
+ mNumLeaves = params.mNumLeaves;
+ mLeafScale = params.mLeafScale;
+ mLeafScaleX = params.mLeafScaleX;
+ mLeafQuality = params.mLeafQuality;
+ mLeafLayoutExp = params.mLeafLayoutExp;
+ mLeafMaterial = params.mLeafMaterial;
+ // Fronds
+ mNumFronds = params.mNumFronds;
+ mFrondScale = params.mFrondScale;
+ mFrondScaleX = params.mFrondScaleX;
+ mFrondQuality = params.mFrondQuality;
+ mFrondMaterial = params.mFrondMaterial;
+ //
+ mAttractionUp = params.mAttractionUp;
+ // Leveled info
+ for( unsigned int i = 0; i < mMaxLevels + 1; ++i ) {
+ mNumVertices[ i ] = params.mNumVertices[ i ];
+ mNumBranches[ i ] = params.mNumBranches[ i ];
+ mDownAngle[ i ] = params.mDownAngle[ i ];
+ mDownAngleV[ i ] = params.mDownAngleV[ i ];
+ mRotate[ i ] = params.mRotate[ i ];
+ mRotateV[ i ] = params.mRotateV[ i ];
+ mLength[ i ] = params.mLength[ i ];
+ mLengthV[ i ] = params.mLengthV[ i ];
+ mCurve[ i ] = params.mCurve[ i ];
+ mCurveBack[ i ] = params.mCurveBack[ i ];
+ mCurveV[ i ] = params.mCurveV[ i ];
+ mCurveRes[ i ] = params.mCurveRes[ i ];
+ }
+ }
+
+ Parameters::~Parameters() {
+ delete [] mNumVertices;
+ delete [] mNumBranches;
+ delete [] mDownAngle;
+ delete [] mDownAngleV;
+ delete [] mRotate;
+ delete [] mRotateV;
+ delete [] mLength;
+ delete [] mLengthV;
+ delete [] mCurve;
+ delete [] mCurveBack;
+ delete [] mCurveV;
+ delete [] mCurveRes;
+ }
+
+ void Parameters::setDefault() {
+ // General
+ mShape = TEND_FLAME;
+ mBaseSize = 0.3f;
+ mScale = 13.0f;
+ mScaleV = 3.0f;
+ mNumLevels = 2;
+ mRatio = 0.03f;
+ mRatioPower = 1.0f;
+ mNumLobes = 5;
+ mLobeDepth = 0.2f;
+ mFlare = 1.4f;
+ mScale0 = 1.0f;
+ mScale0V = 0.0f;
+ mBarkMaterial = "BarkNoLighting";
+ // Leaves
+ mNumLeaves = 4;
+ mLeafScale = 1.4f;
+ mLeafScaleX = 1.0f;
+ mLeafQuality = 1.0f;
+ mLeafLayoutExp = 4.0f;
+ mLeafMaterial = "Leaves";
+ // Fronds
+ mNumFronds = 4;
+ mFrondScale = 1.0f;
+ mFrondScaleX = 1.0f;
+ mFrondQuality = 1.0f;
+ mFrondMaterial = "Frond";
+ //
+ mAttractionUp = 0.5f;
+ // Trunk - level 0, null not used params
+ mNumVertices[ 0 ] = 8;
+ mNumBranches[ 0 ] = 0;
+ mDownAngle[ 0 ] = 0.0f;
+ mDownAngleV[ 0 ] = 0.0f;
+ mRotate[ 0 ] = 0.0f;
+ mRotateV[ 0 ] = 0.0f;
+ mLength[ 0 ] = 1.0f;
+ mLengthV[ 0 ] = 0.0f;
+ mCurve[ 0 ] = 20.0f;
+ mCurveBack[ 0 ] = -15.0f;
+ mCurveV[ 0 ] = 20.0f;
+ mCurveRes[ 0 ] = 8;
+ // Level 1
+ mNumVertices[ 1 ] = 4;
+ mNumBranches[ 1 ] = 20;
+ mDownAngle[ 1 ] = 80.0f;
+ mDownAngleV[ 1 ] = 5.0f;
+ mRotate[ 1 ] = 140.0f;
+ mRotateV[ 1 ] = 0.0f;
+ mLength[ 1 ] = 0.4f;
+ mLengthV[ 1 ] = 0.0f;
+ mCurve[ 1 ] = -30.0f;
+ mCurveBack[ 1 ] = 0.0f;
+ mCurveV[ 1 ] = 10.0f;
+ mCurveRes[ 1 ] = 4;
+ // Roots
+ mNumVertices[ mMaxLevels ] = 6;
+ mNumBranches[ mMaxLevels ] = 6;
+ mDownAngle[ mMaxLevels ] = 95.0f;
+ mDownAngleV[ mMaxLevels ] = 5.0f;
+ mRotate[ mMaxLevels ] = 140.0f;
+ mRotateV[ mMaxLevels ] = 0.0f;
+ mLength[ mMaxLevels ] = 0.4f;
+ mLengthV[ mMaxLevels ] = 0.0f;
+ mCurve[ mMaxLevels ] = 20.0f;
+ mCurveBack[ mMaxLevels ] = -5.0f;
+ mCurveV[ mMaxLevels ] = 5.0f;
+ mCurveRes[ mMaxLevels ] = 4;
+
+ // Null remainning data
+ for( unsigned int i = 2; i < mMaxLevels; ++i ) {
+ mNumVertices[ i ] = 0;
+ mNumBranches[ i ] = 0;
+ mDownAngle[ i ] = 0.0f;
+ mDownAngleV[ i ] = 0.0f;
+ mRotate[ i ] = 0.0f;
+ mRotateV[ i ] = 0.0f;
+ mLength[ i ] = 0.0f;
+ mLengthV[ i ] = 0.0f;
+ mCurve[ i ] = 0.0f;
+ mCurveBack[ i ] = 0.0f;
+ mCurveV[ i ] = 0.0f;
+ mCurveRes[ i ] = 0;
+ }
+
+ }
+
+ Parameters* Parameters::createCopy() const {
+ Parameters *params = new Parameters;
+
+ // General
+ params->mShape = mShape;
+ params->mBaseSize = mBaseSize;
+ params->mScale = mScale;
+ params->mScaleV = mScaleV;
+ params->mNumLevels = mNumLevels;
+ params->mRatio = mRatio;
+ params->mRatioPower = mRatioPower;
+ params->mNumLobes = mNumLobes;
+ params->mLobeDepth = mLobeDepth;
+ params->mFlare = mFlare;
+ params->mScale0 = mScale0;
+ params->mScale0V = mScale0V;
+ params->mBarkMaterial = mBarkMaterial;
+ // Leaves
+ params->mNumLeaves = mNumLeaves;
+ params->mLeafScale = mLeafScale;
+ params->mLeafScaleX = mLeafScaleX;
+ params->mLeafQuality = mLeafQuality;
+ params->mLeafLayoutExp = mLeafLayoutExp;
+ params->mLeafMaterial = mLeafMaterial;
+ // Fronds
+ params->mNumFronds = mNumFronds;
+ params->mFrondScale = mFrondScale;
+ params->mFrondScaleX = mFrondScaleX;
+ params->mFrondQuality = mFrondQuality;
+ params->mFrondMaterial = mFrondMaterial;
+ //
+ params->mAttractionUp = mAttractionUp;
+ // Leveled info
+ for( unsigned int i = 0; i < mMaxLevels + 1; ++i ) {
+ params->mNumVertices[ i ] = mNumVertices[ i ];
+ params->mNumBranches[ i ] = mNumBranches[ i ];
+ params->mDownAngle[ i ] = mDownAngle[ i ];
+ params->mDownAngleV[ i ] = mDownAngleV[ i ];
+ params->mRotate[ i ] = mRotate[ i ];
+ params->mRotateV[ i ] = mRotateV[ i ];
+ params->mLength[ i ] = mLength[ i ];
+ params->mLengthV[ i ] = mLengthV[ i ];
+ params->mCurve[ i ] = mCurve[ i ];
+ params->mCurveBack[ i ] = mCurveBack[ i ];
+ params->mCurveV[ i ] = mCurveV[ i ];
+ params->mCurveRes[ i ] = mCurveRes[ i ];
+ }
+
+ return params;
+ }
+
+ unsigned char Parameters::getCurveRes( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mCurveRes[ level ];
+ return 0;
+ }
+
+ float Parameters::getCurveV( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mCurveV[ level ];
+ return 0.0f;
+ }
+
+ float Parameters::getCurveBack( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mCurveBack[ level ];
+ return 0.0f;
+ }
+
+ float Parameters::getCurve( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mCurve[ level ];
+ return 0.0f;
+ }
+
+ float Parameters::getLengthV( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mLengthV[ level ];
+ return 0.0f;
+ }
+
+ float Parameters::getLength( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mLength[ level ];
+ return 0.0f;
+ }
+
+ float Parameters::getRotateV( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mRotateV[ level ];
+ return 0.0f;
+ }
+
+ float Parameters::getRotate( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mRotate[ level ];
+ return 0.0f;
+ }
+
+ float Parameters::getDownAngleV( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mDownAngleV[ level ];
+ return 0.0f;
+ }
+
+ float Parameters::getDownAngle( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mDownAngle[ level ];
+ return 0.0f;
+ }
+
+ unsigned char Parameters::getNumBranches( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mNumBranches[ level ];
+ return 0;
+ }
+
+ unsigned char Parameters::getNumVertices( unsigned int level ) {
+ if( level <= mMaxLevels )
+ return mNumVertices[ level ];
+ return 0;
+ }
+
+ void Parameters::setCurveRes( unsigned int level, unsigned char curveRes ) {
+ if( level <= mMaxLevels )
+ mCurveRes[ level ] = curveRes;
+ }
+
+ void Parameters::setCurveV( unsigned int level, float curveV ) {
+ if( level <= mMaxLevels )
+ mCurveV[ level ] = curveV;
+ }
+
+ void Parameters::setCurveBack( unsigned int level, float curveBack ) {
+ if( level <= mMaxLevels )
+ mCurveBack[ level ] = curveBack;
+ }
+
+ void Parameters::setCurve( unsigned int level, float curve ) {
+ if( level <= mMaxLevels )
+ mCurve[ level ] = curve;
+ }
+
+ void Parameters::setLengthV( unsigned int level, float lengthV ) {
+ if( level <= mMaxLevels )
+ mLengthV[ level ] = lengthV;
+ }
+
+ void Parameters::setLength( unsigned int level, float length ) {
+ if( level <= mMaxLevels )
+ mLength[ level ] = length;
+ }
+
+ void Parameters::setRotateV( unsigned int level, float rotateV ) {
+ if( level <= mMaxLevels )
+ mRotateV[ level ] = rotateV;
+ }
+
+ void Parameters::setRotate( unsigned int level, float rotate ) {
+ if( level <= mMaxLevels )
+ mRotate[ level ] = rotate;
+ }
+
+ void Parameters::setDownAngleV( unsigned int level, float downAngleV ) {
+ if( level <= mMaxLevels )
+ mDownAngleV[ level ] = downAngleV;
+ }
+
+ void Parameters::setDownAngle( unsigned int level, float downAngle ) {
+ if( level <= mMaxLevels )
+ mDownAngle[ level ] = downAngle;
+ }
+
+ void Parameters::setNumBranches( unsigned int level, unsigned char numBranches ) {
+ if( level <= mMaxLevels )
+ mNumBranches[ level ] = numBranches;
+ }
+
+ void Parameters::setNumVertices( unsigned int level, unsigned char numVertices ) {
+ if( level <= mMaxLevels )
+ mNumVertices[ level ] = numVertices;
+ }
+} // CaduneTree
\ No newline at end of file
Added: trunk/python-ogre/ThirdParty/cadunetree/CTParameters.h
===================================================================
--- trunk/python-ogre/ThirdParty/cadunetree/CTParameters.h (rev 0)
+++ trunk/python-ogre/ThirdParty/cadunetree/CTParameters.h 2008-01-08 02:45:30 UTC (rev 532)
@@ -0,0 +1,359 @@
+/*
+This file is a part of the CaduneTree project,
+library used to generate and render trees with OGRE.
+
+License:
+Copyright (c) 2007 Wojciech Cierpucha
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef _CTParameters_h_
+#define _CTParameters_h_
+
+#include "CTPrerequisites.h"
+#include <OgreString.h>
+
+/// @file
+
+namespace CaduneTree {
+
+
+ /// @class Parameters
+ /// This class describes all parameters used to generate a tree, it allows to keep data for 4 levels of recursion.
+ /// You can save/load it using Serializer class.
+
+ /// Tree parameters class.
+ class Parameters {
+ public:
+ Parameters(); ///< Constructor sets values to default
+ Parameters( const Parameters& params ); ///< Copy constructor
+ ~Parameters(); ///< Destructor cleans up
+
+ /// Serializer has to see private elements
+ friend class Serializer;
+
+ /// This function is used to set parameters to their default values, which describe a low poly tree
+ void setDefault();
+ /// Create another instance of class Parameters by copying this one
+ /// @return - new instance of these Parameters
+ Parameters* createCopy() const;
+
+ /// Set shape
+ /// @param shape - a ShapeEnum enumeration used to choose one of possible tree shapes
+ void setShape( ShapeEnum shape ) { mShape = shape; }
+ /// Set base size
+ /// @param baseSize - tree's base size, varying from 0 to 1, describing how high level 2 branches start
+ void setBaseSize( float baseSize ) { mBaseSize = baseSize; }
+ /// Set scale
+ /// @param scale - a scale factor
+ void setScale( float scale ) { mScale = scale; }
+ /// Set scale variation
+ /// @param scaleV - scale factor variation
+ void setScaleV( float scaleV ) { mScaleV = scaleV; }
+ /// Set number of leaves
+ /// @param numLevels - number of leaves to set
+ void setNumLevels( unsigned char numLevels ) { mNumLevels = numLevels; }
+ /// Set ratio
+ /// @param ratio - ratio
+ void setRatio( float ratio ) { mRatio = ratio; }
+ /// Set ratio power
+ /// @param ratioPower - ratio power factor
+ void setRatioPower( float ratioPower ) { mRatioPower = ratioPower; }
+ /// Set number of lobes
+ /// @param numLobes - number of lobes
+ void setNumLobes( unsigned char numLobes ) { mNumLobes = numLobes; }
+ /// Set depth of lobes
+ /// @param lobeDepth - depth of lobes
+ void setLobeDepth( float lobeDepth ) { mLobeDepth = lobeDepth; }
+ /// Set flare
+ /// @param flare - flare
+ void setFlare( float flare ) { mFlare = flare; }
+ /// Set trunk's scale
+ /// @param scale0 - 0Scale
+ void setScale0( float scale0 ) { mScale0 = scale0; }
+ /// Set trunk's scale variation
+ /// @param scale0V - 0Scale variation
+ void setScale0V( float scale0V ) { mScale0V = scale0V; }
+ /// Set bark material to be used
+ /// @param barkMaterial - material's name
+ void setBarkMaterial( Ogre::String barkMaterial ) { mBarkMaterial = barkMaterial; }
+ /// Set leaf scale
+ /// @param leafScale - scale factor for leaves
+ void setLeafScale( float leafScale ) { mLeafScale = leafScale; }
+ /// Set horizontal leaf scale
+ /// @param leafScaleX - relative horizontal scale factor for leaves
+ void setLeafScaleX( float leafScaleX ) { mLeafScaleX = leafScaleX; }
+ /// Set number of leaves
+ /// @param numLeaves - number of leaves to set for each branch of last level of recursion
+ void setNumLeaves( unsigned char numLeaves ) { mNumLeaves = numLeaves; }
+ /// Set leaf quality factor
+ /// @param leafQuality - factor used to describe number and size of leaves, useful for LOD
+ void setLeafQuality( float leafQuality ) { mLeafQuality = leafQuality; }
+ /// Set leaf layout exponent
+ /// @param leafLayoutExp - when 1 leaves will be situated linearly across the branch
+ void setLeafLayoutExp( float leafLayoutExp ) { mLeafLayoutExp = leafLayoutExp; }
+ /// Set material to be used for leaves
+ /// @param leafMaterial - material's name
+ void setLeafMaterial( Ogre::String leafMaterial ) { mLeafMaterial = leafMaterial; }
+ /// Set frond scale
+ /// @param frondScale - scale factor for fronds
+ void setFrondScale( float frondScale ) { mFrondScale = frondScale; }
+ /// Set horizontal frond scale
+ /// @param frondScaleX - relative horizontal scale factor for fronds
+ void setFrondScaleX( float frondScaleX ) { mFrondScaleX = frondScaleX; }
+ /// Set number of fronds
+ /// @param numFronds - number of fronds to set for each branch of last level of recursion
+ void setNumFronds( unsigned char numFronds ) { mNumFronds = numFronds; }
+ /// Set frond quality factor
+ /// @param frondQuality - factor used to describe number and size of fronds
+ void setFrondQuality( float frondQuality ) { mFrondQuality = frondQuality; }
+ /// Set material to be used for fronds
+ /// @param frondMaterial - material's name
+ void setFrondMaterial( Ogre::String frondMaterial ) { mFrondMaterial = frondMaterial; }
+ /// Set vertical attraction
+ /// @param attractionUp - vertical attraction
+ void setAttractionUp( float attractionUp ) { mAttractionUp = attractionUp; }
+ /// Set number of vertices for given level
+ /// @param level - desired level
+ /// @param numVertices - number of vertices to set
+ void setNumVertices( unsigned int level, unsigned char numVertices );
+ /// Set number of branches for given level
+ /// @param level - desired level
+ /// @param numBranches - number of branches to set
+ void setNumBranches( unsigned int level, unsigned char numBranches );
+ /// Set down angle
+ /// @param level - desired level
+ /// @param downAngle - angle beetwen branch and its parent
+ void setDownAngle( unsigned int level, float downAngle );
+ /// Set down angle variation
+ /// @param level - desired level
+ /// @param downAngleV - down angle variation
+ void setDownAngleV( unsigned int level, float downAngleV );
+ /// Set rotate angle
+ /// @param level - desired level
+ /// @param rotate - angle to rotate around parent
+ void setRotate( unsigned int level, float rotate );
+ /// Set rotate angle variation
+ /// @param level - desired level
+ /// @param rotateV - rotate angle variation
+ void setRotateV( unsigned int level, float rotateV );
+ /// Set length
+ /// @param level - desired level
+ /// @param length - length, 1.0 means parent's length, 2.0 double of it, etc.
+ void setLength( unsigned int level, float length );
+ /// Set length variation
+ /// @param level - desired level
+ /// @param lengthV - length variation
+ void setLengthV( unsigned int level, float lengthV );
+ /// Set curve
+ /// @param level - desired level
+ /// @param curve - angle used to curve the branch
+ void setCurve( unsigned int level, float curve );
+ /// Set back curve
+ /// @param level - desired level
+ /// @param curveBack - back curve
+ void setCurveBack( unsigned int level, float curveBack );
+ /// Set curve variation
+ /// @param level - desired level
+ /// @param curveV - curve variation
+ void setCurveV( unsigned int level, float curveV );
+ /// Set curve resolution
+ /// @param level - desired level
+ /// @param curveRes - number of sections in a branch - resolution
+ void setCurveRes( unsigned int level, unsigned char curveRes );
+
+ /// Get maximum number of levels
+ /// @return constant predefined maximum number of levels
+ unsigned int getMaxLevels() const { return mMaxLevels; }
+
+ /// Get shape
+ /// @return - ShapeEnum shape
+ ShapeEnum getShape() const { return mShape; }
+ /// Get base size
+ /// @return - tree's base size, varying from 0 to 1, describing how high level 2 branches start
+ float getBaseSize() const { return mBaseSize; }
+ /// Get scale
+ /// @return - a scale factor
+ float getScale() const { return mScale; }
+ /// Get scale variation
+ /// @return - scale factor variation
+ float getScaleV() const { return mScaleV; }
+ /// Get number of levels
+ /// @return number of levels of recursion in tree
+ unsigned char getNumLevels() const { return mNumLevels; }
+ /// Get ratio
+ /// @return ratio factor
+ float getRatio() const { return mRatio; }
+ /// Get ratio power
+ /// @return ratio power factor
+ float getRatioPower() const { return mRatioPower; }
+ /// Get number of lobes
+ /// @return number of lobes
+ unsigned char getNumLobes() const { return mNumLobes; }
+ /// Get lobe depth
+ /// @return lobes' depth
+ float getLobeDepth() const { return mLobeDepth; }
+ /// Get flare
+ /// @return flare
+ float getFlare() const { return mFlare; }
+ /// Get trunk's scale
+ /// @return trunk's scale factor
+ float getScale0() const { return mScale0; }
+ /// Get trunk's scale variation
+ /// @return trunk's scale factor variation
+ float getScale0V() const { return mScale0V; }
+ /// Get bark's material to be used
+ /// @return bark's material name
+ Ogre::String getBarkMaterial() const { return mBarkMaterial; }
+ /// Get leaf scale
+ /// @return leaf scale
+ float getLeafScale() const { return mLeafScale; }
+ /// Get horizontal leaf scale
+ /// @return horizontal leaf scale, which is applied to leaf scale
+ float getLeafScaleX() const { return mLeafScaleX; }
+ /// Get number of leaves
+ /// @return number of leaves
+ unsigned char getNumLeaves() const { return mNumLeaves; }
+ /// Get leaf quality
+ /// @return leaf quality factor
+ float getLeafQuality() const { return mLeafQuality; }
+ /// Get leaf layout exponent - used to determine how leaves are located across branches, use 1.0 to use linear distribution
+ /// @return leaf layout exponent
+ float getLeafLayoutExp() const { return mLeafLayoutExp; }
+ /// Get leaf material
+ /// @return material's name
+ Ogre::String getLeafMaterial() const { return mLeafMaterial; }
+ /// Get frond scale
+ /// @return frond scale factor
+ float getFrondScale() const { return mFrondScale; }
+ /// Get horizontal frond scale
+ /// @return relative to frond scale, horizontal scale factor
+ float getFrondScaleX() const { return mFrondScaleX; }
+ /// Get number of fronds
+ /// @return number of fronds
+ unsigned char getNumFronds() const { return mNumFronds; }
+ /// Get frond quality
+ /// @return quality factor
+ float getFrondQuality() const { return mFrondQuality; }
+ /// Get frond material
+ /// @return material's name
+ Ogre::String getFrondMaterial() const { return mFrondMaterial; }
+ /// Get vertical attraction
+ /// @return vertical attraction factor
+ float getAttractionUp() const { return mAttractionUp; }
+ /// Get tapering parameter (not used, constant for now)
+ /// @return taper
+ float getTaper() const { return mTaper; }
+
+ /// Get number of vertices for a specific level
+ /// @param level - desired level of recursion
+ /// @return number of vetices
+ unsigned char getNumVertices( unsigned int level ); // code in .cpp file and check if level < mNumLevels
+ /// Get number of branches for a specific level
+ /// @param level - desired level of recursion
+ /// @return number of branches
+ unsigned char getNumBranches( unsigned int level );
+ /// Get down angle for a specific level
+ /// @param level - desired level of recursion
+ /// @return down angle
+ float getDownAngle( unsigned int level );
+ /// Get down angle variation for a specific level
+ /// @param level - desired level of recursion
+ /// @return down angle variation
+ float getDownAngleV( unsigned int level );
+ /// Get rotate parameter for a specific level
+ /// @param level - desired level of recursion
+ /// @return rotation parameter
+ float getRotate( unsigned int level );
+ /// Get rotate variation parameter for a specific level
+ /// @param level - desired level of recursion
+ /// @return rotation variation parameter
+ float getRotateV( unsigned int level );
+ /// Get length for a specific level
+ /// @param level - desired level of recursion
+ /// @return length
+ float getLength( unsigned int level );
+ /// Get length variation for a specific level
+ /// @param level - desired level of recursion
+ /// @return length variation
+ float getLengthV( unsigned int level );
+ /// Get curve parameter for a specific level
+ /// @param level - desired level of recursion
+ /// @return curve parameter
+ float getCurve( unsigned int level );
+ /// Get curve back parameter for a specific level
+ /// @param level - desired level of recursion
+ /// @return curve back parameter
+ float getCurveBack( unsigned int level );
+ /// Get curve variation parameter for a specific level
+ /// @param level - desired level of recursion
+ /// @return curve variation parameter
+ float getCurveV( unsigned int level );
+ /// Get curve resolution parameter for a specific level
+ /// @param level - desired level of recursion
+ /// @return curve resolution parameter
+ unsigned char getCurveRes( unsigned int level );
+ private:
+ ShapeEnum mShape;
+ float mBaseSize;
+ float mScale;
+ float mScaleV;
+ unsigned char mNumLevels;
+ float mRatio;
+ float mRatioPower;
+ unsigned char mNumLobes;
+ float mLobeDepth;
+ float mFlare;
+ float mScale0;
+ float mScale0V;
+ Ogre::String mBarkMaterial;
+ float mLeafScale;
+ float mLeafScaleX;
+ unsigned char mNumLeaves;
+ float mLeafQuality;
+ float mLeafLayoutExp;
+ Ogre::String mLeafMaterial;
+ float mFrondScale;
+ float mFrondScaleX;
+ unsigned char mNumFronds;
+ float mFrondQuality;
+ Ogre::String mFrondMaterial;
+ float mAttractionUp;
+ const float mTaper; // constant = 1, at least for now
+ unsigned char *mNumVertices;
+ unsigned char *mNumBranches;
+ float *mDownAngle;
+ float *mDownAngleV;
+ float *mRotate;
+ float *mRotateV;
+ float *mLength;
+ float *mLengthV;
+ float *mCurve;
+ float *mCurveBack;
+ float *mCurveV;
+ unsigned char *mCurveRes;
+
+ /// Predefined maximum number of levels possible
+ static const unsigned int mMaxLevels;
+ }; // Parameters
+
+} // CaduneTree
+
+#endif
\ No newline at end of file
Added: trunk/python-ogre/ThirdParty/cadunetree/CTPrerequisites.h
===================================================================
--- trunk/python-ogre/ThirdParty/cadunetree/CTPrerequisites.h (rev 0)
+++ trunk/python-ogre/ThirdParty/cadunetree/CTPrerequisites.h 2008-01-08 02:45:30 UTC (rev 532)
@@ -0,0 +1,56 @@
+/*
+This file is a part of the CaduneTree project,
+library used to generate and render trees with OGRE.
+
+License:
+Copyright (c) 2007 Wojciech Cierpucha
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef _CTPrerequisites_h_
+#define _CTPrerequisites_h_
+
+namespace CaduneTree {
+
+ // Class declarations
+ class Parameters;
+ class Serializer;
+ class Section;
+ class Stem;
+
+ // Enumeration declarations
+ /// @enum ShapeEnum
+ /// Enum used to describe possible tree shapes
+ enum ShapeEnum {
+ CONICAL = 0, ///< Conical shape
+ SPHERICAL, ///< Spherical shape
+ HEMISPHERICAL, ///< Hemispherical shape
+ CYLINDRICAL, ///< Cylindrical shape
+ TAPERED_CYLINDRICAL, ///< Tapered cylindrical shape
+ FLAME, ///< Flame shape
+ INVERSE_CONICAL, ///< Inverse conical shape
+ TEND_FLAME, ///< Tend flame shape
+ //ENVELOPE ///< Envelope shape ---pruning
+ };
+
+
+} // CaduneTree
+
+#endif
\ No newline at end of file
Added: trunk/python-ogre/ThirdParty/cadunetree/CTSection.cpp
===================================================================
--- trunk/python-ogre/ThirdParty/cadunetree/CTSection.cpp (rev 0)
+++ trunk/python-ogre/ThirdParty/cadunetree/CTSection.cpp 2008-01-08 02:45:30 UTC (rev 532)
@@ -0,0 +1,109 @@
+/*
+This file is a part of the CaduneTree project,
+library used to generate and render trees with OGRE.
+
+License:
+Copyright (c) 2007 Wojciech Cierpucha
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "CTSection.h"
+
+namespace CaduneTree {
+
+ Section::Section() {
+ mOrigin = Ogre::Vector3::ZERO;
+ mGlobalOrigin = Ogre::Vector3::ZERO;
+ mOrientation = Ogre::Quaternion::IDENTITY;
+ mTexVCoord = 0.0f;
+ }
+
+ Section::~Section() {
+
+ }
+
+ void Section::create( unsigned int numLobes, float lobeDepth, float radius, unsigned int numVertices ) {
+ float angle = 2 * Ogre::Math::PI / numVertices;
+ float lobedRadius;
+ Ogre::Vector3 localVertex;
+ Ogre::Vector3 globalVertex;
+ for( unsigned int i = 0; i < numVertices; ++i ) {
+ lobedRadius = radius * ( 1.0f + lobeDepth * Ogre::Math::Sin( i * numLobes * angle ) );
+ localVertex.x = Ogre::Math::Cos( i * angle ) * lobedRadius;
+ localVertex.y = 0.0f;
+ localVertex.z = Ogre::Math::Sin( i * angle ) * lobedRadius;
+
+ globalVertex = mOrientation * ( mOrigin + localVertex ) + mGlobalOrigin;
+ mGlobalVertices.push_back( globalVertex );
+ mNormals.push_back( ( mOrientation * localVertex ).normalisedCopy() );
+
+ mTexUCoords.push_back( ( float ) i / numVertices );
+ }
+ // Additional vertex
+ mGlobalVertices.push_back( *mGlobalVertices.begin() );
+ mNormals.push_back( *mNormals.begin() );
+ mTexUCoords.push_back( 1.0f );
+ }
+
+ void Section::setGlobalOrigin( const Ogre::Vector3& globalOrigin ) {
+ mGlobalOrigin = globalOrigin;
+ }
+
+ void Section::setOrigin( const Ogre::Vector3 &origin ) {
+ mOrigin = origin;
+ }
+
+ void Section::setOrientation( const Ogre::Quaternion& orientation ) {
+ mOrientation = orientation;
+ }
+
+ void Section::setTexVCoord( float v ) {
+ mTexVCoord = v;
+ }
+
+ std::vector< Ogre::Vector3 >* Section::getGlobalVertices() {
+ return &mGlobalVertices;
+ }
+
+ std::vector< Ogre::Vector3 >* Section::getNormals() {
+ return &mNormals;
+ }
+
+ std::vector< float >* Section::getTexUCoords() {
+ return &mTexUCoords;
+ }
+
+ Ogre::Quaternion Section::getOrientation() const {
+ return mOrientation;
+ }
+
+ Ogre::Vector3 Section::getOrigin() const {
+ return mOrigin;
+ }
+
+ Ogre::Vector3 Section::getGlobalOrigin() const {
+ return mGlobalOrigin;
+ }
+
+ float Section::getTexVCoord() const {
+ return mTexVCoord;
+ }
+
+} // CaduneTree
\ No newline at end of file
Added: trunk/python-ogre/ThirdParty/cadunetree/CTSection.h
===================================================================
--- trunk/python-ogre/ThirdParty/cadunetree/CTSection.h (rev 0)
+++ trunk/python-ogre/ThirdParty/cadunetree/CTSection.h 2008-01-08 02:45:30 UTC (rev 532)
@@ -0,0 +1,74 @@
+/*
+This file is a part of the CaduneTree project,
+library used to generate and render trees with OGRE.
+
+License:
+Copyright (c) 2007 Wojciech Cierpucha
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef _CTSection_h_
+#define _CTSection_h_
+
+#include "CTPrerequisites.h"
+#include <Ogre.h>
+#include <vector>
+
+/// @file
+
+namespace CaduneTree {
+
+ /// @class Section
+ /// Objects of this type hold information about vertices, their normals and texture coordinates (one set).
+ /// This is used only internally in methods of Stem class. Thus there is no need to document the code.
+
+ /// Used only internally.
+ class Section {
+ public:
+ Section();
+ ~Section();
+
+ void create( unsigned int numLobes, float lobeDepth, float radius, unsigned int numVertices );
+ void setOrientation( const Ogre::Quaternion& orientation );
+ void setGlobalOrigin( const Ogre::Vector3& globalOrigin );
+ void setOrigin( const Ogre::Vector3& origin );
+ void setTexVCoord( float v );
+
+ std::vector< Ogre::Vector3 >* getGlobalVertices();
+ std::vector< Ogre::Vector3 >* getNormals();
+ std::vector< float >* getTexUCoords();
+
+ Ogre::Quaternion getOrientation() const;
+ Ogre::Vector3 getOrigin() const;
+ Ogre::Vector3 getGlobalOrigin() const;
+ float getTexVCoord() const;
+ private:
+ Ogre::Vector3 mOrigin;
+ Ogre::Vector3 mGlobalOrigin;
+ Ogre::Quaternion mOrientation;
+ std::vector< Ogre::Vector3 > mGlobalVertices;
+ std::vector< Ogre::Vector3 > mNormals;
+ std::vector< float > mTexUCoords;
+ float mTexVCoord;
+ };
+
+} // CaduneTree
+
+#endif
\ No newline at end of file
Added: trunk/python-ogre/ThirdParty/cadunetree/CTSerializer.cpp
===================================================================
--- trunk/python-ogre/ThirdParty/cadunetree/CTSerializer.cpp (rev 0)
+++ trunk/python-ogre/ThirdParty/cadunetree/CTSerializer.cpp 2008-01-08 02:45:30 UTC (rev 532)
@@ -0,0 +1,169 @@
+/*
+This file is a part of the CaduneTree project,
+library used to generate and render trees with OGRE.
+
+License:
+Copyright (c) 2007 Wojciech Cierpucha
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "CTSerializer.h"
+#include "CTParameters.h"
+#include <OgreException.h>
+
+using namespace std;
+
+namespace CaduneTree {
+
+ void Serializer::exportDefinition( const string &filename, Parameters *params ) {
+ if( !params )
+ throw Ogre::Exception( Ogre::Exception::ERR_INVALIDPARAMS, "Passed Parameters pointer is null", "Serializer::exportDefinition" );
+
+ ofstream file( filename.c_str(), ios_base::binary );
+
+ // File header
+ file << "CTD";
+ file << ( char ) 6;
+
+ // General
+ file.write( ( char* ) ¶ms->mShape, sizeof( ShapeEnum ) );
+ file.write( ( char* ) ¶ms->mBaseSize, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mScale, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mScaleV, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mNumLevels, sizeof( unsigned char ) );
+ file.write( ( char* ) ¶ms->mRatio, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mRatioPower, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mNumLobes, sizeof( unsigned char ) );
+ file.write( ( char* ) ¶ms->mLobeDepth, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mFlare, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mScale0, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mScale0V, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mAttractionUp, sizeof ( float ) );
+ // file.write( ( char* ) ¶ms->mBarkMaterial, sizeof( string ) );
+
+ // Leaves
+ file.write( ( char* ) ¶ms->mNumLeaves, sizeof( unsigned char ) );
+ file.write( ( char* ) ¶ms->mLeafScale, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mLeafScaleX, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mLeafQuality, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mLeafLayoutExp, sizeof( float ) );
+ // file.write( ( char* ) ¶ms->mLeafMaterial, sizeof( string ) );
+
+ // Fronds
+ file.write( ( char* ) ¶ms->mNumFronds, sizeof( unsigned char ) );
+ file.write( ( char* ) ¶ms->mFrondScale, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mFrondScaleX, sizeof( float ) );
+ file.write( ( char* ) ¶ms->mFrondQuality, sizeof( float ) );
+ //file.write( ( char* ) ¶ms->mFrondMaterial, sizeof( string ) );
+
+ // Branches
+ for( unsigned int i = 0; i < params->mMaxLevels + 1; ++i ) {
+ file.write( ( char* ) ¶ms->mNumVertices[ i ], sizeof( unsigned char ) );
+ file.write( ( char* ) ¶ms->mNumBranches[ i ], sizeof( unsigned char ) );
+ file.write( ( char* ) ¶ms->mDownAngle[ i ], sizeof( float ) );
+ file.write( ( char* ) ¶ms->mDownAngleV[ i ], sizeof( float ) );
+ file.write( ( char* ) ¶ms->mRotate[ i ], sizeof( float ) );
+ file.write( ( char* ) ¶ms->mRotateV[ i ], sizeof( float ) );
+ file.write( ( char* ) ¶ms->mLength[ i ], sizeof( float ) );
+ file.write( ( char* ) ¶ms->mLengthV[ i ], sizeof( float ) );
+ file.write( ( char* ) ¶ms->mCurve[ i ], sizeof( float ) );
+ file.write( ( char* ) ¶ms->mCurveBack[ i ], sizeof( float ) );
+ file.write( ( char* ) ¶ms->mCurveV[ i ], sizeof( float ) );
+ file.write( ( char* ) ¶ms->mCurveRes[ i ], sizeof( unsigned char ) );
+ }
+ // EOF
+ }
+
+ Parameters* Serializer::importDefinition( const string &filename ) {
+ Parameters *params = 0;
+
+ ifstream file( filename.c_str(), ios_base::binary );
+ char cheader[4];
+ file.read( ( char* ) cheader, 3 * sizeof( char ) );
+ cheader[3] = '\0';
+ string header( cheader );
+ if( header != "CTD" )
+ throw Ogre::Exception( Ogre::Exception::ERR_FILE_NOT_FOUND, "This is not a proper .ctd file!", "Serializer::importDefinition" );
+
+ char version;
+ file.read( ( char* ) &version, sizeof( char ) );
+ if( version == 6 )
+ params = import006( &file );
+ else
+ throw Ogre::Exception( Ogre::Exception::ERR_FILE_NOT_FOUND, "Not supported CTD file version!", "Serializer::importDefinition" );
+
+ return params;
+ }
+
+ Parameters* Serializer::import006( ifstream *file ) {
+ Parameters *params = new Parameters;
+
+ // General
+ file->read( ( char* ) ¶ms->mShape, sizeof( ShapeEnum ) );
+ file->read( ( char* ) ¶ms->mBaseSize, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mScale, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mScaleV, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mNumLevels, sizeof( unsigned char ) );
+ file->read( ( char* ) ¶ms->mRatio, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mRatioPower, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mNumLobes, sizeof( unsigned char ) );
+ file->read( ( char* ) ¶ms->mLobeDepth, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mFlare, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mScale0, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mScale0V, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mAttractionUp, sizeof ( float ) );
+ // file->read( ( char* ) ¶ms->mBarkMaterial, sizeof( string ) );
+
+ // Leaves
+ file->read( ( char* ) ¶ms->mNumLeaves, sizeof( unsigned char ) );
+ file->read( ( char* ) ¶ms->mLeafScale, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mLeafScaleX, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mLeafQuality, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mLeafLayoutExp, sizeof( float ) );
+ // file->read( ( char* ) ¶ms->mLeafMaterial, sizeof( string ) );
+
+ // Fronds
+ file->read( ( char* ) ¶ms->mNumFronds, sizeof( unsigned char ) );
+ file->read( ( char* ) ¶ms->mFrondScale, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mFrondScaleX, sizeof( float ) );
+ file->read( ( char* ) ¶ms->mFrondQuality, sizeof( float ) );
+ //file->read( ( char* ) ¶ms->mFrondMaterial, sizeof( string ) );
+
+ // Branches
+ for( unsigned int i = 0; i < params->mMaxLevels + 1; ++i ) {
+ file->read( ( char* ) ¶ms->mNumVertices[ i ], sizeof( unsigned char ) );
+ file->read( ( char* ) ¶ms->mNumBranches[ i ], sizeof( unsigned char ) );
+ file->read( ( char* ) ¶ms->mDownAngle[ i ], sizeof( float ) );
+ file->read( ( char* ) ¶ms->mDownAngleV[ i ], sizeof( float ) );
+ file->read( ( char* ) ¶ms->mRotate[ i ], sizeof( float ) );
+ file->read( ( char* ) ¶ms->mRotateV[ i ], sizeof( float ) );
+ file->read( ( char* ) ¶ms->mLength[ i ], sizeof( float ) );
+ file->read( ( char* ) ¶ms->mLengthV[ i ], sizeof( float ) );
+ file->read( ( char* ) ¶ms->mCurve[ i ], sizeof( float ) );
+ file->read( ( char* ) ¶ms->mCurveBack[ i ], sizeof( float ) );
+ file->read( ( char* ) ¶ms->mCurveV[ i ], sizeof( float ) );
+ file->read( ( char* ) ¶ms->mCurveRes[ i ], sizeof( unsigned char ) );
+ }
+ // EOF
+
+ return params;
+ }
+}
+ // CaduneTree
\ No newline at end of file
Added: trunk/python-ogre/ThirdParty/cadunetree/CTSerializer.h
===================================================================
--- trunk/python-ogre/ThirdParty/cadunetree/CTSerializer.h (rev 0)
+++ trunk/python-ogre/ThirdParty/cadunetree/CTSerializer.h 2008-01-08 02:45:30 UTC (rev 532)
@@ -0,0 +1,58 @@
+/*
+This file is a part of the CaduneTree project,
+library used to generate and render trees with OGRE.
+
+License:
+Copyright (c) 2007 Wojciech Cierpucha
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef _CTSerializer_h_
+#define _CTSerializer_h_
+
+#include "CTPrerequisites.h"
+#include <string>
+#include <fstream>
+
+/// @file
+
+namespace CaduneTree {
+
+ /// @class Serializer
+ /// Using this class one can import from file (every previous version is supported) parameters, as well as export them (only most current version of file format).
+
+ /// Class used for import and export of parameters.
+ class Serializer {
+ public:
+ /// Export parameters to file
+ /// @param filename - path to file or file name (only direct)
+ /// @param params - pointer to Paramaters object, which will be exported
+ static void exportDefinition( const std::string &filename, Parameters *params );
+ /// Import parameters from file
+ /// @param filename - path to file or file name (only direct)
+ static Parameters* importDefinition( const std::string &filename );
+ private:
+ /// Import, file format version 0.6
+ static Parameters* import006( std::ifstream *file );
+ };
+
+} // CaduneTree
+
+#endif
\ No newline at end of file
Added: trunk/python-ogre/ThirdParty/cadunetree/CTStem.cpp
===================================================================
--- trunk/python-ogre/ThirdParty/cadunetree/CTStem.cpp (rev 0)
+++ trunk/python-ogre/ThirdParty/cadunetree/CTStem.cpp 2008-01-08 02:45:30 UTC (rev 532)
@@ -0,0 +1,584 @@
+/*
+This file is a part of the CaduneTree project,
+library used to generate and render trees with OGRE.
+
+License:
+Copyright (c) 2007 Wojciech Cierpucha
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "CTStem.h"
+#include "CTParameters.h"
+#include "CTSection.h"
+
+using namespace Ogre;
+
+namespace CaduneTree {
+
+ Stem::Stem( Parameters* params, Stem* parent ) {
+ if( !params )
+ throw Exception( Exception::ERR_INVALIDPARAMS, "Parameters *params == NULL", "Stem::Stem" );
+
+ mParameters = params;
+ mParent = parent;
+ mNumSubStems = 0;
+ mNumLeaves = 0;
+ mNumFronds = 0;
+ mNumVertices = 0;
+ mNumTriangles = 0;
+ mLength = 1.0f;
+ mRadius = 1.0f;
+ mOffset = 0.0f;
+ mIsRoot = false;
+ mIsGrown = false;
+ }
+
+ Stem::~Stem() {
+ std::vector< Section* >::iterator i;
+ for( i = mSections.begin(); i != mSections.end(); ++i ) {
+ delete *i;
+ }
+ mSections.clear();
+
+ std::list< Stem* >::iterator j;
+ for( j = mSubStems.begin(); j != mSubStems.end(); ++j ) {
+ delete *j;
+ }
+ mSubStems.clear();
+ }
+
+ void Stem::grow( const Quaternion& orientation, const Vector3& origin, float radius, float length, float offset, unsigned char level ) {
+ if( level >= mParameters->getNumLevels() && !mIsRoot )
+ return;
+
+ if( mParameters->getCurveRes( level ) == 0 )
+ return;
+
+ mOrigin = origin;
+ mOrientation = orientation;
+
+ // Locals used
+ Vector3 localSectionOrigin = Vector3::ZERO;
+ Vector3 step = Vector3::ZERO;
+ Vector3 currentOrigin = mOrigin;
+ Quaternion localOrientation = mOrientation;
+ Quaternion newLocalOrientation = mOrientation;
+ Section* section = 0;
+ float sectionRadius = radius;
+ float y = 0.0f;
+ float angle = 0.0f;
+ float treeScale = mParameters->getScale() + getRandom( mParameters->getScaleV() );
+ float trunkLength = treeScale * ( mParameters->getLength( 0 ) + getRandom( mParameters->getLengthV( 0 ) ) );
+ float baseLength = mParameters->getBaseSize() * treeScale;
+
+ // Trunk?
+ if( level == 0 ) {
+ mLength = trunkLength;
+ mRadius = mLength * mParameters->getRatio() * ( mParameters->getScale0() + getRandom( mParameters->getScale0V() ) );
+ mOffset = 0.0f;
+ } else {
+ mRadius = radius;
+ mLength = length;
+ mOffset = offset;
+ }
+
+ // to avoid having empty first block, ie to start from mOrigin
+ //localSectionOrigin = Vector3( 0.0f, mLength / mParameters->getCurveRes( level ), 0.0f );
+ //currentOrigin -= mOrientation * localSectionOrigin; // wow, it works ;)
+ step = Vector3( 0.0f, mLength / mParameters->getCurveRes( level ), 0.0f );
+
+ for( unsigned int i = 0; i < mParameters->getCurveRes( level ); ++i ) {
+ if( !Math::RealEqual( mParameters->getCurveBack( level ), 0.0f ) ) {
+ if( mParameters->getCurveRes( level ) / ( i + 1 ) < 2 )
+ angle = 2.0f * mParameters->getCurve( level ) / mParameters->getCurveRes( level );
+ else
+ angle = 2.0f * mParameters->getCurveBack( level ) / mParameters->getCurveRes( level );
+ }
+ else
+ angle = mParameters->getCurve( level ) / mParameters->getCurveRes( level );
+
+ angle += getRandom( mParameters->getCurveV( level ) / mParameters->getCurveRes( level ) );
+
+ // Calculate vertical attraction
+ if( level > 1 && !mIsRoot ) {
+ float decli = Math::ACos( Vector3( newLocalOrientation * Vector3::UNIT_Y ).y ).valueRadians();
+ float orien = Math::ACos( Vector3( newLocalOrientation * Vector3::UNIT_Z ).y ).valueRadians();
+ // No idea why Weber & Penn used acos and then cos ?!
+ angle += mParameters->getAttractionUp() * decli * Math::Cos( orien ) / mParameters->getCurveRes( level );
+ }
+
+ angle = Math::DegreesToRadians( angle );
+ localOrientation.FromAngleAxis( Radian( angle ), Vector3::UNIT_X );
+ localOrientation = newLocalOrientation * localOrientation;
+
+ y = mLength * ( ( float ) i / mParameters->getCurveRes( level ) );
+ sectionRadius = mRadius * ( 1.0f - Math::Pow( y / mLength, 2 ) );
+
+ // flaring
+ if( level == 0 ) {
+ float y2 = 1.0f - 8.0f * ( ( float ) i / mParameters->getCurveRes( level ) );
+ if( y2 < 0.0f )
+ y2 = 0.0f;
+ sectionRadius *= 1.0f + mParameters->getFlare() * ( Math::Pow( 100, y2 ) - 1.0f ) * 0.01f;
+ }
+
+ section = new Section;
+ section->setOrientation( localOrientation );
+ section->setOrigin( localSectionOrigin );
+ section->setGlobalOrigin( currentOrigin );
+ section->setTexVCoord( ( float ) 0.1f * mLength * i / mParameters->getCurveRes( level ) );
+
+ if( level == 0 ) // lobbed?
+ section->create( mParameters->getNumLobes(), mParameters->getLobeDepth(), sectionRadius, mParameters->getNumVertices( level ) );
+ else
+ section->create( 0, 0.0f, sectionRadius, mParameters->getNumVertices( level ) );
+
+ mSections.push_back( section );
+
+ newLocalOrientation = localOrientation;
+ currentOrigin += localOrientation * step;
+ }
+ mEndVertex = currentOrigin + localOrientation * localSectionOrigin;
+
+ // Situate and spawn substems if this is not a root stem
+ if( !mIsRoot )
+ growChildren( level );
+
+ // Situate leaves and fronds
+ if( level == mParameters->getNumLevels() - 1 && !mIsRoot ) {
+ growLeaves( level );
+ growFronds( level );
+ }
+
+ // this is a trunk stem => grow roots
+ if( level == 0 )
+ growRoots();
+
+ mIsGrown = true;
+ }
+
+ void Stem::growChildren( unsigned char level ) {
+ if( level > mParameters->getNumLevels() )
+ return;
+
+ Quaternion rotQuat = Quaternion::IDENTITY;
+ Quaternion downQuat = Quaternion::IDENTITY;
+ Section* currentSection = 0;
+ Vector3 stemOrigin = Vector3::ZERO;
+ float rotate = getRandom( Math::PI );
+ float downAngle = 0.0f;
+ float treeScale = mParameters->getScale() + getRandom( mParameters->getScaleV() );
+ float baseLength = mParameters->getBaseSize() * treeScale;
+ float lengthChildMax = mParameters->getLength( level + 1 ) + getRandom( mParameters->getLengthV( level + 1 ) );
+ float offset = 0.0f;
+ float length = 1.0f;
+ float radius = 1.0f;
+
+ if( level == 0 )
+ mNumSubStems = mParameters->getNumBranches( level + 1 );
+ else if( level == 1 )
+ mNumSubStems = ( unsigned int ) mParameters->getNumBranches( level + 1 ) * ( 0.2f + 0.8f * ( mLength / mParent->mLength ) / lengthChildMax );
+ else
+ mNumSubStems = ( unsigned int ) mParameters->getNumBranches( level + 1 ) * ( 1.0f - 0.5f * ( mOffset / mParent->mLength ) );
+
+ for( unsigned int i = 0; i < mNumSubStems; ++i ) {
+ if( level == 0 )
+ offset = mLength * ( mParameters->getBaseSize() + ( ( i + 1 ) * ( 1.0f - mParameters->getBaseSize() ) / ( mNumSubStems + 1 ) ) );
+ else
+ offset = mLength * ( ( float ) ( i + 1 ) / ( mNumSubStems + 1 ) );
+
+ currentSection = findSection( offset / mLength, mParameters->getCurveRes( level ) );
+
+ if( level == 0 )
+ length = mLength * lengthChildMax * shapeRatio( mParameters->getShape(), ( mLength - offset ) / ( mLength - ( treeScale * mParameters->getBaseSize() ) ) );
+ else
+ length = lengthChildMax * ( mLength - 0.6f * offset );
+
+ radius = mRadius * Math::Pow( ( length / mLength ), mParameters->getRatioPower() );
+
+ // Down angle
+ if( mParameters->getDownAngleV( level + 1 ) >= 0.0f )
+ downAngle = Math::DegreesToRadians( mParameters->getDownAngle( level + 1 ) + getRandom( mParameters->getDownAngleV( level + 1 ) ) );
+ else {
+ float temp = ( level == 0 ) ? mLength - baseLength : mLength;
+ downAngle = Math::DegreesToRadians( mParameters->getDownAngle( level + 1 ) + getRandom( mParameters->getDownAngleV( level + 1 ) * ( 1.0f - 2.0f * shapeRatio( CONICAL, ( mLength - offset ) / temp ) ) ) );
+ }
+ downQuat.FromAngleAxis( Radian( downAngle ), Vector3::UNIT_X );
+
+ // Rotate angle
+ if( mParameters->getRotate( level + 1 ) > 0.0f )
+ rotate += Math::DegreesToRadians( mParameters->getRotate( level + 1 ) + getRandom( mParameters->getRotateV( level + 1 ) ) );
+ else
+ rotate += Math::DegreesToRadians( 180.0f + mParameters->getRotate( level + 1 ) + getRandom( mParameters->getRotateV( level + 1 ) ) );
+
+ if( rotate > Math::TWO_PI )
+ rotate -= Math::TWO_PI;
+
+ rotQuat.FromAngleAxis( Radian( rotate ), Vector3::UNIT_Y );
+
+
+ stemOrigin = currentSection->getOrientation()
+ * Vector3( 0.0f, offset - findSectionIndex( offset / mLength, mParameters->getCurveRes( level ) ) * mLength / mParameters->getCurveRes( level ), 0.0f )
+ + currentSection->getGlobalOrigin();
+
+ // spawn
+ Stem* child = new Stem( mParameters, this );
+ mSubStems.push_back( child );
+ child->grow( currentSection->getOrientation() * rotQuat * downQuat, stemOrigin, radius, length, offset, level + 1 );
+ }
+ }
+
+ // TODO - this is almost a copy of growChildren
+ void Stem::growRoots() {
+ Quaternion rotQuat = Quaternion::IDENTITY;
+ Quaternion downQuat = Quaternion::IDENTITY;
+ Section* currentSection = mSections[0];
+ float rotate = getRandom( Math::PI );
+ float downAngle = 0.0f;
+ float treeScale = mParameters->getScale() + getRandom( mParameters->getScaleV() );
+ float baseLength = mParameters->getBaseSize() * treeScale;
+ float lengthChildMax = mParameters->getLength( mParameters->getMaxLevels() ) + getRandom( mParameters->getLengthV( mParameters->getMaxLevels() ) );
+ float length = 1.0f;
+ float radius = 1.0f;
+
+ unsigned int numRoots = mParameters->getNumBranches( mParameters->getMaxLevels() );
+ for( unsigned int i = 0; i < numRoots; ++i ) {
+ length = mLength * lengthChildMax;
+ radius = 3 * mRadius * Math::Pow( ( length / mLength ), mParameters->getRatioPower() );
+
+ // Down angle
+ if( mParameters->getDownAngleV( mParameters->getMaxLevels() ) >= 0.0f )
+ downAngle = Math::DegreesToRadians( mParameters->getDownAngle( mParameters->getMaxLevels() ) + getRandom( mParameters->getDownAngleV( mParameters->getMaxLevels() ) ) );
+ else {
+ float temp = mLength - baseLength;
+ downAngle = Math::DegreesToRadians( mParameters->getDownAngle( mParameters->getMaxLevels() ) + getRandom( mParameters->getDownAngleV( mParameters->getMaxLevels() ) * ( 1.0f - 2.0f * shapeRatio( CONICAL, mLength / temp ) ) ) );
+ }
+ downQuat.FromAngleAxis( Radian( downAngle ), Vector3::UNIT_X );
+
+ // Rotate angle
+ if( mParameters->getRotate( mParameters->getMaxLevels() ) > 0.0f )
+ rotate += Math::DegreesToRadians( mParameters->getRotate( mParameters->getMaxLevels() ) + getRandom( mParameters->getRotateV( mParameters->getMaxLevels() ) ) );
+ else
+ rotate += Math::DegreesToRadians( 180.0f + mParameters->getRotate( mParameters->getMaxLevels() ) + getRandom( mParameters->getRotateV( mParameters->getMaxLevels() ) ) );
+
+ if( rotate > Math::TWO_PI )
+ rotate -= Math::TWO_PI;
+
+ rotQuat.FromAngleAxis( Radian( rotate ), Vector3::UNIT_Y );
+
+ // spawn
+ Stem* child = new Stem( mParameters, this );
+ child->mIsRoot = true;
+ mSubStems.push_back( child );
+ child->grow( currentSection->getOrientation() * rotQuat * downQuat, mOrigin, radius, length, 0.0f, mParameters->getMaxLevels() );
+ }
+ }
+
+ void Stem::growLeaves( unsigned char level ) {
+ float offset = 0.0f;
+ Section* currentSection = 0;
+ Vector3 leafPosition = Vector3::ZERO;
+
+ float randomX = 0.0f;
+ float randomZ = 0.0f;
+
+ mNumLeav...
[truncated message content] |