Merged changes in the trunk up to revision 40096.

Conflicts resolved:
source/blender/makesrna/intern/rna_scene.c
source/blender/python/intern/CMakeLists.txt

Note for branch builders: Enabling Blender Player may cause linker errors.
This commit is contained in:
Tamito Kajiyama 2011-09-10 13:36:27 +00:00
commit 353713afe8
420 changed files with 39931 additions and 15902 deletions

@ -452,15 +452,8 @@ if(UNIX AND NOT APPLE)
if(WITH_OPENCOLLADA) if(WITH_OPENCOLLADA)
find_package(OpenCOLLADA) find_package(OpenCOLLADA)
if(OPENCOLLADA_FOUND) if(OPENCOLLADA_FOUND)
set(PCRE /usr CACHE PATH "PCRE Directory") find_package(XML2)
mark_as_advanced(PCRE) find_package(PCRE)
set(PCRE_LIBPATH ${PCRE}/lib)
set(PCRE_LIB pcre)
set(EXPAT /usr CACHE PATH "Expat Directory")
mark_as_advanced(EXPAT)
set(EXPAT_LIBPATH ${EXPAT}/lib)
set(EXPAT_LIB expat)
else() else()
set(WITH_OPENCOLLADA OFF) set(WITH_OPENCOLLADA OFF)
endif() endif()
@ -797,7 +790,7 @@ elseif(WIN32)
else() else()
# keep GCC spesific stuff here # keep GCC spesific stuff here
if(CMAKE_COMPILER_IS_GNUCC) if(CMAKE_COMPILER_IS_GNUCC)
set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid") set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32")
set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing") set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE) add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
@ -1267,6 +1260,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith) ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter) ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings) ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEFINED -Wundef)
# disable because it gives warnings for printf() & friends. # disable because it gives warnings for printf() & friends.
# ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion) # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable) ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
@ -1274,6 +1268,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall) ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof) ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare) ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEFINED -Wundef)
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel") elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")

@ -49,12 +49,14 @@ SET(_opencollada_FIND_COMPONENTS
OpenCOLLADAFramework OpenCOLLADAFramework
OpenCOLLADABaseUtils OpenCOLLADABaseUtils
GeneratedSaxParser GeneratedSaxParser
UTF
MathMLSolver MathMLSolver
pcre )
# Fedora openCOLLADA package links these statically
SET(_opencollada_FIND_STATIC_COMPONENTS
UTF
ftoa ftoa
buffer buffer
xml2
) )
SET(_opencollada_SEARCH_DIRS SET(_opencollada_SEARCH_DIRS
@ -104,6 +106,25 @@ FOREACH(COMPONENT ${_opencollada_FIND_COMPONENTS})
LIST(APPEND _opencollada_LIBRARIES "${OPENCOLLADA_${UPPERCOMPONENT}_LIBRARY}") LIST(APPEND _opencollada_LIBRARIES "${OPENCOLLADA_${UPPERCOMPONENT}_LIBRARY}")
ENDFOREACH() ENDFOREACH()
FOREACH(COMPONENT ${_opencollada_FIND_STATIC_COMPONENTS})
STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
FIND_LIBRARY(OPENCOLLADA_${UPPERCOMPONENT}_LIBRARY
NAMES
${COMPONENT}
HINTS
${_opencollada_SEARCH_DIRS}
PATH_SUFFIXES
lib64 lib
# Ubuntu ppa needs this.
lib64/opencollada lib/opencollada
)
IF(OPENCOLLADA_${UPPERCOMPONENT}_LIBRARY)
MARK_AS_ADVANCED(OPENCOLLADA_${UPPERCOMPONENT}_LIBRARY)
LIST(APPEND _opencollada_LIBRARIES "${OPENCOLLADA_${UPPERCOMPONENT}_LIBRARY}")
ENDIF()
ENDFOREACH()
# handle the QUIETLY and REQUIRED arguments and set OPENCOLLADA_FOUND to TRUE if # handle the QUIETLY and REQUIRED arguments and set OPENCOLLADA_FOUND to TRUE if
# all listed variables are TRUE # all listed variables are TRUE

@ -0,0 +1,43 @@
# - Try to find the PCRE regular expression library
# Once done this will define
#
# PCRE_FOUND - system has the PCRE library
# PCRE_INCLUDE_DIR - the PCRE include directory
# PCRE_LIBRARIES - The libraries needed to use PCRE
# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
if (PCRE_INCLUDE_DIR AND PCRE_PCREPOSIX_LIBRARY AND PCRE_PCRE_LIBRARY)
# Already in cache, be silent
set(PCRE_FIND_QUIETLY TRUE)
endif (PCRE_INCLUDE_DIR AND PCRE_PCREPOSIX_LIBRARY AND PCRE_PCRE_LIBRARY)
if (NOT WIN32)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
find_package(PkgConfig)
pkg_check_modules(PC_PCRE QUIET libpcre)
set(PCRE_DEFINITIONS ${PC_PCRE_CFLAGS_OTHER})
endif (NOT WIN32)
find_path(PCRE_INCLUDE_DIR pcre.h
HINTS ${PC_PCRE_INCLUDEDIR} ${PC_PCRE_INCLUDE_DIRS}
PATH_SUFFIXES pcre)
find_library(PCRE_PCRE_LIBRARY NAMES pcre HINTS ${PC_PCRE_LIBDIR} ${PC_PCRE_LIBRARY_DIRS})
find_library(PCRE_PCREPOSIX_LIBRARY NAMES pcreposix HINTS ${PC_PCRE_LIBDIR} ${PC_PCRE_LIBRARY_DIRS})
include(FindPackageHandleStandardArgs)
IF(NOT WIN32)
find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_INCLUDE_DIR PCRE_PCRE_LIBRARY PCRE_PCREPOSIX_LIBRARY )
mark_as_advanced(PCRE_INCLUDE_DIR PCRE_LIBRARIES PCRE_PCREPOSIX_LIBRARY PCRE_PCRE_LIBRARY)
set(PCRE_LIBRARIES ${PCRE_PCRE_LIBRARY} ${PCRE_PCREPOSIX_LIBRARY})
ELSE()
find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_INCLUDE_DIR PCRE_PCRE_LIBRARY )
set(PCRE_LIBRARIES ${PCRE_PCRE_LIBRARY} )
mark_as_advanced(PCRE_INCLUDE_DIR PCRE_LIBRARIES PCRE_PCRE_LIBRARY)
ENDIF()

@ -0,0 +1,88 @@
# - Try to find XML2
# Once done this will define
#
# XML2_FOUND - system has XML2
# XML2_INCLUDE_DIRS - the XML2 include directory
# XML2_LIBRARIES - Link these to use XML2
# XML2_DEFINITIONS - Compiler switches required for using XML2
#
# Copyright (c) 2008 Andreas Schneider <mail@cynapses.org>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
#
if (XML2_LIBRARIES AND XML2_INCLUDE_DIRS)
# in cache already
set(XML2_FOUND TRUE)
else (XML2_LIBRARIES AND XML2_INCLUDE_DIRS)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
include(UsePkgConfig)
pkgconfig(libxml-2.0 _XML2_INCLUDEDIR _XML2_LIBDIR _XML2_LDFLAGS _XML2_CFLAGS)
else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_XML2 libxml-2.0)
endif (PKG_CONFIG_FOUND)
endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
find_path(XML2_INCLUDE_DIR
NAMES
libxml/xpath.h
PATHS
${_XML2_INCLUDEDIR}
/usr/include
/usr/local/include
/opt/local/include
/sw/include
PATH_SUFFIXES
libxml2
)
find_library(XML2_LIBRARY
NAMES
xml2
PATHS
${_XML2_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
if (XML2_LIBRARY)
set(XML2_FOUND TRUE)
endif (XML2_LIBRARY)
set(XML2_INCLUDE_DIRS
${XML2_INCLUDE_DIR}
)
if (XML2_FOUND)
set(XML2_LIBRARIES
${XML2_LIBRARIES}
${XML2_LIBRARY}
)
endif (XML2_FOUND)
if (XML2_INCLUDE_DIRS AND XML2_LIBRARIES)
set(XML2_FOUND TRUE)
endif (XML2_INCLUDE_DIRS AND XML2_LIBRARIES)
if (XML2_FOUND)
if (NOT XML2_FIND_QUIETLY)
message(STATUS "Found XML2: ${XML2_LIBRARIES}")
endif (NOT XML2_FIND_QUIETLY)
else (XML2_FOUND)
if (XML2_FIND_REQUIRED)
message(FATAL_ERROR "Could not find XML2")
endif (XML2_FIND_REQUIRED)
endif (XML2_FOUND)
# show the XML2_INCLUDE_DIRS and XML2_LIBRARIES variables only in the advanced view
mark_as_advanced(XML2_INCLUDE_DIRS XML2_LIBRARIES)
endif (XML2_LIBRARIES AND XML2_INCLUDE_DIRS)

@ -392,6 +392,7 @@ macro(remove_strict_flags)
remove_flag("-Wstrict-prototypes") remove_flag("-Wstrict-prototypes")
remove_flag("-Wunused-parameter") remove_flag("-Wunused-parameter")
remove_flag("-Wwrite-strings") remove_flag("-Wwrite-strings")
remove_flag("-Wundef")
remove_flag("-Wshadow") remove_flag("-Wshadow")
remove_flag("-Werror=[^ ]+") remove_flag("-Werror=[^ ]+")
remove_flag("-Werror") remove_flag("-Werror")

@ -14,7 +14,7 @@ USE_SDK=True
################### Cocoa & architecture settings ################## ################### Cocoa & architecture settings ##################
############################################################################# #############################################################################
WITH_GHOST_COCOA=True WITH_GHOST_COCOA=True
MACOSX_ARCHITECTURE = 'x86_64' # valid archs: ppc, i386, ppc64, x86_64 MACOSX_ARCHITECTURE = 'i386' # valid archs: ppc, i386, ppc64, x86_64
cmd = 'uname -p' cmd = 'uname -p'

@ -127,6 +127,7 @@ WITH_BF_BINRELOC = False
WITH_BF_FFMPEG = True # -DWITH_FFMPEG WITH_BF_FFMPEG = True # -DWITH_FFMPEG
BF_FFMPEG = LIBDIR + '/ffmpeg' BF_FFMPEG = LIBDIR + '/ffmpeg'
BF_FFMPEG_LIB = 'avformat-53 avcodec-53 avdevice-53 avutil-51 swscale-2' BF_FFMPEG_LIB = 'avformat-53 avcodec-53 avdevice-53 avutil-51 swscale-2'
BF_FFMPEG_DLL = '${BF_FFMPEG_LIBPATH}/avformat-53.dll ${BF_FFMPEG_LIBPATH}/avcodec-53.dll ${BF_FFMPEG_LIBPATH}/avdevice-53.dll ${BF_FFMPEG_LIBPATH}/avutil-51.dll ${BF_FFMPEG_LIBPATH}/swscale-2.dll'
BF_FFMPEG_INC = '${BF_FFMPEG}/include' BF_FFMPEG_INC = '${BF_FFMPEG}/include'
BF_FFMPEG_LIBPATH = '${BF_FFMPEG}/lib' BF_FFMPEG_LIBPATH = '${BF_FFMPEG}/lib'
BF_FFMPEG_DLL = '${BF_FFMPEG_LIBPATH}/avformat-53.dll ${BF_FFMPEG_LIBPATH}/avcodec-53.dll ${BF_FFMPEG_LIBPATH}/avdevice-53.dll ${BF_FFMPEG_LIBPATH}/avutil-51.dll ${BF_FFMPEG_LIBPATH}/swscale-2.dll' BF_FFMPEG_DLL = '${BF_FFMPEG_LIBPATH}/avformat-53.dll ${BF_FFMPEG_LIBPATH}/avcodec-53.dll ${BF_FFMPEG_LIBPATH}/avdevice-53.dll ${BF_FFMPEG_LIBPATH}/avutil-51.dll ${BF_FFMPEG_LIBPATH}/swscale-2.dll'

@ -174,7 +174,7 @@ C_WARN = ['-Wno-char-subscripts', '-Wdeclaration-after-statement', '-Wstrict-pro
CC_WARN = [ '-Wall' ] CC_WARN = [ '-Wall' ]
LLIBS = ['-lshell32', '-lshfolder', '-lgdi32', '-lmsvcrt', '-lwinmm', '-lmingw32', '-lm', '-lws2_32', '-lz', '-lstdc++','-lole32','-luuid'] LLIBS = ['-lshell32', '-lshfolder', '-lgdi32', '-lmsvcrt', '-lwinmm', '-lmingw32', '-lm', '-lws2_32', '-lz', '-lstdc++','-lole32','-luuid', '-lwsock32']
PLATFORM_LINKFLAGS = ['--stack,2097152'] PLATFORM_LINKFLAGS = ['--stack,2097152']

@ -14,7 +14,7 @@ def createTexture(cont):
object = cont.owner object = cont.owner
# get the reference pointer (ID) of the internal texture # get the reference pointer (ID) of the internal texture
ID = texture.materialID(obj, 'IMoriginal.png') ID = texture.materialID(object, 'IMoriginal.png')
# create a texture object # create a texture object
object_texture = texture.Texture(object, ID) object_texture = texture.Texture(object, ID)

@ -21,7 +21,7 @@ class HelloWorldOperator(bpy.types.Operator):
print("Hello World") print("Hello World")
return {'FINISHED'} return {'FINISHED'}
bpy.utils.register_class(SimpleOperator) bpy.utils.register_class(HelloWorldOperator)
# test call to the newly defined operator # test call to the newly defined operator
bpy.ops.wm.hello_world() bpy.ops.wm.hello_world()

@ -56,9 +56,9 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type n: int :type n: int
:arg n: Specifies the number of textures to be queried. :arg n: Specifies the number of textures to be queried.
:type textures: :class:`Buffer` object I{type GL_INT} :type textures: :class:`bgl.Buffer` object I{type GL_INT}
:arg textures: Specifies an array containing the names of the textures to be queried :arg textures: Specifies an array containing the names of the textures to be queried
:type residences: :class:`Buffer` object I{type GL_INT}(boolean) :type residences: :class:`bgl.Buffer` object I{type GL_INT}(boolean)
:arg residences: An array in which the texture residence status in returned. :arg residences: An array in which the texture residence status in returned.
The residence status of a texture named by an element of textures is The residence status of a texture named by an element of textures is
returned in the corresponding element of residences. returned in the corresponding element of residences.
@ -101,7 +101,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type xmove, ymove: float :type xmove, ymove: float
:arg xmove, ymove: Specify the x and y offsets to be added to the current raster position after :arg xmove, ymove: Specify the x and y offsets to be added to the current raster position after
the bitmap is drawn. the bitmap is drawn.
:type bitmap: :class:`Buffer` object I{type GL_BYTE} :type bitmap: :class:`bgl.Buffer` object I{type GL_BYTE}
:arg bitmap: Specifies the address of the bitmap image. :arg bitmap: Specifies the address of the bitmap image.
@ -139,7 +139,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg n: Specifies the number of display lists to be executed. :arg n: Specifies the number of display lists to be executed.
:type type: Enumerated constant :type type: Enumerated constant
:arg type: Specifies the type of values in lists. :arg type: Specifies the type of values in lists.
:type lists: :class:`Buffer` object :type lists: :class:`bgl.Buffer` object
:arg lists: Specifies the address of an array of name offsets in the display list. :arg lists: Specifies the address of an array of name offsets in the display list.
The pointer type is void because the offsets can be bytes, shorts, ints, or floats, The pointer type is void because the offsets can be bytes, shorts, ints, or floats,
depending on the value of type. depending on the value of type.
@ -217,7 +217,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type plane: Enumerated constant :type plane: Enumerated constant
:arg plane: Specifies which clipping plane is being positioned. :arg plane: Specifies which clipping plane is being positioned.
:type equation: :class:`Buffer` object I{type GL_FLOAT}(double) :type equation: :class:`bgl.Buffer` object I{type GL_FLOAT}(double)
:arg equation: Specifies the address of an array of four double- precision :arg equation: Specifies the address of an array of four double- precision
floating-point values. These values are interpreted as a plane equation. floating-point values. These values are interpreted as a plane equation.
@ -340,7 +340,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type n: int :type n: int
:arg n: Specifies the number of textures to be deleted :arg n: Specifies the number of textures to be deleted
:type textures: :class:`Buffer` I{GL_INT} :type textures: :class:`bgl.Buffer` I{GL_INT}
:arg textures: Specifies an array of textures to be deleted :arg textures: Specifies an array of textures to be deleted
@ -413,7 +413,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg format: Specifies the format of the pixel data. :arg format: Specifies the format of the pixel data.
:type type: Enumerated constant :type type: Enumerated constant
:arg type: Specifies the data type for pixels. :arg type: Specifies the data type for pixels.
:type pixels: :class:`Buffer` object :type pixels: :class:`bgl.Buffer` object
:arg pixels: Specifies a pointer to the pixel data. :arg pixels: Specifies a pointer to the pixel data.
@ -512,7 +512,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type type: Enumerated constant :type type: Enumerated constant
:arg type: Specifies a symbolic constant that describes the information that :arg type: Specifies a symbolic constant that describes the information that
will be returned for each vertex. will be returned for each vertex.
:type buffer: :class:`Buffer` object I{GL_FLOAT} :type buffer: :class:`bgl.Buffer` object I{GL_FLOAT}
:arg buffer: Returns the feedback data. :arg buffer: Returns the feedback data.
@ -592,7 +592,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type n: int :type n: int
:arg n: Specifies the number of textures name to be generated. :arg n: Specifies the number of textures name to be generated.
:type textures: :class:`Buffer` object I{type GL_INT} :type textures: :class:`bgl.Buffer` object I{type GL_INT}
:arg textures: Specifies an array in which the generated textures names are stored. :arg textures: Specifies an array in which the generated textures names are stored.
@ -620,7 +620,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg plane: Specifies a clipping plane. The number of clipping planes depends on the :arg plane: Specifies a clipping plane. The number of clipping planes depends on the
implementation, but at least six clipping planes are supported. They are identified by implementation, but at least six clipping planes are supported. They are identified by
symbolic names of the form GL_CLIP_PLANEi where 0 < i < GL_MAX_CLIP_PLANES. symbolic names of the form GL_CLIP_PLANEi where 0 < i < GL_MAX_CLIP_PLANES.
:type equation: :class:`Buffer` object I{type GL_FLOAT} :type equation: :class:`bgl.Buffer` object I{type GL_FLOAT}
:arg equation: Returns four float (double)-precision values that are the coefficients of the :arg equation: Returns four float (double)-precision values that are the coefficients of the
plane equation of plane in eye coordinates. The initial value is (0, 0, 0, 0). plane equation of plane in eye coordinates. The initial value is (0, 0, 0, 0).
@ -646,7 +646,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
names of the form GL_LIGHTi where 0 < i < GL_MAX_LIGHTS. names of the form GL_LIGHTi where 0 < i < GL_MAX_LIGHTS.
:type pname: Enumerated constant :type pname: Enumerated constant
:arg pname: Specifies a light source parameter for light. :arg pname: Specifies a light source parameter for light.
:type params: :class:`Buffer` object. Depends on function prototype. :type params: :class:`bgl.Buffer` object. Depends on function prototype.
:arg params: Returns the requested data. :arg params: Returns the requested data.
@ -662,7 +662,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg target: Specifies the symbolic name of a map. :arg target: Specifies the symbolic name of a map.
:type query: Enumerated constant :type query: Enumerated constant
:arg query: Specifies which parameter to return. :arg query: Specifies which parameter to return.
:type v: :class:`Buffer` object. Depends on function prototype. :type v: :class:`bgl.Buffer` object. Depends on function prototype.
:arg v: Returns the requested data. :arg v: Returns the requested data.
@ -679,7 +679,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
representing the front and back materials, respectively. representing the front and back materials, respectively.
:type pname: Enumerated constant :type pname: Enumerated constant
:arg pname: Specifies the material parameter to return. :arg pname: Specifies the material parameter to return.
:type params: :class:`Buffer` object. Depends on function prototype. :type params: :class:`bgl.Buffer` object. Depends on function prototype.
:arg params: Returns the requested data. :arg params: Returns the requested data.
@ -693,7 +693,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type map: Enumerated constant :type map: Enumerated constant
:arg map: Specifies the name of the pixel map to return. :arg map: Specifies the name of the pixel map to return.
:type values: :class:`Buffer` object. Depends on function prototype. :type values: :class:`bgl.Buffer` object. Depends on function prototype.
:arg values: Returns the pixel map contents. :arg values: Returns the pixel map contents.
@ -703,7 +703,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
.. seealso:: `OpenGL Docs <http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/getpolygonstipple.html>`_ .. seealso:: `OpenGL Docs <http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/getpolygonstipple.html>`_
:type mask: :class:`Buffer` object I{type GL_BYTE} :type mask: :class:`bgl.Buffer` object I{type GL_BYTE}
:arg mask: Returns the stipple pattern. The initial value is all 1's. :arg mask: Returns the stipple pattern. The initial value is all 1's.
@ -730,7 +730,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg target: Specifies a texture environment. Must be GL_TEXTURE_ENV. :arg target: Specifies a texture environment. Must be GL_TEXTURE_ENV.
:type pname: Enumerated constant :type pname: Enumerated constant
:arg pname: Specifies the symbolic name of a texture environment parameter. :arg pname: Specifies the symbolic name of a texture environment parameter.
:type params: :class:`Buffer` object. Depends on function prototype. :type params: :class:`bgl.Buffer` object. Depends on function prototype.
:arg params: Returns the requested data. :arg params: Returns the requested data.
@ -746,7 +746,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg coord: Specifies a texture coordinate. :arg coord: Specifies a texture coordinate.
:type pname: Enumerated constant :type pname: Enumerated constant
:arg pname: Specifies the symbolic name of the value(s) to be returned. :arg pname: Specifies the symbolic name of the value(s) to be returned.
:type params: :class:`Buffer` object. Depends on function prototype. :type params: :class:`bgl.Buffer` object. Depends on function prototype.
:arg params: Returns the requested data. :arg params: Returns the requested data.
@ -765,7 +765,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg format: Specifies a pixel format for the returned data. :arg format: Specifies a pixel format for the returned data.
:type type: Enumerated constant :type type: Enumerated constant
:arg type: Specifies a pixel type for the returned data. :arg type: Specifies a pixel type for the returned data.
:type pixels: :class:`Buffer` object. :type pixels: :class:`bgl.Buffer` object.
:arg pixels: Returns the texture image. Should be a pointer to an array of the :arg pixels: Returns the texture image. Should be a pointer to an array of the
type specified by type type specified by type
@ -785,7 +785,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
Level 0 is the base image level. Level n is the nth mipmap reduction image. Level 0 is the base image level. Level n is the nth mipmap reduction image.
:type pname: Enumerated constant :type pname: Enumerated constant
:arg pname: Specifies the symbolic name of a texture parameter. :arg pname: Specifies the symbolic name of a texture parameter.
:type params: :class:`Buffer` object. Depends on function prototype. :type params: :class:`bgl.Buffer` object. Depends on function prototype.
:arg params: Returns the requested data. :arg params: Returns the requested data.
@ -801,7 +801,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg target: Specifies the symbolic name of the target texture. :arg target: Specifies the symbolic name of the target texture.
:type pname: Enumerated constant :type pname: Enumerated constant
:arg pname: Specifies the symbolic name the target texture. :arg pname: Specifies the symbolic name the target texture.
:type params: :class:`Buffer` object. Depends on function prototype. :type params: :class:`bgl.Buffer` object. Depends on function prototype.
:arg params: Returns the texture parameters. :arg params: Returns the texture parameters.
@ -826,7 +826,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
.. seealso:: `OpenGL Docs <http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/index_.html>`_ .. seealso:: `OpenGL Docs <http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/index_.html>`_
:type c: :class:`Buffer` object. Depends on function prototype. :type c: :class:`bgl.Buffer` object. Depends on function prototype.
:arg c: Specifies a pointer to a one element array that contains the new value for :arg c: Specifies a pointer to a one element array that contains the new value for
the current color index. the current color index.
@ -956,7 +956,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
.. seealso:: `OpenGL Docs <http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/loadmatrix.html>`_ .. seealso:: `OpenGL Docs <http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/loadmatrix.html>`_
:type m: :class:`Buffer` object. Depends on function prototype. :type m: :class:`bgl.Buffer` object. Depends on function prototype.
:arg m: Specifies a pointer to 16 consecutive values, which are used as the elements :arg m: Specifies a pointer to 16 consecutive values, which are used as the elements
of a 4x4 column-major matrix. of a 4x4 column-major matrix.
@ -1002,7 +1002,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
occupy contiguous memory locations. occupy contiguous memory locations.
:type order: int :type order: int
:arg order: Specifies the number of control points. Must be positive. :arg order: Specifies the number of control points. Must be positive.
:type points: :class:`Buffer` object. Depends on function prototype. :type points: :class:`bgl.Buffer` object. Depends on function prototype.
:arg points: Specifies a pointer to the array of control points. :arg points: Specifies a pointer to the array of control points.
@ -1043,7 +1043,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type vorder: int :type vorder: int
:arg vorder: Specifies the dimension of the control point array in the v axis. :arg vorder: Specifies the dimension of the control point array in the v axis.
Must be positive. The initial value is 1. Must be positive. The initial value is 1.
:type points: :class:`Buffer` object. Depends on function prototype. :type points: :class:`bgl.Buffer` object. Depends on function prototype.
:arg points: Specifies a pointer to the array of control points. :arg points: Specifies a pointer to the array of control points.
@ -1103,7 +1103,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
.. seealso:: `OpenGL Docs <http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/multmatrix.html>`_ .. seealso:: `OpenGL Docs <http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/multmatrix.html>`_
:type m: :class:`Buffer` object. Depends on function prototype. :type m: :class:`bgl.Buffer` object. Depends on function prototype.
:arg m: Points to 16 consecutive values that are used as the elements of a 4x4 column :arg m: Points to 16 consecutive values that are used as the elements of a 4x4 column
major matrix. major matrix.
@ -1132,7 +1132,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type nx, ny, nz: Depends on function prototype. (non - 'v' prototypes only) :type nx, ny, nz: Depends on function prototype. (non - 'v' prototypes only)
:arg nx, ny, nz: Specify the x, y, and z coordinates of the new current normal. :arg nx, ny, nz: Specify the x, y, and z coordinates of the new current normal.
The initial value of the current normal is the unit vector, (0, 0, 1). The initial value of the current normal is the unit vector, (0, 0, 1).
:type v: :class:`Buffer` object. Depends on function prototype. ('v' prototypes) :type v: :class:`bgl.Buffer` object. Depends on function prototype. ('v' prototypes)
:arg v: Specifies a pointer to an array of three elements: the x, y, and z coordinates :arg v: Specifies a pointer to an array of three elements: the x, y, and z coordinates
of the new current normal. of the new current normal.
@ -1177,7 +1177,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg map: Specifies a symbolic map name. :arg map: Specifies a symbolic map name.
:type mapsize: int :type mapsize: int
:arg mapsize: Specifies the size of the map being defined. :arg mapsize: Specifies the size of the map being defined.
:type values: :class:`Buffer` object. Depends on function prototype. :type values: :class:`bgl.Buffer` object. Depends on function prototype.
:arg values: Specifies an array of mapsize values. :arg values: Specifies an array of mapsize values.
@ -1266,7 +1266,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
.. seealso:: `OpenGL Docs <http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/polygonstipple.html>`_ .. seealso:: `OpenGL Docs <http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/polygonstipple.html>`_
:type mask: :class:`Buffer` object I{type GL_BYTE} :type mask: :class:`bgl.Buffer` object I{type GL_BYTE}
:arg mask: Specifies a pointer to a 32x32 stipple pattern that will be unpacked :arg mask: Specifies a pointer to a 32x32 stipple pattern that will be unpacked
from memory in the same way that glDrawPixels unpacks pixels. from memory in the same way that glDrawPixels unpacks pixels.
@ -1307,9 +1307,9 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type n: int :type n: int
:arg n: Specifies the number of textures to be prioritized. :arg n: Specifies the number of textures to be prioritized.
:type textures: :class:`Buffer` I{type GL_INT} :type textures: :class:`bgl.Buffer` I{type GL_INT}
:arg textures: Specifies an array containing the names of the textures to be prioritized. :arg textures: Specifies an array containing the names of the textures to be prioritized.
:type priorities: :class:`Buffer` I{type GL_FLOAT} :type priorities: :class:`bgl.Buffer` I{type GL_FLOAT}
:arg priorities: Specifies an array containing the texture priorities. :arg priorities: Specifies an array containing the texture priorities.
A priority given in an element of priorities applies to the texture named A priority given in an element of priorities applies to the texture named
by the corresponding element of textures. by the corresponding element of textures.
@ -1417,7 +1417,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg format: Specifies the format of the pixel data. :arg format: Specifies the format of the pixel data.
:type type: Enumerated constant :type type: Enumerated constant
:arg type: Specifies the data type of the pixel data. :arg type: Specifies the data type of the pixel data.
:type pixels: :class:`Buffer` object :type pixels: :class:`bgl.Buffer` object
:arg pixels: Returns the pixel data. :arg pixels: Returns the pixel data.
@ -1496,7 +1496,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type size: int :type size: int
:arg size: Specifies the size of buffer :arg size: Specifies the size of buffer
:type buffer: :class:`Buffer` I{type GL_INT} :type buffer: :class:`bgl.Buffer` I{type GL_INT}
:arg buffer: Returns the selection data :arg buffer: Returns the selection data
@ -1575,7 +1575,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type s, t, r, q: Depends on function prototype. (r and q for '3' and '4' prototypes only) :type s, t, r, q: Depends on function prototype. (r and q for '3' and '4' prototypes only)
:arg s, t, r, q: Specify s, t, r, and q texture coordinates. Not all parameters are :arg s, t, r, q: Specify s, t, r, and q texture coordinates. Not all parameters are
present in all forms of the command. present in all forms of the command.
:type v: :class:`Buffer` object. Depends on function prototype. (for 'v' prototypes only) :type v: :class:`bgl.Buffer` object. Depends on function prototype. (for 'v' prototypes only)
:arg v: Specifies a pointer to an array of one, two, three, or four elements, :arg v: Specifies a pointer to an array of one, two, three, or four elements,
which in turn specify the s, t, r, and q texture coordinates. which in turn specify the s, t, r, and q texture coordinates.
@ -1642,7 +1642,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg format: Specifies the format of the pixel data. :arg format: Specifies the format of the pixel data.
:type type: Enumerated constant :type type: Enumerated constant
:arg type: Specifies the data type of the pixel data. :arg type: Specifies the data type of the pixel data.
:type pixels: :class:`Buffer` object. :type pixels: :class:`bgl.Buffer` object.
:arg pixels: Specifies a pointer to the image data in memory. :arg pixels: Specifies a pointer to the image data in memory.
@ -1673,7 +1673,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg format: Specifies the format of the pixel data. :arg format: Specifies the format of the pixel data.
:type type: Enumerated constant :type type: Enumerated constant
:arg type: Specifies the data type of the pixel data. :arg type: Specifies the data type of the pixel data.
:type pixels: :class:`Buffer` object. :type pixels: :class:`bgl.Buffer` object.
:arg pixels: Specifies a pointer to the image data in memory. :arg pixels: Specifies a pointer to the image data in memory.
@ -1720,7 +1720,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type x, y, z, w: Depends on function prototype (z and w for '3' and '4' prototypes only) :type x, y, z, w: Depends on function prototype (z and w for '3' and '4' prototypes only)
:arg x, y, z, w: Specify x, y, z, and w coordinates of a vertex. Not all parameters :arg x, y, z, w: Specify x, y, z, and w coordinates of a vertex. Not all parameters
are present in all forms of the command. are present in all forms of the command.
:type v: :class:`Buffer` object. Depends of function prototype (for 'v' :type v: :class:`bgl.Buffer` object. Depends of function prototype (for 'v'
prototypes only) prototypes only)
:arg v: Specifies a pointer to an array of two, three, or four elements. The :arg v: Specifies a pointer to an array of two, three, or four elements. The
elements of a two-element array are x and y; of a three-element array, elements of a two-element array are x and y; of a three-element array,
@ -1795,7 +1795,7 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:arg x, y: Specify the center of a picking region in window coordinates. :arg x, y: Specify the center of a picking region in window coordinates.
:type width, height: double :type width, height: double
:arg width, height: Specify the width and height, respectively, of the picking region in window coordinates. :arg width, height: Specify the width and height, respectively, of the picking region in window coordinates.
:type viewport: :class:`Buffer` object. [int] :type viewport: :class:`bgl.Buffer` object. [int]
:arg viewport: Specifies the current viewport. :arg viewport: Specifies the current viewport.
@ -1807,13 +1807,13 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type objx, objy, objz: double :type objx, objy, objz: double
:arg objx, objy, objz: Specify the object coordinates. :arg objx, objy, objz: Specify the object coordinates.
:type modelMatrix: :class:`Buffer` object. [double] :type modelMatrix: :class:`bgl.Buffer` object. [double]
:arg modelMatrix: Specifies the current modelview matrix (as from a glGetDoublev call). :arg modelMatrix: Specifies the current modelview matrix (as from a glGetDoublev call).
:type projMatrix: :class:`Buffer` object. [double] :type projMatrix: :class:`bgl.Buffer` object. [double]
:arg projMatrix: Specifies the current projection matrix (as from a glGetDoublev call). :arg projMatrix: Specifies the current projection matrix (as from a glGetDoublev call).
:type viewport: :class:`Buffer` object. [int] :type viewport: :class:`bgl.Buffer` object. [int]
:arg viewport: Specifies the current viewport (as from a glGetIntegerv call). :arg viewport: Specifies the current viewport (as from a glGetIntegerv call).
:type winx, winy, winz: :class:`Buffer` object. [double] :type winx, winy, winz: :class:`bgl.Buffer` object. [double]
:arg winx, winy, winz: Return the computed window coordinates. :arg winx, winy, winz: Return the computed window coordinates.
@ -1825,13 +1825,13 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
:type winx, winy, winz: double :type winx, winy, winz: double
:arg winx, winy, winz: Specify the window coordinates to be mapped. :arg winx, winy, winz: Specify the window coordinates to be mapped.
:type modelMatrix: :class:`Buffer` object. [double] :type modelMatrix: :class:`bgl.Buffer` object. [double]
:arg modelMatrix: Specifies the current modelview matrix (as from a glGetDoublev call). :arg modelMatrix: Specifies the current modelview matrix (as from a glGetDoublev call).
:type projMatrix: :class:`Buffer` object. [double] :type projMatrix: :class:`bgl.Buffer` object. [double]
:arg projMatrix: Specifies the current projection matrix (as from a glGetDoublev call). :arg projMatrix: Specifies the current projection matrix (as from a glGetDoublev call).
:type viewport: :class:`Buffer` object. [int] :type viewport: :class:`bgl.Buffer` object. [int]
:arg viewport: Specifies the current viewport (as from a glGetIntegerv call). :arg viewport: Specifies the current viewport (as from a glGetIntegerv call).
:type objx, objy, objz: :class:`Buffer` object. [double] :type objx, objy, objz: :class:`bgl.Buffer` object. [double]
:arg objx, objy, objz: Return the computed object coordinates. :arg objx, objy, objz: Return the computed object coordinates.

531
doc/python_api/rst/gpu.rst Normal file

@ -0,0 +1,531 @@
GPU functions (gpu)
===================
*****
Intro
*****
Module to provide functions concerning the GPU implementation in Blender, in particular
the GLSL shaders that blender generates automatically to render materials in the 3D view
and in the game engine.
.. warning::
The API provided by this module should be consider unstable. The data exposed by the API
are are closely related to Blender's internal GLSL code and may change if the GLSL code
is modified (e.g. new uniform type).
.. module:: gpu
*********
Constants
*********
--------------
GLSL data type
--------------
.. _data-type:
Type of GLSL data.
For shader uniforms, the data type determines which glUniform function
variant to use to send the uniform value to the GPU.
For vertex attributes, the data type determines which glVertexAttrib function
variant to use to send the vertex attribute to the GPU.
See export_shader_
.. data:: GPU_DATA_1I
one integer
:value: 1
.. data:: GPU_DATA_1F
one float
:value: 2
.. data:: GPU_DATA_2F
two floats
:value: 3
.. data:: GPU_DATA_3F
three floats
:value: 4
.. data:: GPU_DATA_4F
four floats
:value: 5
.. data:: GPU_DATA_9F
matrix 3x3 in column-major order
:value: 6
.. data:: GPU_DATA_16F
matrix 4x4 in column-major order
:value: 7
.. data:: GPU_DATA_4UB
four unsigned byte
:value: 8
-----------------
GLSL uniform type
-----------------
.. _uniform-type:
Constants that specify the type of uniform used in a GLSL shader.
The uniform type determines the data type, origin and method
of calculation used by Blender to compute the uniform value.
The calculation of some of the uniforms is based on matrices available in the scene:
.. _mat4_cam_to_world:
.. _mat4_world_to_cam:
*mat4_cam_to_world*
Model matrix of the camera. OpenGL 4x4 matrix that converts
camera local coordinates to world coordinates. In blender this is obtained from the
'matrix_world' attribute of the camera object.
Some uniform will need the *mat4_world_to_cam*
matrix computed as the inverse of this matrix.
.. _mat4_object_to_world:
.. _mat4_world_to_object:
*mat4_object_to_world*
Model matrix of the object that is being rendered. OpenGL 4x4 matric that converts
object local coordinates to world coordinates. In blender this is obtained from the
'matrix_world' attribute of the object.
Some uniform will need the *mat4_world_to_object* matrix, computed as the inverse of this matrix.
.. _mat4_lamp_to_world:
.. _mat4_world_to_lamp:
*mat4_lamp_to_world*
Model matrix of the lamp lighting the object. OpenGL 4x4 matrix that converts lamp
local coordinates to world coordinates. In blender this is obtained from the
'matrix_world' attribute of the lamp object.
Some uniform will need the *mat4_world_to_lamp* matrix
computed as the inverse of this matrix.
.. data:: GPU_DYNAMIC_OBJECT_VIEWMAT
The uniform is a 4x4 GL matrix that converts world coordinates to
camera coordinates (see mat4_world_to_cam_). Can be set once per frame.
There is at most one uniform of that type per shader.
:value: 1
.. data:: GPU_DYNAMIC_OBJECT_MAT
The uniform is a 4x4 GL matrix that converts object coordinates
to world coordinates (see mat4_object_to_world_). Must be set before drawing the object.
There is at most one uniform of that type per shader.
:value: 2
.. data:: GPU_DYNAMIC_OBJECT_VIEWIMAT
The uniform is a 4x4 GL matrix that converts coordinates
in camera space to world coordinates (see mat4_cam_to_world_).
Can be set once per frame.
There is at most one uniform of that type per shader.
:value: 3
.. data:: GPU_DYNAMIC_OBJECT_IMAT
The uniform is a 4x4 GL matrix that converts world coodinates
to object coordinates (see mat4_world_to_object_).
Must be set before drawing the object.
There is at most one uniform of that type per shader.
:value: 4
.. data:: GPU_DYNAMIC_OBJECT_COLOR
The uniform is a vector of 4 float representing a RGB color + alpha defined at object level.
Each values between 0.0 and 1.0. In blender it corresponds to the 'color' attribute of the object.
Must be set before drawing the object.
There is at most one uniform of that type per shader.
:value: 5
.. data:: GPU_DYNAMIC_LAMP_DYNVEC
The uniform is a vector of 3 float representing the direction of light in camera space.
In Blender, this is computed by
mat4_world_to_cam_ * (-vec3_lamp_Z_axis)
as the lamp Z axis points to the opposite direction of light.
The norm of the vector should be unity. Can be set once per frame.
There is one uniform of that type per lamp lighting the material.
:value: 6
.. data:: GPU_DYNAMIC_LAMP_DYNCO
The uniform is a vector of 3 float representing the position of the light in camera space.
Computed as
mat4_world_to_cam_ * vec3_lamp_pos
Can be set once per frame.
There is one uniform of that type per lamp lighting the material.
:value: 7
.. data:: GPU_DYNAMIC_LAMP_DYNIMAT
The uniform is a 4x4 GL matrix that converts vector in camera space to lamp space.
Computed as
mat4_world_to_lamp_ * mat4_cam_to_world_
Can be set once per frame.
There is one uniform of that type per lamp lighting the material.
:value: 8
.. data:: GPU_DYNAMIC_LAMP_DYNPERSMAT
The uniform is a 4x4 GL matrix that converts a vector in camera space to shadow buffer depth space.
Computed as
mat4_perspective_to_depth_ * mat4_lamp_to_perspective_ * mat4_world_to_lamp_ * mat4_cam_to_world_.
.. _mat4_perspective_to_depth:
*mat4_perspective_to_depth* is a fixed matrix defined as follow::
0.5 0.0 0.0 0.5
0.0 0.5 0.0 0.5
0.0 0.0 0.5 0.5
0.0 0.0 0.0 1.0
This uniform can be set once per frame. There is one uniform of that type per lamp casting shadow in the scene.
:value: 9
.. data:: GPU_DYNAMIC_LAMP_DYNENERGY
The uniform is a single float representing the lamp energy. In blender it corresponds
to the 'energy' attribute of the lamp data block.
There is one uniform of that type per lamp lighting the material.
:value: 10
.. data:: GPU_DYNAMIC_LAMP_DYNCOL
The uniform is a vector of 3 float representing the lamp color.
Color elements are between 0.0 and 1.0. In blender it corresponds
to the 'color' attribute of the lamp data block.
There is one uniform of that type per lamp lighting the material.
:value: 11
.. data:: GPU_DYNAMIC_SAMPLER_2DBUFFER
The uniform is an integer representing an internal texture used for certain effect
(color band, etc).
:value: 12
.. data:: GPU_DYNAMIC_SAMPLER_2DIMAGE
The uniform is an integer representing a texture loaded from an image file.
:value: 13
.. data:: GPU_DYNAMIC_SAMPLER_2DSHADOW
The uniform is an integer representing a shadow buffer corresponding to a lamp
casting shadow.
:value: 14
-------------------
GLSL attribute type
-------------------
.. _attribute-type:
Type of the vertex attribute used in the GLSL shader. Determines the mesh custom data
layer that contains the vertex attribute.
.. data:: CD_MTFACE
Vertex attribute is a UV layer. Data type is vector of 2 float.
There can be more than one attribute of that type, they are differenciated by name.
In blender, you can retrieve the attribute data with:
.. code-block:: python
mesh.uv_textures[attribute['name']]
:value: 5
.. data:: CD_MCOL
Vertex attribute is color layer. Data type is vector 4 unsigned byte (RGBA).
There can be more than one attribute of that type, they are differenciated by name.
In blender you can retrieve the attribute data with:
.. code-block:: python
mesh.vertex_colors[attribute['name']]
:value: 6
.. data:: CD_ORCO
Vertex attribute is original coordinates. Data type is vector 3 float.
There can be only 1 attribute of that type per shader.
In blender you can retrieve the attribute data with:
.. code-block:: python
mesh.vertices
:value: 14
.. data:: CD_TANGENT
Vertex attribute is the tangent vector. Data type is vector 4 float.
There can be only 1 attribute of that type per shader.
There is currently no way to retrieve this attribute data via the RNA API but a standalone
C function to compute the tangent layer from the other layers can be obtained from
blender.org.
:value: 18
*********
Functions
*********
.. _export_shader:
.. function:: export_shader(scene,material)
Extracts the GLSL shader producing the visual effect of material in scene for the purpose of
reusing the shader in an external engine. This function is meant to be used in material exporter
so that the GLSL shader can be exported entirely. The return value is a dictionary containing the
shader source code and all associated data.
:arg scene: the scene in which the material in rendered.
:type scene: :class:`bpy.types.Scene`
:arg material: the material that you want to export the GLSL shader
:type material: :class:`bpy.types.Material`
:return: the shader source code and all associated data in a dictionary
:rtype: dictionary
The dictionary contains the following elements:
* ['fragment'] : string
fragment shader source code.
* ['vertex'] : string
vertex shader source code.
* ['uniforms'] : sequence
list of uniforms used in fragment shader, can be empty list. Each element of the
sequence is a dictionary with the following elements:
* ['varname'] : string
name of the uniform in the fragment shader. Always of the form 'unf<number>'.
* ['datatype'] : integer
data type of the uniform variable. Can be one of the following:
* :data:`gpu.GPU_DATA_1I` : use glUniform1i
* :data:`gpu.GPU_DATA_1F` : use glUniform1fv
* :data:`gpu.GPU_DATA_2F` : use glUniform2fv
* :data:`gpu.GPU_DATA_3F` : use glUniform3fv
* :data:`gpu.GPU_DATA_4F` : use glUniform4fv
* :data:`gpu.GPU_DATA_9F` : use glUniformMatrix3fv
* :data:`gpu.GPU_DATA_16F` : use glUniformMatrix4fv
* ['type'] : integer
type of uniform, determines the origin and method of calculation. See uniform-type_.
Depending on the type, more elements will be be present.
* ['lamp'] : :class:`bpy.types.Object`
Reference to the lamp object from which the uniforms value are extracted. Set for the following uniforms types:
.. hlist::
:columns: 3
* :data:`gpu.GPU_DYNAMIC_LAMP_DYNVEC`
* :data:`gpu.GPU_DYNAMIC_LAMP_DYNCO`
* :data:`gpu.GPU_DYNAMIC_LAMP_DYNIMAT`
* :data:`gpu.GPU_DYNAMIC_LAMP_DYNPERSMAT`
* :data:`gpu.GPU_DYNAMIC_LAMP_DYNENERGY`
* :data:`gpu.GPU_DYNAMIC_LAMP_DYNCOL`
* :data:`gpu.GPU_DYNAMIC_SAMPLER_2DSHADOW`
Notes:
* The uniforms :data:`gpu.GPU_DYNAMIC_LAMP_DYNVEC`, :data:`gpu.GPU_DYNAMIC_LAMP_DYNCO`, :data:`gpu.GPU_DYNAMIC_LAMP_DYNIMAT` and :data:`gpu.GPU_DYNAMIC_LAMP_DYNPERSMAT`
refer to the lamp object position and orientation, both of can be derived from the object world matrix:
.. code-block:: python
obmat = uniform['lamp'].matrix_world
where obmat is the mat4_lamp_to_world_ matrix of the lamp as a 2 dimensional array,
the lamp world location location is in obmat[3].
* The uniform types :data:`gpu.GPU_DYNAMIC_LAMP_DYNENERGY` and :data:`gpu.GPU_DYNAMIC_LAMP_DYNCOL` refer to the lamp data bloc that you get from:
.. code-block:: python
la = uniform['lamp'].data
from which you get la.energy and la.color
* Lamp duplication is not supported: if you have duplicated lamps in your scene
(i.e. lamp that are instantiated by dupligroup, etc), this element will only
give you a reference to the orignal lamp and you will not know which instance
of the lamp it is refering too. You can still handle that case in the exporter
by distributing the uniforms amongst the duplicated lamps.
* ['image'] : :class:`bpy.types.Image`
Reference to the image databloc. Set for uniform type :data:`gpu.GPU_DYNAMIC_SAMPLER_2DIMAGE`. You can get the image data from:
.. code-block:: python
# full path to image file
uniform['image'].filepath
# image size as a 2-dimensional array of int
uniform['image'].size
* ['texnumber'] : integer
Channel number to which the texture is bound when drawing the object.
Set for uniform types :data:`gpu.GPU_DYNAMIC_SAMPLER_2DBUFFER`, :data:`gpu.GPU_DYNAMIC_SAMPLER_2DIMAGE` and :data:`gpu.GPU_DYNAMIC_SAMPLER_2DSHADOW`.
This is provided for information only: when reusing the shader outside blencer,
you are free to assign the textures to the channel of your choice and to pass
that number channel to the GPU in the uniform.
* ['texpixels'] : byte array
texture data for uniform type :data:`gpu.GPU_DYNAMIC_SAMPLER_2DBUFFER`. Although
the corresponding uniform is a 2D sampler, the texture is always a 1D texture
of n x 1 pixel. The texture size n is provided in ['texsize'] element.
These texture are only used for computer generated texture (colorband, etc).
The texture data is provided so that you can make a real image out of it in the
exporter.
* ['texsize'] : integer
horizontal size of texture for uniform type :data:`gpu.GPU_DYNAMIC_SAMPLER_2DBUFFER`.
The texture data is in ['texpixels'].
* ['attributes'] : sequence
list of attributes used in vertex shader, can be empty. Blender doesn't use
standard attributes except for vertex position and normal. All other vertex
attributes must be passed using the generic glVertexAttrib functions.
The attribute data can be found in the derived mesh custom data using RNA.
Each element of the sequence is a dictionary containing the following elements:
* ['varname'] : string
name of the uniform in the vertex shader. Always of the form 'att<number>'.
* ['datatype'] : integer
data type of vertex attribute, can be one of the following:
* :data:`gpu.GPU_DATA_2F` : use glVertexAttrib2fv
* :data:`gpu.GPU_DATA_3F` : use glVertexAttrib3fv
* :data:`gpu.GPU_DATA_4F` : use glVertexAttrib4fv
* :data:`gpu.GPU_DATA_4UB` : use glVertexAttrib4ubv
* ['number'] : integer
generic attribute number. This is provided for information only. Blender
doesn't use glBindAttribLocation to place generic attributes at specific location,
it lets the shader compiler place the attributes automatically and query the
placement with glGetAttribLocation. The result of this placement is returned in
this element.
When using this shader in a render engine, you should either use
glBindAttribLocation to force the attribute at this location or use
glGetAttribLocation to get the placement chosen by the compiler of your GPU.
* ['type'] : integer
type of the mesh custom data from which the vertex attribute is loaded.
See attribute-type_.
* ['name'] : string or integer
custom data layer name, used for attribute type :data:`gpu.CD_MTFACE` and :data:`gpu.CD_MCOL`.
Example:
.. code-block:: python
import gpu
# get GLSL shader of material Mat.001 in scene Scene.001
scene = bpy.data.scenes['Scene.001']
material = bpy.data.materials['Mat.001']
shader = gpu.export_shader(scene,material)
# scan the uniform list and find the images used in the shader
for uniform in shader['uniforms']:
if uniform['type'] == gpu.GPU_DYNAMIC_SAMPLER_2DIMAGE:
print("uniform {0} is using image {1}".format(uniform['varname'], uniform['image'].filepath))
# scan the attribute list and find the UV layer used in the shader
for attribute in shader['attributes']:
if attribute['type'] == gpu.CD_MTFACE:
print("attribute {0} is using UV layer {1}".format(attribute['varname'], attribute['name']))
*****
Notes
*****
.. _mat4_lamp_to_perspective:
1. Calculation of the *mat4_lamp_to_perspective* matrix for a spot lamp.
The following pseudo code shows how the *mat4_lamp_to_perspective* matrix is computed
in blender for uniforms of :data:`gpu.GPU_DYNAMIC_LAMP_DYNPERSMAT` type::
#Get the lamp datablock with:
lamp=bpy.data.objects[uniform['lamp']].data
#Compute the projection matrix:
# You will need these lamp attributes:
# lamp.clipsta : near clip plane in world unit
# lamp.clipend : far clip plane in world unit
# lamp.spotsize : angle in degree of the spot light
#The size of the projection plane is computed with the usual formula:
wsize = lamp.clista * tan(lamp.spotsize/2)
#And the projection matrix:
mat4_lamp_to_perspective = glFrustum(-wsize,wsize,-wsize,wsize,lamp.clista,lamp.clipend)
2. Creation of the shadow map for a spot lamp.
The shadow map is the depth buffer of a render performed by placing the camera at the
spot light position. The size of the shadow map is given by the attribute lamp.bufsize :
shadow map size in pixel, same size in both dimensions.

@ -0,0 +1,65 @@
*************
Best Practice
*************
TODO: Intro text
Style Conventions
=================
For Blender 2.5 we have chosen to follow python suggested style guide to avoid mixing styles amongst our own scripts and make it easier to use python scripts from other projects.
Using our style guide for your own scripts makes it easier if you eventually want to contribute them to blender.
This style guide is known as pep8 and can be found `here <http://www.python.org/dev/peps/pep-0008>`_
A brief listing of pep8 criteria.
* camel caps for class names: MyClass
* all lower case underscore separated module names: my_module
* indentation of 4 spaces (no tabs)
* spaces around operators. ``1 + 1``, not ``1+1``
* only use explicit imports, (no importing '*')
* don't use single line: ``if val: body``, separate onto 2 lines instead.
As well as pep8 we have other conventions used for blender python scripts.
* Use single quotes for enums, and double quotes for strings.
Both are of course strings but in our internal API enums are unique items from a limited set. eg.
.. code-block:: python
bpy.context.scene.render.file_format = 'PNG'
bpy.context.scene.render.filepath = "//render_out"
* pep8 also defines that lines should not exceed 79 characters, we felt this is too restrictive so this is optional per script.
Periodically we run checks for pep8 compliance on blender scripts, for scripts to be included in this check add this line as a comment at the top of the script.
``# <pep8 compliant>``
To enable line length checks use this instead.
``# <pep8-80 compliant>``
User Interface Layout
=====================
TODO: Thomas
Script Efficiency
=================
TODO: Campbell

@ -156,7 +156,7 @@ Note that these properties can only be assigned basic Python types.
* array of ints/floats * array of ints/floats
* dictionary (only string keys types on this list) * dictionary (only string keys are supported, values must be basic types too)
These properties are valid outside of Python. They can be animated by curves or used in driver paths. These properties are valid outside of Python. They can be animated by curves or used in driver paths.
@ -420,49 +420,3 @@ Using Low-Level Functions:
fcu_z.keyframe_points[0].co = 10.0, 0.0 fcu_z.keyframe_points[0].co = 10.0, 0.0
fcu_z.keyframe_points[1].co = 20.0, 1.0 fcu_z.keyframe_points[1].co = 20.0, 1.0
Style Conventions
=================
For Blender 2.5 we have chosen to follow python suggested style guide to avoid mixing styles amongst our own scripts and make it easier to use python scripts from other projects.
Using our style guide for your own scripts makes it easier if you eventually want to contribute them to blender.
This style guide is known as pep8 and can be found `here <http://www.python.org/dev/peps/pep-0008>`_
A brief listing of pep8 criteria.
* camel caps for class names: MyClass
* all lower case underscore separated module names: my_module
* indentation of 4 spaces (no tabs)
* spaces around operators. ``1 + 1``, not ``1+1``
* only use explicit imports, (no importing '*')
* don't use single line: ``if val: body``, separate onto 2 lines instead.
As well as pep8 we have other conventions used for blender python scripts.
* Use single quotes for enums, and double quotes for strings.
Both are of course strings but in our internal API enums are unique items from a limited set. eg.
.. code-block:: python
bpy.context.scene.render.file_format = 'PNG'
bpy.context.scene.render.filepath = "//render_out"
* pep8 also defines that lines should not exceed 79 characters, we felt this is too restrictive so this is optional per script.
Periodically we run checks for pep8 compliance on blender scripts, for scripts to be included in this check add this line as a comment at the top of the script.
``# <pep8 compliant>``
To enable line length checks use this instead.
``# <pep8-80 compliant>``

@ -1,57 +1,228 @@
############### ***************
Tips and Tricks Tips and Tricks
############### ***************
Some of these are just python features that scripters may not have thaught to use with blender. Here are various suggestions that you might find useful when writing scripts.
Some of these are just python features that scripters may not have thought to use with blender, others are blender specific.
****************
Use The Terminal Use The Terminal
**************** ================
For Linux and OSX users this means starting the terminal first, then running blender from within it. on Windows the terminal can be enabled from the help menu. When writing python scripts, its useful to have a terminal open, this is not the built-in python console but a terminal application which is used to start blender.
******************** There are 3 main uses for the terminal, these are:
Run External Scripts
******************** * You can see the output of `print()` as you're script runs, which is useful to view debug info.
* The error trace-back is printed in full to the terminal which wont always generate an error popup in blenders user interface (depending on how the script is executed).
* If the script runs for too long or you accidentally enter an infinite loop, Ctrl+C in the terminal (Ctrl+Break on Windows) will quit the script early.
.. note::
For Linux and OSX users this means starting the terminal first, then running blender from within it. On Windows the terminal can be enabled from the help menu.
Use an External Editor
======================
Blenders text editor is fine for small changes and writing tests but its not full featured, for larger projects you'll probably want to use a standalone editor or python IDE.
Editing a text file externally and having the same text open in blender does work but isn't that optimal so here are 2 ways you can easily use an external file from blender.
Using the following examples you'll still need textblock in blender to execute, but reference an external file rather then including it directly.
Executing External Scripts
--------------------------
This is the equivalent to running the script directly, referencing a scripts path from a 2 line textblock.
.. code-block:: python
filename = "/full/path/to/myscript.py"
exec(compile(open(filename).read(), filename, 'exec'))
You might want to reference a script relative to the blend file.
.. code-block:: python
import bpy
import os
filename = os.path.join(os.path.basename(bpy.data.filepath), "myscript.py")
exec(compile(open(filename).read(), filename, 'exec'))
Executing Modules
-----------------
This example shows loading a script in as a module and executing a module function.
.. code-block:: python
import myscript
import imp
imp.reload(myscript)
myscript.main()
Notice that the script is reloaded every time, this forces use of the modified version otherwise the cached one in `sys.modules` would be used until blender was restarted.
The important difference between this and executing the script directly is it has to call a function in the module, in this case `main()` but it can be any function, an advantage with this is you can pass arguments to the function from this small script which is often useful for testing different settings quickly.
The other issue with this is the script has to be in pythons module search path.
While this is not best practice - for testing you can extend the search path, this example adds the current blend files directory to the search path, then loads the script as a module.
.. code-block:: python
import sys
import os
import bpy
blend_dir = os.path.basename(bpy.data.filepath)
if blend_dir not in sys.path:
sys.path.append(blend_dir)
import myscript
import imp
imp.reload(myscript)
myscript.main()
******************
Don't Use Blender! Don't Use Blender!
****************** ==================
While developing your own scripts blenders interface can get in the way, manually reloading, running the scripts, opening file import etc. adds overhead.
For scripts that are not interactive it can end up being more efficient not to use blenders interface at all and instead execute the script on the command line.
.. code-block:: python
blender --background --python myscript.py
You might want to run this with a blend file so the script has some data to operate on.
.. code-block:: python
blender myscene.blend --background --python myscript.py
.. note::
Depending on you're setup you might have to enter the full path to the blender executable.
Once the script is running properly in background mode, you'll want to check the output of the script, this depends completely on the task at hand however here are some suggestions.
* render the output to an image, use an image viewer and keep writing over the same image each time.
* save a new blend file, or export the file using one of blenders exporters.
* if the results can be displayed as text - print them or write them to a file.
This can take a little time to setup, but it can be well worth the effort to reduce the time it takes to test changes - you can even have blender running the script ever few seconds with a viewer updating the results, so no need to leave you're text editor to see changes.
******************
Use External Tools Use External Tools
****************** ==================
When there are no readily available python modules to perform specific tasks its worth keeping in mind you may be able to have python execute an external command on you're data and read the result back in.
Using external programs adds an extra dependency and may limit who can use the script but to quickly setup you're own custom pipeline or writing one-off scripts this can be handy.
Examples include:
* Run The Gimp in batch mode to execute custom scripts for advanced image processing.
* Write out 3D models to use external mesh manipulation tools and read back in the results.
* Convert files into recognizable formats before reading.
************** Bundled Python & Extensions
Bundled Python ===========================
**************
Blender from blender.org includes a compleate python installation on all platforms, this has the disadvantage that any extensions you have installed in you're systems python wont be found by blender. The Blender releases distributed from blender.org include a complete python installation on all platforms, this has the disadvantage that any extensions you have installed in you're systems python wont be found by blender.
There are 2 ways around this: There are 2 ways around this:
* remove blender python subdirectory, blender will then look for the systems python and use that instead **python version must match the one that blender comes with**. * remove blender python sub-directory, blender will then fallback on the systems python and use that instead **python version must match the one that blender comes with**.
* copy the extensions into blender's python sub-directory so blender can access them, you could also copy the entire python installation into blenders sub-directory, replacing the one blender comes with. This works as long as the python versions match and the paths are created in the same relative locations. Doing this has the advantage that you can redistribute this bundle to others with blender and/or the game player, including any extensions you rely on.
Drop Into a Python Interpreter in You're Script
===============================================
In the middle of a script you may want to inspect some variables, run some function and generally dig about to see whats going on.
.. code-block:: python
import code
code.interact(local=locals())
If you want to access both global and local variables do this...
.. code-block:: python
import code
namespace = globals().copy()
namespace.update(locals())
code.interact(local=namespace)
The next example is an equivalent single line version of the script above which is easier to paste into you're code:
.. code-block:: python
__import__('code').interact(local={k: v for ns in (globals(), locals()) for k, v in ns.items()})
`code.interact` can be added at any line in the script and will pause the script an launch an interactive interpreter in the terminal, when you're done you can quit the interpreter and the script will continue execution.
Admittedly this highlights the lack of any python debugging support built into blender, but its still handy to know.
.. note::
This works in the game engine as well, it can be handy to inspect the state of a running game.
* copy the extensions into blender's python subdirectry so blender can access them, you could also copy the entire python installation into blenders subdirectory, replacing the one blender comes with. This works as long as the python versions match and the paths are created in the same location relative locations. Doing this has the advantage that you can redistribute this bundle to others with blender and/or the game player, including any extensions you rely on.
********
Advanced Advanced
******** ========
===================
Blender as a module Blender as a module
=================== -------------------
From a python perspective its nicer to have everything as an extension which lets the python script combine many components.
Advantages include:
* you can use external editors/IDE's with blenders python API and execute scripts within the IDE (step over code, inspect variables as the script runs).
* editors/IDE's can auto complete blender modules & variables.
* existing scripts can import blender API's without having to run inside blender.
This is marked advanced because to run blender as a python module requires a special build option.
For instructions on building see `Building blender as a python module <http://wiki.blender.org/index.php/User:Ideasman42/BlenderAsPyModule>`_
============================
Python Safety (Build Option) Python Safety (Build Option)
============================ ----------------------------
Since its possible to accessed data which has been removed (see Gotcha's), this can be a hard to track down the cause of crashes.
To raise python exceptions on accessing freed data (rather then crashing), enable the CMake build option WITH_PYTHON_SAFETY.
This enables data tracking which makes data access about 2x slower which is why the option is not enabled in release builds.
=================
CTypes in Blender
=================

@ -104,6 +104,8 @@ sphinx-build doc/python_api/sphinx-in doc/python_api/sphinx-out
INFO_DOCS = ( INFO_DOCS = (
("info_quickstart.rst", "Blender/Python Quickstart: new to blender/scripting and want to get you're feet wet?"), ("info_quickstart.rst", "Blender/Python Quickstart: new to blender/scripting and want to get you're feet wet?"),
("info_overview.rst", "Blender/Python API Overview: a more complete explanation of python integration"), ("info_overview.rst", "Blender/Python API Overview: a more complete explanation of python integration"),
("info_best_practice.rst", "Best Practice: Conventions to follow for writing good scripts"),
("info_tips_and_tricks.rst", "Tips and Tricks: Hints to help you while writeing scripts for blender"),
("info_gotcha.rst", "Gotcha's: some of the problems you may come up against when writing scripts"), ("info_gotcha.rst", "Gotcha's: some of the problems you may come up against when writing scripts"),
) )
@ -586,6 +588,7 @@ def pycontext2sphinx(BASEPATH):
"sequences": ("Sequence", True), "sequences": ("Sequence", True),
"smoke": ("SmokeModifier", False), "smoke": ("SmokeModifier", False),
"soft_body": ("SoftBodyModifier", False), "soft_body": ("SoftBodyModifier", False),
"speaker": ("Speaker", False),
"texture": ("Texture", False), "texture": ("Texture", False),
"texture_slot": ("MaterialTextureSlot", False), "texture_slot": ("MaterialTextureSlot", False),
"vertex_paint_object": ("Object", False), "vertex_paint_object": ("Object", False),

@ -43,6 +43,10 @@ if(WITH_BUILTIN_GLEW)
add_subdirectory(glew) add_subdirectory(glew)
endif() endif()
if(WITH_GAMEENGINE)
add_subdirectory(recastnavigation)
endif()
if(WITH_IMAGE_OPENJPEG AND (NOT UNIX OR APPLE)) if(WITH_IMAGE_OPENJPEG AND (NOT UNIX OR APPLE))
add_subdirectory(libopenjpeg) add_subdirectory(libopenjpeg)
endif() endif()

1
extern/SConscript vendored

@ -3,6 +3,7 @@
Import('env') Import('env')
SConscript(['glew/SConscript']) SConscript(['glew/SConscript'])
SConscript(['recastnavigation/SConscript'])
if env['WITH_BF_ELTOPO']: if env['WITH_BF_ELTOPO']:
SConscript(['eltopo/SConscript']) SConscript(['eltopo/SConscript'])

66
extern/recastnavigation/CMakeLists.txt vendored Normal file

@ -0,0 +1,66 @@
# $Id$
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# The Original Code is Copyright (C) 2006, Blender Foundation
# All rights reserved.
#
# The Original Code is: all of this file.
#
# Contributor(s): Daniel Genrich
#
# ***** END GPL LICENSE BLOCK *****
set(INC
Recast/Include
Detour/Include
)
set(INC_SYS
)
set(SRC
Detour/Source/DetourCommon.cpp
Detour/Source/DetourNode.cpp
Detour/Source/DetourStatNavMesh.cpp
Detour/Source/DetourStatNavMeshBuilder.cpp
Detour/Source/DetourTileNavMesh.cpp
Detour/Source/DetourTileNavMeshBuilder.cpp
Detour/Include/DetourCommon.h
Detour/Include/DetourNode.h
Detour/Include/DetourStatNavMesh.h
Detour/Include/DetourStatNavMeshBuilder.h
Detour/Include/DetourTileNavMesh.h
Detour/Include/DetourTileNavMeshBuilder.h
Recast/Source/Recast.cpp
Recast/Source/RecastContour.cpp
Recast/Source/RecastFilter.cpp
Recast/Source/RecastLog.cpp
Recast/Source/RecastMesh.cpp
Recast/Source/RecastMeshDetail.cpp
Recast/Source/RecastRasterization.cpp
Recast/Source/RecastRegion.cpp
Recast/Source/RecastTimer.cpp
Recast/Include/Recast.h
Recast/Include/RecastLog.h
Recast/Include/RecastTimer.h
)
blender_add_lib(extern_recastnavigation "${SRC}" "${INC}" "${INC_SYS}")

@ -0,0 +1,167 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef DETOURCOMMON_H
#define DETOURCOMMON_H
//////////////////////////////////////////////////////////////////////////////////////////
template<class T> inline void swap(T& a, T& b) { T t = a; a = b; b = t; }
template<class T> inline T min(T a, T b) { return a < b ? a : b; }
template<class T> inline T max(T a, T b) { return a > b ? a : b; }
template<class T> inline T abs(T a) { return a < 0 ? -a : a; }
template<class T> inline T sqr(T a) { return a*a; }
template<class T> inline T clamp(T v, T mn, T mx) { return v < mn ? mn : (v > mx ? mx : v); }
inline void vcross(float* dest, const float* v1, const float* v2)
{
dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
dest[2] = v1[0]*v2[1] - v1[1]*v2[0];
}
inline float vdot(const float* v1, const float* v2)
{
return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
}
inline void vmad(float* dest, const float* v1, const float* v2, const float s)
{
dest[0] = v1[0]+v2[0]*s;
dest[1] = v1[1]+v2[1]*s;
dest[2] = v1[2]+v2[2]*s;
}
inline void vadd(float* dest, const float* v1, const float* v2)
{
dest[0] = v1[0]+v2[0];
dest[1] = v1[1]+v2[1];
dest[2] = v1[2]+v2[2];
}
inline void vsub(float* dest, const float* v1, const float* v2)
{
dest[0] = v1[0]-v2[0];
dest[1] = v1[1]-v2[1];
dest[2] = v1[2]-v2[2];
}
inline void vmin(float* mn, const float* v)
{
mn[0] = min(mn[0], v[0]);
mn[1] = min(mn[1], v[1]);
mn[2] = min(mn[2], v[2]);
}
inline void vmax(float* mx, const float* v)
{
mx[0] = max(mx[0], v[0]);
mx[1] = max(mx[1], v[1]);
mx[2] = max(mx[2], v[2]);
}
inline void vcopy(float* dest, const float* a)
{
dest[0] = a[0];
dest[1] = a[1];
dest[2] = a[2];
}
inline float vdist(const float* v1, const float* v2)
{
float dx = v2[0] - v1[0];
float dy = v2[1] - v1[1];
float dz = v2[2] - v1[2];
return sqrtf(dx*dx + dy*dy + dz*dz);
}
inline float vdistSqr(const float* v1, const float* v2)
{
float dx = v2[0] - v1[0];
float dy = v2[1] - v1[1];
float dz = v2[2] - v1[2];
return dx*dx + dy*dy + dz*dz;
}
inline void vnormalize(float* v)
{
float d = 1.0f / sqrtf(sqr(v[0]) + sqr(v[1]) + sqr(v[2]));
v[0] *= d;
v[1] *= d;
v[2] *= d;
}
inline bool vequal(const float* p0, const float* p1)
{
static const float thr = sqr(1.0f/16384.0f);
const float d = vdistSqr(p0, p1);
return d < thr;
}
inline int nextPow2(int v)
{
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
return v;
}
inline float vdot2D(const float* u, const float* v)
{
return u[0]*v[0] + u[2]*v[2];
}
inline float vperp2D(const float* u, const float* v)
{
return u[2]*v[0] - u[0]*v[2];
}
inline float triArea2D(const float* a, const float* b, const float* c)
{
return ((b[0]*a[2] - a[0]*b[2]) + (c[0]*b[2] - b[0]*c[2]) + (a[0]*c[2] - c[0]*a[2])) * 0.5f;
}
inline bool checkOverlapBox(const unsigned short amin[3], const unsigned short amax[3],
const unsigned short bmin[3], const unsigned short bmax[3])
{
bool overlap = true;
overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap;
overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap;
overlap = (amin[2] > bmax[2] || amax[2] < bmin[2]) ? false : overlap;
return overlap;
}
void closestPtPointTriangle(float* closest, const float* p,
const float* a, const float* b, const float* c);
bool closestHeightPointTriangle(const float* p, const float* a, const float* b, const float* c, float& h);
bool intersectSegmentPoly2D(const float* p0, const float* p1,
const float* verts, int nverts,
float& tmin, float& tmax,
int& segMin, int& segMax);
float distancePtSegSqr2D(const float* pt, const float* p, const float* q, float& t);
void calcPolyCenter(float* tc, const unsigned short* idx, int nidx, const float* verts);
#endif // DETOURCOMMON_H

@ -0,0 +1,149 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef DETOURNODE_H
#define DETOURNODE_H
enum dtNodeFlags
{
DT_NODE_OPEN = 0x01,
DT_NODE_CLOSED = 0x02,
};
struct dtNode
{
float cost;
float total;
unsigned int id;
unsigned int pidx : 30;
unsigned int flags : 2;
};
class dtNodePool
{
public:
dtNodePool(int maxNodes, int hashSize);
~dtNodePool();
inline void operator=(const dtNodePool&) {}
void clear();
dtNode* getNode(unsigned int id);
const dtNode* findNode(unsigned int id) const;
inline unsigned int getNodeIdx(const dtNode* node) const
{
if (!node) return 0;
return (unsigned int)(node - m_nodes)+1;
}
inline dtNode* getNodeAtIdx(unsigned int idx)
{
if (!idx) return 0;
return &m_nodes[idx-1];
}
inline int getMemUsed() const
{
return sizeof(*this) +
sizeof(dtNode)*m_maxNodes +
sizeof(unsigned short)*m_maxNodes +
sizeof(unsigned short)*m_hashSize;
}
private:
inline unsigned int hashint(unsigned int a) const
{
a += ~(a<<15);
a ^= (a>>10);
a += (a<<3);
a ^= (a>>6);
a += ~(a<<11);
a ^= (a>>16);
return a;
}
dtNode* m_nodes;
unsigned short* m_first;
unsigned short* m_next;
const int m_maxNodes;
const int m_hashSize;
int m_nodeCount;
};
class dtNodeQueue
{
public:
dtNodeQueue(int n);
~dtNodeQueue();
inline void operator=(dtNodeQueue&) {}
inline void clear()
{
m_size = 0;
}
inline dtNode* top()
{
return m_heap[0];
}
inline dtNode* pop()
{
dtNode* result = m_heap[0];
m_size--;
trickleDown(0, m_heap[m_size]);
return result;
}
inline void push(dtNode* node)
{
m_size++;
bubbleUp(m_size-1, node);
}
inline void modify(dtNode* node)
{
for (int i = 0; i < m_size; ++i)
{
if (m_heap[i] == node)
{
bubbleUp(i, node);
return;
}
}
}
inline bool empty() const { return m_size == 0; }
inline int getMemUsed() const
{
return sizeof(*this) +
sizeof(dtNode*)*(m_capacity+1);
}
private:
void bubbleUp(int i, dtNode* node);
void trickleDown(int i, dtNode* node);
dtNode** m_heap;
const int m_capacity;
int m_size;
};
#endif // DETOURNODE_H

@ -0,0 +1,234 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef DETOURSTATNAVMESH_H
#define DETOURSTATNAVMESH_H
// Reference to navigation polygon.
typedef unsigned short dtStatPolyRef;
// Maximum number of vertices per navigation polygon.
static const int DT_STAT_VERTS_PER_POLYGON = 6;
// Structure holding the navigation polygon data.
struct dtStatPoly
{
unsigned short v[DT_STAT_VERTS_PER_POLYGON]; // Indices to vertices of the poly.
dtStatPolyRef n[DT_STAT_VERTS_PER_POLYGON]; // Refs to neighbours of the poly.
unsigned char nv; // Number of vertices.
unsigned char flags; // Flags (not used).
};
struct dtStatPolyDetail
{
unsigned short vbase; // Offset to detail vertex array.
unsigned short nverts; // Number of vertices in the detail mesh.
unsigned short tbase; // Offset to detail triangle array.
unsigned short ntris; // Number of triangles.
};
const int DT_STAT_NAVMESH_MAGIC = 'NAVM';
const int DT_STAT_NAVMESH_VERSION = 3;
struct dtStatBVNode
{
unsigned short bmin[3], bmax[3];
int i;
};
struct dtStatNavMeshHeader
{
int magic;
int version;
int npolys;
int nverts;
int nnodes;
int ndmeshes;
int ndverts;
int ndtris;
float cs;
float bmin[3], bmax[3];
dtStatPoly* polys;
float* verts;
dtStatBVNode* bvtree;
dtStatPolyDetail* dmeshes;
float* dverts;
unsigned char* dtris;
};
class dtStatNavMesh
{
public:
dtStatNavMesh();
~dtStatNavMesh();
// Initializes the navmesh with data.
// Params:
// data - (in) Pointer to navmesh data.
// dataSize - (in) size of the navmesh data.
// ownsData - (in) Flag indicating if the navmesh should own and delete the data.
bool init(unsigned char* data, int dataSize, bool ownsData);
// Finds the nearest navigation polygon around the center location.
// Params:
// center - (in) The center of the search box.
// extents - (in) The extents of the search box.
// Returns: Reference identifier for the polygon, or 0 if no polygons found.
dtStatPolyRef findNearestPoly(const float* center, const float* extents);
// Returns polygons which touch the query box.
// Params:
// center - (in) the center of the search box.
// extents - (in) the extents of the search box.
// polys - (out) array holding the search result.
// maxPolys - (in) The max number of polygons the polys array can hold.
// Returns: Number of polygons in search result array.
int queryPolygons(const float* center, const float* extents,
dtStatPolyRef* polys, const int maxPolys);
// Finds path from start polygon to end polygon.
// If target polygon canno be reached through the navigation graph,
// the last node on the array is nearest node to the end polygon.
// Params:
// startRef - (in) ref to path start polygon.
// endRef - (in) ref to path end polygon.
// path - (out) array holding the search result.
// maxPathSize - (in) The max number of polygons the path array can hold.
// Returns: Number of polygons in search result array.
int findPath(dtStatPolyRef startRef, dtStatPolyRef endRef,
const float* startPos, const float* endPos,
dtStatPolyRef* path, const int maxPathSize);
// Finds a straight path from start to end locations within the corridor
// described by the path polygons.
// Start and end locations will be clamped on the corridor.
// Params:
// startPos - (in) Path start location.
// endPos - (in) Path end location.
// path - (in) Array of connected polygons describing the corridor.
// pathSize - (in) Number of polygons in path array.
// straightPath - (out) Points describing the straight path.
// maxStraightPathSize - (in) The max number of points the straight path array can hold.
// Returns: Number of points in the path.
int findStraightPath(const float* startPos, const float* endPos,
const dtStatPolyRef* path, const int pathSize,
float* straightPath, const int maxStraightPathSize);
// Finds intersection againts walls starting from start pos.
// Params:
// startRef - (in) ref to the polygon where the start lies.
// startPos - (in) start position of the query.
// endPos - (in) end position of the query.
// t - (out) hit parameter along the segment, 0 if no hit.
// endRef - (out) ref to the last polygon which was processed.
// Returns: Number of polygons in path or 0 if failed.
int raycast(dtStatPolyRef startRef, const float* startPos, const float* endPos,
float& t, dtStatPolyRef* path, const int pathSize);
// Returns distance to nearest wall from the specified location.
// Params:
// centerRef - (in) ref to the polygon where the center lies.
// centerPos - (in) center if the query circle.
// maxRadius - (in) max search radius.
// hitPos - (out) location of the nearest hit.
// hitNormal - (out) normal of the nearest hit.
// Returns: Distance to nearest wall from the test location.
float findDistanceToWall(dtStatPolyRef centerRef, const float* centerPos, float maxRadius,
float* hitPos, float* hitNormal);
// Finds polygons found along the navigation graph which touch the specified circle.
// Params:
// centerRef - (in) ref to the polygon where the center lies.
// centerPos - (in) center if the query circle
// radius - (in) radius of the query circle
// resultRef - (out, opt) refs to the polygons touched by the circle.
// resultParent - (out, opt) parent of each result polygon.
// resultCost - (out, opt) search cost at each result polygon.
// maxResult - (int) maximum capacity of search results.
// Returns: Number of results.
int findPolysAround(dtStatPolyRef centerRef, const float* centerPos, float radius,
dtStatPolyRef* resultRef, dtStatPolyRef* resultParent, float* resultCost,
const int maxResult);
// Returns closest point on navigation polygon.
// Params:
// ref - (in) ref to the polygon.
// pos - (in) the point to check.
// closest - (out) closest point.
// Returns: true if closest point found.
bool closestPointToPoly(dtStatPolyRef ref, const float* pos, float* closest) const;
// Returns height of the polygon at specified location.
// Params:
// ref - (in) ref to the polygon.
// pos - (in) the point where to locate the height.
// height - (out) height at the location.
// Returns: true if oer polygon.
bool getPolyHeight(dtStatPolyRef ref, const float* pos, float* height) const;
// Returns pointer to a polygon based on ref.
const dtStatPoly* getPolyByRef(dtStatPolyRef ref) const;
// Returns polygon index based on ref, or -1 if failed.
int getPolyIndexByRef(dtStatPolyRef ref) const;
// Returns number of navigation polygons.
inline int getPolyCount() const { return m_header ? m_header->npolys : 0; }
// Rerturns pointer to specified navigation polygon.
inline const dtStatPoly* getPoly(int i) const { return &m_header->polys[i]; }
// Returns number of vertices.
inline int getVertexCount() const { return m_header ? m_header->nverts : 0; }
// Returns pointer to specified vertex.
inline const float* getVertex(int i) const { return &m_header->verts[i*3]; }
// Returns number of navigation polygons details.
inline int getPolyDetailCount() const { return m_header ? m_header->ndmeshes : 0; }
// Rerturns pointer to specified navigation polygon detail.
const dtStatPolyDetail* getPolyDetail(int i) const { return &m_header->dmeshes[i]; }
// Returns pointer to specified vertex.
inline const float* getDetailVertex(int i) const { return &m_header->dverts[i*3]; }
// Returns pointer to specified vertex.
inline const unsigned char* getDetailTri(int i) const { return &m_header->dtris[i*4]; }
bool isInClosedList(dtStatPolyRef ref) const;
int getMemUsed() const;
inline unsigned char* getData() const { return m_data; }
inline int getDataSize() const { return m_dataSize; }
inline const dtStatNavMeshHeader* getHeader() const { return m_header; }
inline const dtStatBVNode* getBvTreeNodes() const { return m_header ? m_header->bvtree : 0; }
inline int getBvTreeNodeCount() const { return m_header ? m_header->nnodes : 0; }
private:
// Copies the locations of vertices of a polygon to an array.
int getPolyVerts(dtStatPolyRef ref, float* verts) const;
// Returns portal points between two polygons.
bool getPortalPoints(dtStatPolyRef from, dtStatPolyRef to, float* left, float* right) const;
// Returns edge mid point between two polygons.
bool getEdgeMidPoint(dtStatPolyRef from, dtStatPolyRef to, float* mid) const;
unsigned char* m_data;
int m_dataSize;
dtStatNavMeshHeader* m_header;
class dtNodePool* m_nodePool;
class dtNodeQueue* m_openList;
};
#endif // DETOURSTATNAVMESH_H

@ -0,0 +1,33 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef DETOURSTATNAVMESHBUILDER_H
#define DETOURSTATNAVMESHBUILDER_H
bool dtCreateNavMeshData(const unsigned short* verts, const int nverts,
const unsigned short* polys, const int npolys, const int nvp,
const float* bmin, const float* bmax, float cs, float ch,
const unsigned short* dmeshes, const float* dverts, const int ndverts,
const unsigned char* dtris, const int ndtris,
unsigned char** outData, int* outDataSize);
int createBVTree(const unsigned short* verts, const int nverts,
const unsigned short* polys, const int npolys, const int nvp,
float cs, float ch, int nnodes, dtStatBVNode* nodes);
#endif // DETOURSTATNAVMESHBUILDER_H

@ -0,0 +1,315 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef DETOURTILENAVMESH_H
#define DETOURTILENAVMESH_H
// Reference to navigation polygon.
typedef unsigned int dtTilePolyRef;
// The bits used in the poly ref.
static const int DT_TILE_REF_SALT_BITS = 12;
static const int DT_TILE_REF_TILE_BITS = 12;
static const int DT_TILE_REF_POLY_BITS = 8;
static const int DT_TILE_REF_SALT_MASK = (1<<DT_TILE_REF_SALT_BITS)-1;
static const int DT_TILE_REF_TILE_MASK = (1<<DT_TILE_REF_TILE_BITS)-1;
static const int DT_TILE_REF_POLY_MASK = (1<<DT_TILE_REF_POLY_BITS)-1;
// Maximum number of vertices per navigation polygon.
static const int DT_TILE_VERTS_PER_POLYGON = 6;
static const int DT_MAX_TILES = 1 << DT_TILE_REF_TILE_BITS;
static const int DT_MAX_POLYGONS = 1 << DT_TILE_REF_POLY_BITS;
static const int DT_TILE_NAVMESH_MAGIC = 'NAVT';
static const int DT_TILE_NAVMESH_VERSION = 2;
// Structure holding the navigation polygon data.
struct dtTilePoly
{
unsigned short v[DT_TILE_VERTS_PER_POLYGON]; // Indices to vertices of the poly.
unsigned short n[DT_TILE_VERTS_PER_POLYGON]; // Refs to neighbours of the poly.
unsigned short links; // Base index to header 'links' array.
unsigned char nlinks; // Number of links for
unsigned char nv; // Number of vertices.
unsigned char flags; // Flags (not used).
};
struct dtTilePolyDetail
{
unsigned short vbase; // Offset to detail vertex array.
unsigned short nverts; // Number of vertices in the detail mesh.
unsigned short tbase; // Offset to detail triangle array.
unsigned short ntris; // Number of triangles.
};
// Stucture holding a link to another polygon.
struct dtTileLink
{
dtTilePolyRef ref; // Neighbour reference.
unsigned short p; // Index to polygon which owns this link.
unsigned char e; // Index to polygon edge which owns this link.
unsigned char side; // If boundary link, defines on which side the link is.
unsigned char bmin, bmax; // If boundary link, defines the sub edge area.
};
struct dtTileHeader
{
int magic; // Magic number, used to identify the data.
int version; // Data version number.
int npolys; // Number of polygons in the tile.
int nverts; // Number of vertices in the tile.
int nlinks; // Number of links in the tile (will be updated when tile is added).
int maxlinks; // Number of allocated links.
int ndmeshes;
int ndverts;
int ndtris;
float bmin[3], bmax[3]; // Bounding box of the tile.
dtTilePoly* polys; // Pointer to the polygons (will be updated when tile is added).
float* verts; // Pointer to the vertices (will be updated when tile added).
dtTileLink* links; // Pointer to the links (will be updated when tile added).
dtTilePolyDetail* dmeshes;
float* dverts;
unsigned char* dtris;
};
struct dtTile
{
int salt; // Counter describing modifications to the tile.
int x,y; // Grid location of the tile.
dtTileHeader* header; // Pointer to tile header.
unsigned char* data; // Pointer to tile data.
int dataSize; // Size of the tile data.
bool ownsData; // Flag indicating of the navmesh should release the data.
dtTile* next; // Next free tile or, next tile in spatial grid.
};
// Encodes a tile id.
inline dtTilePolyRef dtEncodeTileId(unsigned int salt, unsigned int it, unsigned int ip)
{
return (salt << (DT_TILE_REF_POLY_BITS+DT_TILE_REF_TILE_BITS)) | ((it+1) << DT_TILE_REF_POLY_BITS) | ip;
}
// Decodes a tile id.
inline void dtDecodeTileId(dtTilePolyRef ref, unsigned int& salt, unsigned int& it, unsigned int& ip)
{
salt = (ref >> (DT_TILE_REF_POLY_BITS+DT_TILE_REF_TILE_BITS)) & DT_TILE_REF_SALT_MASK;
it = ((ref >> DT_TILE_REF_POLY_BITS) & DT_TILE_REF_TILE_MASK) - 1;
ip = ref & DT_TILE_REF_POLY_MASK;
}
static const int DT_TILE_LOOKUP_SIZE = DT_MAX_TILES/4;
class dtTiledNavMesh
{
public:
dtTiledNavMesh();
~dtTiledNavMesh();
// Initializes the nav mesh.
// Params:
// orig - (in) origin of the nav mesh tile space.
// tileSiz - (in) size of a tile.
// portalheight - (in) height of the portal region between tiles.
// Returns: True if succeed, else false.
bool init(const float* orig, float tileSize, float portalHeight);
// Adds new tile into the navmesh.
// The add will fail if the data is in wrong format,
// there is not enough tiles left, or if there is a tile already at the location.
// Params:
// x,y - (in) Location of the new tile.
// data - (in) Data of the new tile mesh.
// dataSize - (in) Data size of the new tile mesh.
// ownsData - (in) Flag indicating if the navmesh should own and delete the data.
// Returns: True if tile was added, else false.
bool addTileAt(int x, int y, unsigned char* data, int dataSize, bool ownsData);
// Removes tile at specified location.
// Params:
// x,y - (in) Location of the tile to remove.
// data - (out) Data associated with deleted tile.
// dataSize - (out) Size of the data associated with deleted tile.
// Returns: True if remove suceed, else false.
bool removeTileAt(int x, int y, unsigned char** data, int* dataSize);
// Returns pointer to tile at specified location.
// Params:
// x,y - (in) Location of the tile to get.
// Returns: pointer to tile if tile exists or 0 tile does not exists.
dtTile* getTileAt(int x, int y);
// Returns pointer to tile in the tile array.
// Params:
// i - (in) Index to the tile to retrieve, must be in range [0,DT_MAX_TILES[
// Returns: Pointer to specified tile.
dtTile* getTile(int i);
const dtTile* getTile(int i) const;
// Finds the nearest navigation polygon around the center location.
// Params:
// center - (in) The center of the search box.
// extents - (in) The extents of the search box.
// Returns: Reference identifier for the polygon, or 0 if no polygons found.
dtTilePolyRef findNearestPoly(const float* center, const float* extents);
// Returns polygons which touch the query box.
// Params:
// center - (in) the center of the search box.
// extents - (in) the extents of the search box.
// polys - (out) array holding the search result.
// maxPolys - (in) The max number of polygons the polys array can hold.
// Returns: Number of polygons in search result array.
int queryPolygons(const float* center, const float* extents,
dtTilePolyRef* polys, const int maxPolys);
// Finds path from start polygon to end polygon.
// If target polygon canno be reached through the navigation graph,
// the last node on the array is nearest node to the end polygon.
// Params:
// startRef - (in) ref to path start polygon.
// endRef - (in) ref to path end polygon.
// path - (out) array holding the search result.
// maxPathSize - (in) The max number of polygons the path array can hold.
// Returns: Number of polygons in search result array.
int findPath(dtTilePolyRef startRef, dtTilePolyRef endRef,
const float* startPos, const float* endPos,
dtTilePolyRef* path, const int maxPathSize);
// Finds a straight path from start to end locations within the corridor
// described by the path polygons.
// Start and end locations will be clamped on the corridor.
// Params:
// startPos - (in) Path start location.
// endPos - (in) Path end location.
// path - (in) Array of connected polygons describing the corridor.
// pathSize - (in) Number of polygons in path array.
// straightPath - (out) Points describing the straight path.
// maxStraightPathSize - (in) The max number of points the straight path array can hold.
// Returns: Number of points in the path.
int findStraightPath(const float* startPos, const float* endPos,
const dtTilePolyRef* path, const int pathSize,
float* straightPath, const int maxStraightPathSize);
// Finds intersection againts walls starting from start pos.
// Params:
// startRef - (in) ref to the polygon where the start lies.
// startPos - (in) start position of the query.
// endPos - (in) end position of the query.
// t - (out) hit parameter along the segment, 0 if no hit.
// endRef - (out) ref to the last polygon which was processed.
// Returns: Number of polygons in path or 0 if failed.
int raycast(dtTilePolyRef startRef, const float* startPos, const float* endPos,
float& t, dtTilePolyRef* path, const int pathSize);
// Returns distance to nearest wall from the specified location.
// Params:
// centerRef - (in) ref to the polygon where the center lies.
// centerPos - (in) center if the query circle.
// maxRadius - (in) max search radius.
// hitPos - (out) location of the nearest hit.
// hitNormal - (out) normal of the nearest hit.
// Returns: Distance to nearest wall from the test location.
float findDistanceToWall(dtTilePolyRef centerRef, const float* centerPos, float maxRadius,
float* hitPos, float* hitNormal);
// Finds polygons found along the navigation graph which touch the specified circle.
// Params:
// centerRef - (in) ref to the polygon where the center lies.
// centerPos - (in) center if the query circle
// radius - (in) radius of the query circle
// resultRef - (out, opt) refs to the polygons touched by the circle.
// resultParent - (out, opt) parent of each result polygon.
// resultCost - (out, opt) search cost at each result polygon.
// maxResult - (int) maximum capacity of search results.
// Returns: Number of results.
int findPolysAround(dtTilePolyRef centerRef, const float* centerPos, float radius,
dtTilePolyRef* resultRef, dtTilePolyRef* resultParent, float* resultCost,
const int maxResult);
// Returns closest point on navigation polygon.
// Params:
// ref - (in) ref to the polygon.
// pos - (in) the point to check.
// closest - (out) closest point.
// Returns: true if closest point found.
bool closestPointToPoly(dtTilePolyRef ref, const float* pos, float* closest) const;
// Returns height of the polygon at specified location.
// Params:
// ref - (in) ref to the polygon.
// pos - (in) the point where to locate the height.
// height - (out) height at the location.
// Returns: true if over polygon.
bool getPolyHeight(dtTilePolyRef ref, const float* pos, float* height) const;
// Returns pointer to a polygon based on ref.
const dtTilePoly* getPolyByRef(dtTilePolyRef ref) const;
// Returns pointer to a polygon vertices based on ref.
const float* getPolyVertsByRef(dtTilePolyRef ref) const;
// Returns pointer to a polygon link based on ref.
const dtTileLink* getPolyLinksByRef(dtTilePolyRef ref) const;
private:
// Returns base id for the tile.
dtTilePolyRef getTileId(dtTile* tile);
// Returns neighbour tile based on side.
dtTile* getNeighbourTileAt(int x, int y, int side);
// Returns all polygons in neighbour tile based on portal defined by the segment.
int findConnectingPolys(const float* va, const float* vb,
dtTile* tile, int side,
dtTilePolyRef* con, float* conarea, int maxcon);
// Builds internal polygons links for a tile.
void buildIntLinks(dtTile* tile);
// Builds external polygon links for a tile.
void buildExtLinks(dtTile* tile, dtTile* target, int side);
// Removes external links at specified side.
void removeExtLinks(dtTile* tile, int side);
// Queries polygons within a tile.
int queryTilePolygons(dtTile* tile, const float* qmin, const float* qmax,
dtTilePolyRef* polys, const int maxPolys);
float getCost(dtTilePolyRef prev, dtTilePolyRef from, dtTilePolyRef to) const;
float getFirstCost(const float* pos, dtTilePolyRef from, dtTilePolyRef to) const;
float getLastCost(dtTilePolyRef from, dtTilePolyRef to, const float* pos) const;
float getHeuristic(const float* from, const float* to) const;
// Returns portal points between two polygons.
bool getPortalPoints(dtTilePolyRef from, dtTilePolyRef to, float* left, float* right) const;
// Returns edge mid point between two polygons.
bool getEdgeMidPoint(dtTilePolyRef from, dtTilePolyRef to, float* mid) const;
float m_orig[3];
float m_tileSize;
float m_portalHeight;
dtTile* m_posLookup[DT_TILE_LOOKUP_SIZE];
dtTile* m_nextFree;
dtTile m_tiles[DT_MAX_TILES];
dtTileLink* m_tmpLinks;
int m_ntmpLinks;
class dtNodePool* m_nodePool;
class dtNodeQueue* m_openList;
};
#endif // DETOURTILENAVMESH_H

@ -0,0 +1,29 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef DETOURTILEDNAVMESHBUILDER_H
#define DETOURTILEDNAVMESHBUILDER_H
bool dtCreateNavMeshTileData(const unsigned short* verts, const int nverts,
const unsigned short* polys, const int npolys, const int nvp,
const unsigned short* dmeshes, const float* dverts, const int ndverts,
const unsigned char* dtris, const int ndtris,
const float* bmin, const float* bmax, float cs, float ch, int tileSize, int walkableClimb,
unsigned char** outData, int* outDataSize);
#endif // DETOURTILEDNAVMESHBUILDER_H

@ -0,0 +1,244 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#include <math.h>
#include "DetourCommon.h"
void closestPtPointTriangle(float* closest, const float* p,
const float* a, const float* b, const float* c)
{
// Check if P in vertex region outside A
float ab[3], ac[3], ap[3];
vsub(ab, b, a);
vsub(ac, c, a);
vsub(ap, p, a);
float d1 = vdot(ab, ap);
float d2 = vdot(ac, ap);
if (d1 <= 0.0f && d2 <= 0.0f)
{
// barycentric coordinates (1,0,0)
vcopy(closest, a);
return;
}
// Check if P in vertex region outside B
float bp[3];
vsub(bp, p, b);
float d3 = vdot(ab, bp);
float d4 = vdot(ac, bp);
if (d3 >= 0.0f && d4 <= d3)
{
// barycentric coordinates (0,1,0)
vcopy(closest, b);
return;
}
// Check if P in edge region of AB, if so return projection of P onto AB
float vc = d1*d4 - d3*d2;
if (vc <= 0.0f && d1 >= 0.0f && d3 <= 0.0f)
{
// barycentric coordinates (1-v,v,0)
float v = d1 / (d1 - d3);
closest[0] = a[0] + v * ab[0];
closest[1] = a[1] + v * ab[1];
closest[2] = a[2] + v * ab[2];
return;
}
// Check if P in vertex region outside C
float cp[3];
vsub(cp, p, c);
float d5 = vdot(ab, cp);
float d6 = vdot(ac, cp);
if (d6 >= 0.0f && d5 <= d6)
{
// barycentric coordinates (0,0,1)
vcopy(closest, c);
return;
}
// Check if P in edge region of AC, if so return projection of P onto AC
float vb = d5*d2 - d1*d6;
if (vb <= 0.0f && d2 >= 0.0f && d6 <= 0.0f)
{
// barycentric coordinates (1-w,0,w)
float w = d2 / (d2 - d6);
closest[0] = a[0] + w * ac[0];
closest[1] = a[1] + w * ac[1];
closest[2] = a[2] + w * ac[2];
return;
}
// Check if P in edge region of BC, if so return projection of P onto BC
float va = d3*d6 - d5*d4;
if (va <= 0.0f && (d4 - d3) >= 0.0f && (d5 - d6) >= 0.0f)
{
// barycentric coordinates (0,1-w,w)
float w = (d4 - d3) / ((d4 - d3) + (d5 - d6));
closest[0] = b[0] + w * (c[0] - b[0]);
closest[1] = b[1] + w * (c[1] - b[1]);
closest[2] = b[2] + w * (c[2] - b[2]);
return;
}
// P inside face region. Compute Q through its barycentric coordinates (u,v,w)
float denom = 1.0f / (va + vb + vc);
float v = vb * denom;
float w = vc * denom;
closest[0] = a[0] + ab[0] * v + ac[0] * w;
closest[1] = a[1] + ab[1] * v + ac[1] * w;
closest[2] = a[2] + ab[2] * v + ac[2] * w;
}
bool intersectSegmentPoly2D(const float* p0, const float* p1,
const float* verts, int nverts,
float& tmin, float& tmax,
int& segMin, int& segMax)
{
static const float EPS = 0.00000001f;
tmin = 0;
tmax = 1;
segMin = -1;
segMax = -1;
float dir[3];
vsub(dir, p1, p0);
for (int i = 0, j = nverts-1; i < nverts; j=i++)
{
float edge[3], diff[3];
vsub(edge, &verts[i*3], &verts[j*3]);
vsub(diff, p0, &verts[j*3]);
float n = vperp2D(edge, diff);
float d = -vperp2D(edge, dir);
if (fabs(d) < EPS)
{
// S is nearly parallel to this edge
if (n < 0)
return false;
else
continue;
}
float t = n / d;
if (d < 0)
{
// segment S is entering across this edge
if (t > tmin)
{
tmin = t;
segMin = j;
// S enters after leaving polygon
if (tmin > tmax)
return false;
}
}
else
{
// segment S is leaving across this edge
if (t < tmax)
{
tmax = t;
segMax = j;
// S leaves before entering polygon
if (tmax < tmin)
return false;
}
}
}
return true;
}
float distancePtSegSqr2D(const float* pt, const float* p, const float* q, float& t)
{
float pqx = q[0] - p[0];
float pqz = q[2] - p[2];
float dx = pt[0] - p[0];
float dz = pt[2] - p[2];
float d = pqx*pqx + pqz*pqz;
t = pqx*dx + pqz*dz;
if (d > 0)
t /= d;
if (t < 0)
t = 0;
else if (t > 1)
t = 1;
dx = p[0] + t*pqx - pt[0];
dz = p[2] + t*pqz - pt[2];
return dx*dx + dz*dz;
}
void calcPolyCenter(float* tc, const unsigned short* idx, int nidx, const float* verts)
{
tc[0] = 0.0f;
tc[1] = 0.0f;
tc[2] = 0.0f;
for (int j = 0; j < nidx; ++j)
{
const float* v = &verts[idx[j]*3];
tc[0] += v[0];
tc[1] += v[1];
tc[2] += v[2];
}
const float s = 1.0f / nidx;
tc[0] *= s;
tc[1] *= s;
tc[2] *= s;
}
inline float vdot2(const float* a, const float* b)
{
return a[0]*b[0] + a[2]*b[2];
}
#include <stdio.h>
bool closestHeightPointTriangle(const float* p, const float* a, const float* b, const float* c, float& h)
{
float v0[3], v1[3], v2[3];
vsub(v0, c,a);
vsub(v1, b,a);
vsub(v2, p,a);
const float dot00 = vdot2(v0, v0);
const float dot01 = vdot2(v0, v1);
const float dot02 = vdot2(v0, v2);
const float dot11 = vdot2(v1, v1);
const float dot12 = vdot2(v1, v2);
// Compute barycentric coordinates
float invDenom = 1.0f / (dot00 * dot11 - dot01 * dot01);
float u = (dot11 * dot02 - dot01 * dot12) * invDenom;
float v = (dot00 * dot12 - dot01 * dot02) * invDenom;
// The (sloppy) epsilon is needed to allow to get height of points which
// are interpolated along the edges of the triangles.
static const float EPS = 1e-4f;
// If point lies inside the triangle, return interpolated ycoord.
if (u >= -EPS && v >= -EPS && (u+v) <= 1+EPS)
{
h = a[1] + v0[1]*u + v1[1]*v;
return true;
}
return false;
}

@ -0,0 +1,140 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#include "DetourNode.h"
#include <string.h>
//////////////////////////////////////////////////////////////////////////////////////////
dtNodePool::dtNodePool(int maxNodes, int hashSize) :
m_nodes(0),
m_first(0),
m_next(0),
m_maxNodes(maxNodes),
m_hashSize(hashSize),
m_nodeCount(0)
{
m_nodes = new dtNode[m_maxNodes];
m_next = new unsigned short[m_maxNodes];
m_first = new unsigned short[hashSize];
memset(m_first, 0xff, sizeof(unsigned short)*m_hashSize);
memset(m_next, 0xff, sizeof(unsigned short)*m_maxNodes);
}
dtNodePool::~dtNodePool()
{
delete [] m_nodes;
delete [] m_next;
delete [] m_first;
}
void dtNodePool::clear()
{
memset(m_first, 0xff, sizeof(unsigned short)*m_hashSize);
m_nodeCount = 0;
}
const dtNode* dtNodePool::findNode(unsigned int id) const
{
unsigned int bucket = hashint(id) & (m_hashSize-1);
unsigned short i = m_first[bucket];
while (i != 0xffff)
{
if (m_nodes[i].id == id)
return &m_nodes[i];
i = m_next[i];
}
return 0;
}
dtNode* dtNodePool::getNode(unsigned int id)
{
unsigned int bucket = hashint(id) & (m_hashSize-1);
unsigned short i = m_first[bucket];
dtNode* node = 0;
while (i != 0xffff)
{
if (m_nodes[i].id == id)
return &m_nodes[i];
i = m_next[i];
}
if (m_nodeCount >= m_maxNodes)
return 0;
i = (unsigned short)m_nodeCount;
m_nodeCount++;
// Init node
node = &m_nodes[i];
node->pidx = 0;
node->cost = 0;
node->total = 0;
node->id = id;
node->flags = 0;
m_next[i] = m_first[bucket];
m_first[bucket] = i;
return node;
}
//////////////////////////////////////////////////////////////////////////////////////////
dtNodeQueue::dtNodeQueue(int n) :
m_heap(0),
m_capacity(n),
m_size(0)
{
m_heap = new dtNode*[m_capacity+1];
}
dtNodeQueue::~dtNodeQueue()
{
delete [] m_heap;
}
void dtNodeQueue::bubbleUp(int i, dtNode* node)
{
int parent = (i-1)/2;
// note: (index > 0) means there is a parent
while ((i > 0) && (m_heap[parent]->total > node->total))
{
m_heap[i] = m_heap[parent];
i = parent;
parent = (i-1)/2;
}
m_heap[i] = node;
}
void dtNodeQueue::trickleDown(int i, dtNode* node)
{
int child = (i*2)+1;
while (child < m_size)
{
if (((child+1) < m_size) &&
(m_heap[child]->total > m_heap[child+1]->total))
{
child++;
}
m_heap[i] = m_heap[child];
i = child;
child = (i*2)+1;
}
bubbleUp(i, node);
}

@ -0,0 +1,876 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#include <math.h>
#include <float.h>
#include <string.h>
#include <stdio.h>
#include "DetourStatNavMesh.h"
#include "DetourNode.h"
#include "DetourCommon.h"
//////////////////////////////////////////////////////////////////////////////////////////
dtStatNavMesh::dtStatNavMesh() :
m_data(0),
m_dataSize(0),
m_header(0),
m_nodePool(0),
m_openList(0)
{
}
dtStatNavMesh::~dtStatNavMesh()
{
delete m_nodePool;
delete m_openList;
if (m_data)
delete [] m_data;
}
bool dtStatNavMesh::init(unsigned char* data, int dataSize, bool ownsData)
{
dtStatNavMeshHeader* header = (dtStatNavMeshHeader*)data;
if (header->magic != DT_STAT_NAVMESH_MAGIC)
return false;
if (header->version != DT_STAT_NAVMESH_VERSION)
return false;
const int headerSize = sizeof(dtStatNavMeshHeader);
const int vertsSize = sizeof(float)*3*header->nverts;
const int polysSize = sizeof(dtStatPoly)*header->npolys;
const int nodesSize = sizeof(dtStatBVNode)*header->npolys*2;
const int detailMeshesSize = sizeof(dtStatPolyDetail)*header->ndmeshes;
const int detailVertsSize = sizeof(float)*3*header->ndverts;
const int detailTrisSize = sizeof(unsigned char)*4*header->ndtris;
unsigned char* d = data + headerSize;
header->verts = (float*)d; d += vertsSize;
header->polys = (dtStatPoly*)d; d += polysSize;
header->bvtree = (dtStatBVNode*)d; d += nodesSize;
header->dmeshes = (dtStatPolyDetail*)d; d += detailMeshesSize;
header->dverts = (float*)d; d += detailVertsSize;
header->dtris = (unsigned char*)d; d += detailTrisSize;
m_nodePool = new dtNodePool(2048, 256);
if (!m_nodePool)
return false;
m_openList = new dtNodeQueue(2048);
if (!m_openList)
return false;
if (ownsData)
{
m_data = data;
m_dataSize = dataSize;
}
m_header = header;
return true;
}
const dtStatPoly* dtStatNavMesh::getPolyByRef(dtStatPolyRef ref) const
{
if (!m_header || ref == 0 || (int)ref > m_header->npolys) return 0;
return &m_header->polys[ref-1];
}
int dtStatNavMesh::getPolyIndexByRef(dtStatPolyRef ref) const
{
if (!m_header || ref == 0 || (int)ref > m_header->npolys) return -1;
return (int)ref-1;
}
int dtStatNavMesh::findPath(dtStatPolyRef startRef, dtStatPolyRef endRef,
const float* startPos, const float* endPos,
dtStatPolyRef* path, const int maxPathSize)
{
if (!m_header) return 0;
if (!startRef || !endRef)
return 0;
if (!maxPathSize)
return 0;
if (startRef == endRef)
{
path[0] = startRef;
return 1;
}
m_nodePool->clear();
m_openList->clear();
static const float H_SCALE = 1.1f; // Heuristic scale.
dtNode* startNode = m_nodePool->getNode(startRef);
startNode->pidx = 0;
startNode->cost = 0;
startNode->total = vdist(startPos, endPos) * H_SCALE;
startNode->id = startRef;
startNode->flags = DT_NODE_OPEN;
m_openList->push(startNode);
dtNode* lastBestNode = startNode;
float lastBestNodeCost = startNode->total;
while (!m_openList->empty())
{
dtNode* bestNode = m_openList->pop();
if (bestNode->id == endRef)
{
lastBestNode = bestNode;
break;
}
const dtStatPoly* poly = getPoly(bestNode->id-1);
for (int i = 0; i < (int)poly->nv; ++i)
{
dtStatPolyRef neighbour = poly->n[i];
if (neighbour)
{
// Skip parent node.
if (bestNode->pidx && m_nodePool->getNodeAtIdx(bestNode->pidx)->id == neighbour)
continue;
dtNode* parent = bestNode;
dtNode newNode;
newNode.pidx = m_nodePool->getNodeIdx(parent);
newNode.id = neighbour;
// Calculate cost.
float p0[3], p1[3];
if (!parent->pidx)
vcopy(p0, startPos);
else
getEdgeMidPoint(m_nodePool->getNodeAtIdx(parent->pidx)->id, parent->id, p0);
getEdgeMidPoint(parent->id, newNode.id, p1);
newNode.cost = parent->cost + vdist(p0,p1);
// Special case for last node.
if (newNode.id == endRef)
newNode.cost += vdist(p1, endPos);
// Heuristic
const float h = vdist(p1,endPos)*H_SCALE;
newNode.total = newNode.cost + h;
dtNode* actualNode = m_nodePool->getNode(newNode.id);
if (!actualNode)
continue;
if (!((actualNode->flags & DT_NODE_OPEN) && newNode.total > actualNode->total) &&
!((actualNode->flags & DT_NODE_CLOSED) && newNode.total > actualNode->total))
{
actualNode->flags &= ~DT_NODE_CLOSED;
actualNode->pidx = newNode.pidx;
actualNode->cost = newNode.cost;
actualNode->total = newNode.total;
if (h < lastBestNodeCost)
{
lastBestNodeCost = h;
lastBestNode = actualNode;
}
if (actualNode->flags & DT_NODE_OPEN)
{
m_openList->modify(actualNode);
}
else
{
actualNode->flags |= DT_NODE_OPEN;
m_openList->push(actualNode);
}
}
}
}
bestNode->flags |= DT_NODE_CLOSED;
}
// Reverse the path.
dtNode* prev = 0;
dtNode* node = lastBestNode;
do
{
dtNode* next = m_nodePool->getNodeAtIdx(node->pidx);
node->pidx = m_nodePool->getNodeIdx(prev);
prev = node;
node = next;
}
while (node);
// Store path
node = prev;
int n = 0;
do
{
path[n++] = node->id;
node = m_nodePool->getNodeAtIdx(node->pidx);
}
while (node && n < maxPathSize);
return n;
}
bool dtStatNavMesh::closestPointToPoly(dtStatPolyRef ref, const float* pos, float* closest) const
{
int idx = getPolyIndexByRef(ref);
if (idx == -1)
return false;
float closestDistSqr = FLT_MAX;
const dtStatPoly* p = getPoly(idx);
const dtStatPolyDetail* pd = getPolyDetail(idx);
for (int j = 0; j < pd->ntris; ++j)
{
const unsigned char* t = getDetailTri(pd->tbase+j);
const float* v[3];
for (int k = 0; k < 3; ++k)
{
if (t[k] < p->nv)
v[k] = getVertex(p->v[t[k]]);
else
v[k] = getDetailVertex(pd->vbase+(t[k]-p->nv));
}
float pt[3];
closestPtPointTriangle(pt, pos, v[0], v[1], v[2]);
float d = vdistSqr(pos, pt);
if (d < closestDistSqr)
{
vcopy(closest, pt);
closestDistSqr = d;
}
}
return true;
}
bool dtStatNavMesh::getPolyHeight(dtStatPolyRef ref, const float* pos, float* height) const
{
int idx = getPolyIndexByRef(ref);
if (idx == -1)
return false;
const dtStatPoly* p = getPoly(idx);
const dtStatPolyDetail* pd = getPolyDetail(idx);
for (int i = 0; i < pd->ntris; ++i)
{
const unsigned char* t = getDetailTri(pd->tbase+i);
const float* v[3];
for (int j = 0; j < 3; ++j)
{
if (t[j] < p->nv)
v[j] = getVertex(p->v[t[j]]);
else
v[j] = getDetailVertex(pd->vbase+(t[j]-p->nv));
}
float h;
if (closestHeightPointTriangle(pos, v[0], v[1], v[2], h))
{
if (height)
*height = h;
return true;
}
}
return false;
}
int dtStatNavMesh::findStraightPath(const float* startPos, const float* endPos,
const dtStatPolyRef* path, const int pathSize,
float* straightPath, const int maxStraightPathSize)
{
if (!m_header) return 0;
if (!maxStraightPathSize)
return 0;
if (!path[0])
return 0;
int straightPathSize = 0;
float closestStartPos[3];
if (!closestPointToPoly(path[0], startPos, closestStartPos))
return 0;
// Add start point.
vcopy(&straightPath[straightPathSize*3], closestStartPos);
straightPathSize++;
if (straightPathSize >= maxStraightPathSize)
return straightPathSize;
float closestEndPos[3];
if (!closestPointToPoly(path[pathSize-1], endPos, closestEndPos))
return 0;
float portalApex[3], portalLeft[3], portalRight[3];
if (pathSize > 1)
{
vcopy(portalApex, closestStartPos);
vcopy(portalLeft, portalApex);
vcopy(portalRight, portalApex);
int apexIndex = 0;
int leftIndex = 0;
int rightIndex = 0;
for (int i = 0; i < pathSize; ++i)
{
float left[3], right[3];
if (i < pathSize-1)
{
// Next portal.
getPortalPoints(path[i], path[i+1], left, right);
}
else
{
// End of the path.
vcopy(left, closestEndPos);
vcopy(right, closestEndPos);
}
// Right vertex.
if (vequal(portalApex, portalRight))
{
vcopy(portalRight, right);
rightIndex = i;
}
else
{
if (triArea2D(portalApex, portalRight, right) <= 0.0f)
{
if (triArea2D(portalApex, portalLeft, right) > 0.0f)
{
vcopy(portalRight, right);
rightIndex = i;
}
else
{
vcopy(portalApex, portalLeft);
apexIndex = leftIndex;
if (!vequal(&straightPath[(straightPathSize-1)*3], portalApex))
{
vcopy(&straightPath[straightPathSize*3], portalApex);
straightPathSize++;
if (straightPathSize >= maxStraightPathSize)
return straightPathSize;
}
vcopy(portalLeft, portalApex);
vcopy(portalRight, portalApex);
leftIndex = apexIndex;
rightIndex = apexIndex;
// Restart
i = apexIndex;
continue;
}
}
}
// Left vertex.
if (vequal(portalApex, portalLeft))
{
vcopy(portalLeft, left);
leftIndex = i;
}
else
{
if (triArea2D(portalApex, portalLeft, left) >= 0.0f)
{
if (triArea2D(portalApex, portalRight, left) < 0.0f)
{
vcopy(portalLeft, left);
leftIndex = i;
}
else
{
vcopy(portalApex, portalRight);
apexIndex = rightIndex;
if (!vequal(&straightPath[(straightPathSize-1)*3], portalApex))
{
vcopy(&straightPath[straightPathSize*3], portalApex);
straightPathSize++;
if (straightPathSize >= maxStraightPathSize)
return straightPathSize;
}
vcopy(portalLeft, portalApex);
vcopy(portalRight, portalApex);
leftIndex = apexIndex;
rightIndex = apexIndex;
// Restart
i = apexIndex;
continue;
}
}
}
}
}
// Add end point.
vcopy(&straightPath[straightPathSize*3], closestEndPos);
straightPathSize++;
return straightPathSize;
}
int dtStatNavMesh::getPolyVerts(dtStatPolyRef ref, float* verts) const
{
if (!m_header) return 0;
const dtStatPoly* poly = getPolyByRef(ref);
if (!poly) return 0;
float* v = verts;
for (int i = 0; i < (int)poly->nv; ++i)
{
const float* cv = &m_header->verts[poly->v[i]*3];
*v++ = cv[0];
*v++ = cv[1];
*v++ = cv[2];
}
return (int)poly->nv;
}
int dtStatNavMesh::raycast(dtStatPolyRef centerRef, const float* startPos, const float* endPos,
float& t, dtStatPolyRef* path, const int pathSize)
{
if (!m_header) return 0;
if (!centerRef) return 0;
dtStatPolyRef prevRef = centerRef;
dtStatPolyRef curRef = centerRef;
t = 0;
float verts[DT_STAT_VERTS_PER_POLYGON*3];
int n = 0;
while (curRef)
{
// Cast ray against current polygon.
int nv = getPolyVerts(curRef, verts);
if (nv < 3)
{
// Hit bad polygon, report hit.
return n;
}
float tmin, tmax;
int segMin, segMax;
if (!intersectSegmentPoly2D(startPos, endPos, verts, nv, tmin, tmax, segMin, segMax))
{
// Could not a polygon, keep the old t and report hit.
return n;
}
// Keep track of furthest t so far.
if (tmax > t)
t = tmax;
if (n < pathSize)
path[n++] = curRef;
// Check the neighbour of this polygon.
const dtStatPoly* poly = getPolyByRef(curRef);
dtStatPolyRef nextRef = poly->n[segMax];
if (!nextRef)
{
// No neighbour, we hit a wall.
return n;
}
// No hit, advance to neighbour polygon.
prevRef = curRef;
curRef = nextRef;
}
return n;
}
float dtStatNavMesh::findDistanceToWall(dtStatPolyRef centerRef, const float* centerPos, float maxRadius,
float* hitPos, float* hitNormal)
{
if (!m_header) return 0;
if (!centerRef) return 0;
m_nodePool->clear();
m_openList->clear();
dtNode* startNode = m_nodePool->getNode(centerRef);
startNode->pidx = 0;
startNode->cost = 0;
startNode->total = 0;
startNode->id = centerRef;
startNode->flags = DT_NODE_OPEN;
m_openList->push(startNode);
float radiusSqr = sqr(maxRadius);
hitNormal[0] = 1;
hitNormal[1] = 0;
hitNormal[2] = 0;
while (!m_openList->empty())
{
dtNode* bestNode = m_openList->pop();
const dtStatPoly* poly = getPoly(bestNode->id-1);
// Hit test walls.
for (int i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j = i++)
{
// Skip non-solid edges.
if (poly->n[j]) continue;
// Calc distance to the edge.
const float* vj = getVertex(poly->v[j]);
const float* vi = getVertex(poly->v[i]);
float tseg;
float distSqr = distancePtSegSqr2D(centerPos, vj, vi, tseg);
// Edge is too far, skip.
if (distSqr > radiusSqr)
continue;
// Hit wall, update radius.
radiusSqr = distSqr;
// Calculate hit pos.
hitPos[0] = vj[0] + (vi[0] - vj[0])*tseg;
hitPos[1] = vj[1] + (vi[1] - vj[1])*tseg;
hitPos[2] = vj[2] + (vi[2] - vj[2])*tseg;
}
// Check to see if teh circle expands to one of the neighbours and expand.
for (int i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j = i++)
{
// Skip solid edges.
if (!poly->n[j]) continue;
// Expand to neighbour if not visited yet.
dtStatPolyRef neighbour = poly->n[j];
// Skip parent node.
if (bestNode->pidx && m_nodePool->getNodeAtIdx(bestNode->pidx)->id == neighbour)
continue;
// Calc distance to the edge.
const float* vj = getVertex(poly->v[j]);
const float* vi = getVertex(poly->v[i]);
float tseg;
float distSqr = distancePtSegSqr2D(centerPos, vj, vi, tseg);
// Edge is too far, skip.
if (distSqr > radiusSqr)
continue;
dtNode* parent = bestNode;
dtNode newNode;
newNode.pidx = m_nodePool->getNodeIdx(parent);
newNode.id = neighbour;
// Cost
float p0[3], p1[3];
if (!parent->pidx)
vcopy(p0, centerPos);
else
getEdgeMidPoint(m_nodePool->getNodeAtIdx(parent->pidx)->id, parent->id, p0);
getEdgeMidPoint(parent->id, newNode.id, p1);
newNode.total = parent->total + vdist(p0,p1);
dtNode* actualNode = m_nodePool->getNode(newNode.id);
if (!actualNode)
continue;
if (!((actualNode->flags & DT_NODE_OPEN) && newNode.total > actualNode->total) &&
!((actualNode->flags & DT_NODE_CLOSED) && newNode.total > actualNode->total))
{
actualNode->flags &= ~DT_NODE_CLOSED;
actualNode->pidx = newNode.pidx;
actualNode->total = newNode.total;
if (actualNode->flags & DT_NODE_OPEN)
{
m_openList->modify(actualNode);
}
else
{
actualNode->flags |= DT_NODE_OPEN;
m_openList->push(actualNode);
}
}
}
bestNode->flags |= DT_NODE_CLOSED;
}
// Calc hit normal.
vsub(hitNormal, centerPos, hitPos);
vnormalize(hitNormal);
return sqrtf(radiusSqr);
}
int dtStatNavMesh::findPolysAround(dtStatPolyRef centerRef, const float* centerPos, float radius,
dtStatPolyRef* resultRef, dtStatPolyRef* resultParent, float* resultCost,
const int maxResult)
{
if (!m_header) return 0;
if (!centerRef) return 0;
m_nodePool->clear();
m_openList->clear();
dtNode* startNode = m_nodePool->getNode(centerRef);
startNode->pidx = 0;
startNode->cost = 0;
startNode->total = 0;
startNode->id = centerRef;
startNode->flags = DT_NODE_OPEN;
m_openList->push(startNode);
int n = 0;
if (n < maxResult)
{
if (resultRef)
resultRef[n] = startNode->id;
if (resultParent)
resultParent[n] = 0;
if (resultCost)
resultCost[n] = 0;
++n;
}
const float radiusSqr = sqr(radius);
while (!m_openList->empty())
{
dtNode* bestNode = m_openList->pop();
const dtStatPoly* poly = getPoly(bestNode->id-1);
for (unsigned i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j=i++)
{
dtStatPolyRef neighbour = poly->n[j];
if (neighbour)
{
// Skip parent node.
if (bestNode->pidx && m_nodePool->getNodeAtIdx(bestNode->pidx)->id == neighbour)
continue;
// Calc distance to the edge.
const float* vj = getVertex(poly->v[j]);
const float* vi = getVertex(poly->v[i]);
float tseg;
float distSqr = distancePtSegSqr2D(centerPos, vj, vi, tseg);
// If the circle is not touching the next polygon, skip it.
if (distSqr > radiusSqr)
continue;
dtNode* parent = bestNode;
dtNode newNode;
newNode.pidx = m_nodePool->getNodeIdx(parent);
newNode.id = neighbour;
// Cost
float p0[3], p1[3];
if (!parent->pidx)
vcopy(p0, centerPos);
else
getEdgeMidPoint(m_nodePool->getNodeAtIdx(parent->pidx)->id, parent->id, p0);
getEdgeMidPoint(parent->id, newNode.id, p1);
newNode.total = parent->total + vdist(p0,p1);
dtNode* actualNode = m_nodePool->getNode(newNode.id);
if (!actualNode)
continue;
if (!((actualNode->flags & DT_NODE_OPEN) && newNode.total > actualNode->total) &&
!((actualNode->flags & DT_NODE_CLOSED) && newNode.total > actualNode->total))
{
actualNode->flags &= ~DT_NODE_CLOSED;
actualNode->pidx = newNode.pidx;
actualNode->total = newNode.total;
if (actualNode->flags & DT_NODE_OPEN)
{
m_openList->modify(actualNode);
}
else
{
if (n < maxResult)
{
if (resultRef)
resultRef[n] = actualNode->id;
if (resultParent)
resultParent[n] = m_nodePool->getNodeAtIdx(actualNode->pidx)->id;
if (resultCost)
resultCost[n] = actualNode->total;
++n;
}
actualNode->flags |= DT_NODE_OPEN;
m_openList->push(actualNode);
}
}
}
}
bestNode->flags |= DT_NODE_CLOSED;
}
return n;
}
// Returns polygons which are withing certain radius from the query location.
int dtStatNavMesh::queryPolygons(const float* center, const float* extents,
dtStatPolyRef* polys, const int maxIds)
{
if (!m_header) return 0;
const dtStatBVNode* node = &m_header->bvtree[0];
const dtStatBVNode* end = &m_header->bvtree[m_header->nnodes];
// Calculate quantized box
const float ics = 1.0f / m_header->cs;
unsigned short bmin[3], bmax[3];
// Clamp query box to world box.
float minx = clamp(center[0] - extents[0], m_header->bmin[0], m_header->bmax[0]) - m_header->bmin[0];
float miny = clamp(center[1] - extents[1], m_header->bmin[1], m_header->bmax[1]) - m_header->bmin[1];
float minz = clamp(center[2] - extents[2], m_header->bmin[2], m_header->bmax[2]) - m_header->bmin[2];
float maxx = clamp(center[0] + extents[0], m_header->bmin[0], m_header->bmax[0]) - m_header->bmin[0];
float maxy = clamp(center[1] + extents[1], m_header->bmin[1], m_header->bmax[1]) - m_header->bmin[1];
float maxz = clamp(center[2] + extents[2], m_header->bmin[2], m_header->bmax[2]) - m_header->bmin[2];
// Quantize
bmin[0] = (unsigned short)(ics * minx) & 0xfffe;
bmin[1] = (unsigned short)(ics * miny) & 0xfffe;
bmin[2] = (unsigned short)(ics * minz) & 0xfffe;
bmax[0] = (unsigned short)(ics * maxx + 1) | 1;
bmax[1] = (unsigned short)(ics * maxy + 1) | 1;
bmax[2] = (unsigned short)(ics * maxz + 1) | 1;
// Traverse tree
int n = 0;
while (node < end)
{
bool overlap = checkOverlapBox(bmin, bmax, node->bmin, node->bmax);
bool isLeafNode = node->i >= 0;
if (isLeafNode && overlap)
{
if (n < maxIds)
{
polys[n] = (dtStatPolyRef)node->i;
n++;
}
}
if (overlap || isLeafNode)
node++;
else
{
const int escapeIndex = -node->i;
node += escapeIndex;
}
}
return n;
}
dtStatPolyRef dtStatNavMesh::findNearestPoly(const float* center, const float* extents)
{
if (!m_header) return 0;
// Get nearby polygons from proximity grid.
dtStatPolyRef polys[128];
int npolys = queryPolygons(center, extents, polys, 128);
// Find nearest polygon amongst the nearby polygons.
dtStatPolyRef nearest = 0;
float nearestDistanceSqr = FLT_MAX;
for (int i = 0; i < npolys; ++i)
{
dtStatPolyRef ref = polys[i];
float closest[3];
if (!closestPointToPoly(ref, center, closest))
continue;
float d = vdistSqr(center, closest);
if (d < nearestDistanceSqr)
{
nearestDistanceSqr = d;
nearest = ref;
}
}
return nearest;
}
bool dtStatNavMesh::getPortalPoints(dtStatPolyRef from, dtStatPolyRef to, float* left, float* right) const
{
const dtStatPoly* fromPoly = getPolyByRef(from);
if (!fromPoly)
return false;
// Find common edge between the polygons and returns the segment end points.
for (unsigned i = 0, j = (int)fromPoly->nv - 1; i < (int)fromPoly->nv; j = i++)
{
unsigned short neighbour = fromPoly->n[j];
if (neighbour == to)
{
vcopy(left, getVertex(fromPoly->v[j]));
vcopy(right, getVertex(fromPoly->v[i]));
return true;
}
}
return false;
}
bool dtStatNavMesh::getEdgeMidPoint(dtStatPolyRef from, dtStatPolyRef to, float* mid) const
{
float left[3], right[3];
if (!getPortalPoints(from, to, left,right)) return false;
mid[0] = (left[0]+right[0])*0.5f;
mid[1] = (left[1]+right[1])*0.5f;
mid[2] = (left[2]+right[2])*0.5f;
return true;
}
bool dtStatNavMesh::isInClosedList(dtStatPolyRef ref) const
{
if (!m_nodePool) return false;
const dtNode* node = m_nodePool->findNode(ref);
return node && node->flags & DT_NODE_CLOSED;
}
int dtStatNavMesh::getMemUsed() const
{
if (!m_nodePool || ! m_openList)
return 0;
return sizeof(*this) + m_dataSize +
m_nodePool->getMemUsed() +
m_openList->getMemUsed();
}

@ -0,0 +1,346 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "DetourStatNavMesh.h"
struct BVItem
{
unsigned short bmin[3];
unsigned short bmax[3];
int i;
};
static int compareItemX(const void* va, const void* vb)
{
const BVItem* a = (const BVItem*)va;
const BVItem* b = (const BVItem*)vb;
if (a->bmin[0] < b->bmin[0])
return -1;
if (a->bmin[0] > b->bmin[0])
return 1;
return 0;
}
static int compareItemY(const void* va, const void* vb)
{
const BVItem* a = (const BVItem*)va;
const BVItem* b = (const BVItem*)vb;
if (a->bmin[1] < b->bmin[1])
return -1;
if (a->bmin[1] > b->bmin[1])
return 1;
return 0;
}
static int compareItemZ(const void* va, const void* vb)
{
const BVItem* a = (const BVItem*)va;
const BVItem* b = (const BVItem*)vb;
if (a->bmin[2] < b->bmin[2])
return -1;
if (a->bmin[2] > b->bmin[2])
return 1;
return 0;
}
static void calcExtends(BVItem* items, int nitems, int imin, int imax,
unsigned short* bmin, unsigned short* bmax)
{
bmin[0] = items[imin].bmin[0];
bmin[1] = items[imin].bmin[1];
bmin[2] = items[imin].bmin[2];
bmax[0] = items[imin].bmax[0];
bmax[1] = items[imin].bmax[1];
bmax[2] = items[imin].bmax[2];
for (int i = imin+1; i < imax; ++i)
{
const BVItem& it = items[i];
if (it.bmin[0] < bmin[0]) bmin[0] = it.bmin[0];
if (it.bmin[1] < bmin[1]) bmin[1] = it.bmin[1];
if (it.bmin[2] < bmin[2]) bmin[2] = it.bmin[2];
if (it.bmax[0] > bmax[0]) bmax[0] = it.bmax[0];
if (it.bmax[1] > bmax[1]) bmax[1] = it.bmax[1];
if (it.bmax[2] > bmax[2]) bmax[2] = it.bmax[2];
}
}
inline int longestAxis(unsigned short x, unsigned short y, unsigned short z)
{
int axis = 0;
unsigned short maxVal = x;
if (y > maxVal)
{
axis = 1;
maxVal = y;
}
if (z > maxVal)
{
axis = 2;
maxVal = z;
}
return axis;
}
static void subdivide(BVItem* items, int nitems, int imin, int imax, int& curNode, dtStatBVNode* nodes)
{
int inum = imax - imin;
int icur = curNode;
dtStatBVNode& node = nodes[curNode++];
if (inum == 1)
{
// Leaf
node.bmin[0] = items[imin].bmin[0];
node.bmin[1] = items[imin].bmin[1];
node.bmin[2] = items[imin].bmin[2];
node.bmax[0] = items[imin].bmax[0];
node.bmax[1] = items[imin].bmax[1];
node.bmax[2] = items[imin].bmax[2];
node.i = items[imin].i;
}
else
{
// Split
calcExtends(items, nitems, imin, imax, node.bmin, node.bmax);
int axis = longestAxis(node.bmax[0] - node.bmin[0],
node.bmax[1] - node.bmin[1],
node.bmax[2] - node.bmin[2]);
if (axis == 0)
{
// Sort along x-axis
qsort(items+imin, inum, sizeof(BVItem), compareItemX);
}
else if (axis == 1)
{
// Sort along y-axis
qsort(items+imin, inum, sizeof(BVItem), compareItemY);
}
else
{
// Sort along z-axis
qsort(items+imin, inum, sizeof(BVItem), compareItemZ);
}
int isplit = imin+inum/2;
// Left
subdivide(items, nitems, imin, isplit, curNode, nodes);
// Right
subdivide(items, nitems, isplit, imax, curNode, nodes);
int iescape = curNode - icur;
// Negative index means escape.
node.i = -iescape;
}
}
/*static*/ int createBVTree(const unsigned short* verts, const int nverts,
const unsigned short* polys, const int npolys, const int nvp,
float cs, float ch,
int nnodes, dtStatBVNode* nodes)
{
// Build tree
BVItem* items = new BVItem[npolys];
for (int i = 0; i < npolys; i++)
{
BVItem& it = items[i];
it.i = i+1;
// Calc polygon bounds.
const unsigned short* p = &polys[i*nvp*2];
it.bmin[0] = it.bmax[0] = verts[p[0]*3+0];
it.bmin[1] = it.bmax[1] = verts[p[0]*3+1];
it.bmin[2] = it.bmax[2] = verts[p[0]*3+2];
for (int j = 1; j < nvp; ++j)
{
if (p[j] == 0xffff) break;
unsigned short x = verts[p[j]*3+0];
unsigned short y = verts[p[j]*3+1];
unsigned short z = verts[p[j]*3+2];
if (x < it.bmin[0]) it.bmin[0] = x;
if (y < it.bmin[1]) it.bmin[1] = y;
if (z < it.bmin[2]) it.bmin[2] = z;
if (x > it.bmax[0]) it.bmax[0] = x;
if (y > it.bmax[1]) it.bmax[1] = y;
if (z > it.bmax[2]) it.bmax[2] = z;
}
// Remap y
it.bmin[1] = (unsigned short)floorf((float)it.bmin[1]*ch/cs);
it.bmax[1] = (unsigned short)ceilf((float)it.bmax[1]*ch/cs);
}
int curNode = 0;
subdivide(items, npolys, 0, npolys, curNode, nodes);
delete [] items;
return curNode;
}
bool dtCreateNavMeshData(const unsigned short* verts, const int nverts,
const unsigned short* polys, const int npolys, const int nvp,
const float* bmin, const float* bmax, float cs, float ch,
const unsigned short* dmeshes, const float* dverts, const int ndverts,
const unsigned char* dtris, const int ndtris,
unsigned char** outData, int* outDataSize)
{
if (nvp > DT_STAT_VERTS_PER_POLYGON)
return false;
if (nverts >= 0xffff)
return false;
if (!nverts)
return false;
if (!npolys)
return false;
if (!dmeshes || !dverts || ! dtris)
return false;
// Find unique detail vertices.
int uniqueDetailVerts = 0;
if (dmeshes)
{
for (int i = 0; i < npolys; ++i)
{
const unsigned short* p = &polys[i*nvp*2];
int ndv = dmeshes[i*4+1];
int nv = 0;
for (int j = 0; j < nvp; ++j)
{
if (p[j] == 0xffff) break;
nv++;
}
ndv -= nv;
uniqueDetailVerts += ndv;
}
}
// Calculate data size
const int headerSize = sizeof(dtStatNavMeshHeader);
const int vertsSize = sizeof(float)*3*nverts;
const int polysSize = sizeof(dtStatPoly)*npolys;
const int nodesSize = sizeof(dtStatBVNode)*npolys*2;
const int detailMeshesSize = sizeof(dtStatPolyDetail)*npolys;
const int detailVertsSize = sizeof(float)*3*uniqueDetailVerts;
const int detailTrisSize = sizeof(unsigned char)*4*ndtris;
const int dataSize = headerSize + vertsSize + polysSize + nodesSize +
detailMeshesSize + detailVertsSize + detailTrisSize;
unsigned char* data = new unsigned char[dataSize];
if (!data)
return false;
memset(data, 0, dataSize);
unsigned char* d = data;
dtStatNavMeshHeader* header = (dtStatNavMeshHeader*)d; d += headerSize;
float* navVerts = (float*)d; d += vertsSize;
dtStatPoly* navPolys = (dtStatPoly*)d; d += polysSize;
dtStatBVNode* navNodes = (dtStatBVNode*)d; d += nodesSize;
dtStatPolyDetail* navDMeshes = (dtStatPolyDetail*)d; d += detailMeshesSize;
float* navDVerts = (float*)d; d += detailVertsSize;
unsigned char* navDTris = (unsigned char*)d; d += detailTrisSize;
// Store header
header->magic = DT_STAT_NAVMESH_MAGIC;
header->version = DT_STAT_NAVMESH_VERSION;
header->npolys = npolys;
header->nverts = nverts;
header->cs = cs;
header->bmin[0] = bmin[0];
header->bmin[1] = bmin[1];
header->bmin[2] = bmin[2];
header->bmax[0] = bmax[0];
header->bmax[1] = bmax[1];
header->bmax[2] = bmax[2];
header->ndmeshes = dmeshes ? npolys : 0;
header->ndverts = dmeshes ? uniqueDetailVerts : 0;
header->ndtris = dmeshes ? ndtris : 0;
// Store vertices
for (int i = 0; i < nverts; ++i)
{
const unsigned short* iv = &verts[i*3];
float* v = &navVerts[i*3];
v[0] = bmin[0] + iv[0] * cs;
v[1] = bmin[1] + iv[1] * ch;
v[2] = bmin[2] + iv[2] * cs;
}
// Store polygons
const unsigned short* src = polys;
for (int i = 0; i < npolys; ++i)
{
dtStatPoly* p = &navPolys[i];
p->nv = 0;
for (int j = 0; j < nvp; ++j)
{
if (src[j] == 0xffff) break;
p->v[j] = src[j];
p->n[j] = src[nvp+j]+1;
p->nv++;
}
src += nvp*2;
}
header->nnodes = createBVTree(verts, nverts, polys, npolys, nvp,
cs, ch, npolys*2, navNodes);
// Store detail meshes and vertices.
// The nav polygon vertices are stored as the first vertices on each mesh.
// We compress the mesh data by skipping them and using the navmesh coordinates.
unsigned short vbase = 0;
for (int i = 0; i < npolys; ++i)
{
dtStatPolyDetail& dtl = navDMeshes[i];
const int vb = dmeshes[i*4+0];
const int ndv = dmeshes[i*4+1];
const int nv = navPolys[i].nv;
dtl.vbase = vbase;
dtl.nverts = ndv-nv;
dtl.tbase = dmeshes[i*4+2];
dtl.ntris = dmeshes[i*4+3];
// Copy vertices except the first 'nv' verts which are equal to nav poly verts.
if (ndv-nv)
{
memcpy(&navDVerts[vbase*3], &dverts[(vb+nv)*3], sizeof(float)*3*(ndv-nv));
vbase += ndv-nv;
}
}
// Store triangles.
memcpy(navDTris, dtris, sizeof(unsigned char)*4*ndtris);
*outData = data;
*outDataSize = dataSize;
return true;
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,213 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "DetourTileNavMesh.h"
#include "DetourCommon.h"
bool dtCreateNavMeshTileData(const unsigned short* verts, const int nverts,
const unsigned short* polys, const int npolys, const int nvp,
const unsigned short* dmeshes, const float* dverts, const int ndverts,
const unsigned char* dtris, const int ndtris,
const float* bmin, const float* bmax, float cs, float ch, int tileSize, int walkableClimb,
unsigned char** outData, int* outDataSize)
{
if (nvp != DT_TILE_VERTS_PER_POLYGON)
return false;
if (nverts >= 0xffff)
return false;
if (!nverts)
return false;
if (!npolys)
return false;
if (!dmeshes || !dverts || ! dtris)
return false;
// Find portal edges which are at tile borders.
int nedges = 0;
int nportals = 0;
for (int i = 0; i < npolys; ++i)
{
const unsigned short* p = &polys[i*2*nvp];
for (int j = 0; j < nvp; ++j)
{
if (p[j] == 0xffff) break;
int nj = j+1;
if (nj >= nvp || p[nj] == 0xffff) nj = 0;
const unsigned short* va = &verts[p[j]*3];
const unsigned short* vb = &verts[p[nj]*3];
nedges++;
if (va[0] == tileSize && vb[0] == tileSize)
nportals++; // x+
else if (va[2] == tileSize && vb[2] == tileSize)
nportals++; // z+
else if (va[0] == 0 && vb[0] == 0)
nportals++; // x-
else if (va[2] == 0 && vb[2] == 0)
nportals++; // z-
}
}
const int maxLinks = nedges + nportals*2;
// Find unique detail vertices.
int uniqueDetailVerts = 0;
if (dmeshes)
{
for (int i = 0; i < npolys; ++i)
{
const unsigned short* p = &polys[i*nvp*2];
int ndv = dmeshes[i*4+1];
int nv = 0;
for (int j = 0; j < nvp; ++j)
{
if (p[j] == 0xffff) break;
nv++;
}
ndv -= nv;
uniqueDetailVerts += ndv;
}
}
// Calculate data size
const int headerSize = sizeof(dtTileHeader);
const int vertsSize = sizeof(float)*3*nverts;
const int polysSize = sizeof(dtTilePoly)*npolys;
const int linksSize = sizeof(dtTileLink)*maxLinks;
const int detailMeshesSize = sizeof(dtTilePolyDetail)*npolys;
const int detailVertsSize = sizeof(float)*3*uniqueDetailVerts;
const int detailTrisSize = sizeof(unsigned char)*4*ndtris;
const int dataSize = headerSize + vertsSize + polysSize + linksSize +
detailMeshesSize + detailVertsSize + detailTrisSize;
unsigned char* data = new unsigned char[dataSize];
if (!data)
return false;
memset(data, 0, dataSize);
unsigned char* d = data;
dtTileHeader* header = (dtTileHeader*)d; d += headerSize;
float* navVerts = (float*)d; d += vertsSize;
dtTilePoly* navPolys = (dtTilePoly*)d; d += polysSize;
d += linksSize;
dtTilePolyDetail* navDMeshes = (dtTilePolyDetail*)d; d += detailMeshesSize;
float* navDVerts = (float*)d; d += detailVertsSize;
unsigned char* navDTris = (unsigned char*)d; d += detailTrisSize;
// Store header
header->magic = DT_TILE_NAVMESH_MAGIC;
header->version = DT_TILE_NAVMESH_VERSION;
header->npolys = npolys;
header->nverts = nverts;
header->maxlinks = maxLinks;
header->bmin[0] = bmin[0];
header->bmin[1] = bmin[1];
header->bmin[2] = bmin[2];
header->bmax[0] = bmax[0];
header->bmax[1] = bmax[1];
header->bmax[2] = bmax[2];
header->ndmeshes = npolys;
header->ndverts = uniqueDetailVerts;
header->ndtris = ndtris;
// Store vertices
for (int i = 0; i < nverts; ++i)
{
const unsigned short* iv = &verts[i*3];
float* v = &navVerts[i*3];
v[0] = bmin[0] + iv[0] * cs;
v[1] = bmin[1] + iv[1] * ch;
v[2] = bmin[2] + iv[2] * cs;
}
// Store polygons
const unsigned short* src = polys;
for (int i = 0; i < npolys; ++i)
{
dtTilePoly* p = &navPolys[i];
p->nv = 0;
for (int j = 0; j < nvp; ++j)
{
if (src[j] == 0xffff) break;
p->v[j] = src[j];
p->n[j] = (src[nvp+j]+1) & 0xffff;
p->nv++;
}
src += nvp*2;
}
// Store portal edges.
for (int i = 0; i < npolys; ++i)
{
dtTilePoly* poly = &navPolys[i];
for (int j = 0; j < poly->nv; ++j)
{
int nj = j+1;
if (nj >= poly->nv) nj = 0;
const unsigned short* va = &verts[poly->v[j]*3];
const unsigned short* vb = &verts[poly->v[nj]*3];
if (va[0] == tileSize && vb[0] == tileSize) // x+
poly->n[j] = 0x8000 | 0;
else if (va[2] == tileSize && vb[2] == tileSize) // z+
poly->n[j] = 0x8000 | 1;
else if (va[0] == 0 && vb[0] == 0) // x-
poly->n[j] = 0x8000 | 2;
else if (va[2] == 0 && vb[2] == 0) // z-
poly->n[j] = 0x8000 | 3;
}
}
// Store detail meshes and vertices.
// The nav polygon vertices are stored as the first vertices on each mesh.
// We compress the mesh data by skipping them and using the navmesh coordinates.
unsigned short vbase = 0;
for (int i = 0; i < npolys; ++i)
{
dtTilePolyDetail& dtl = navDMeshes[i];
const int vb = dmeshes[i*4+0];
const int ndv = dmeshes[i*4+1];
const int nv = navPolys[i].nv;
dtl.vbase = vbase;
dtl.nverts = ndv-nv;
dtl.tbase = dmeshes[i*4+2];
dtl.ntris = dmeshes[i*4+3];
// Copy vertices except the first 'nv' verts which are equal to nav poly verts.
if (ndv-nv)
{
memcpy(&navDVerts[vbase*3], &dverts[(vb+nv)*3], sizeof(float)*3*(ndv-nv));
vbase += ndv-nv;
}
}
// Store triangles.
memcpy(navDTris, dtris, sizeof(unsigned char)*4*ndtris);
*outData = data;
*outDataSize = dataSize;
return true;
}

18
extern/recastnavigation/License.txt vendored Normal file

@ -0,0 +1,18 @@
Copyright (c) 2009 Mikko Mononen memon@inside.org
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

120
extern/recastnavigation/Readme.txt vendored Normal file

@ -0,0 +1,120 @@
Recast & Detour Version 1.4
Recast
Recast is state of the art navigation mesh construction toolset for games.
* It is automatic, which means that you can throw any level geometry
at it and you will get robust mesh out
* It is fast which means swift turnaround times for level designers
* It is open source so it comes with full source and you can
customize it to your hearts content.
The Recast process starts with constructing a voxel mold from a level geometry
and then casting a navigation mesh over it. The process consists of three steps,
building the voxel mold, partitioning the mold into simple regions, peeling off
the regions as simple polygons.
1. The voxel mold is build from the input triangle mesh by rasterizing
the triangles into a multi-layer heightfield. Some simple filters are
then applied to the mold to prune out locations where the character
would not be able to move.
2. The walkable areas described by the mold are divided into simple
overlayed 2D regions. The resulting regions have only one non-overlapping
contour, which simplifies the final step of the process tremendously.
3. The navigation polygons are peeled off from the regions by first tracing
the boundaries and then simplifying them. The resulting polygons are
finally converted to convex polygons which makes them perfect for
pathfinding and spatial reasoning about the level.
The toolset code is located in the Recast folder and demo application using the Recast
toolset is located in the RecastDemo folder.
The project files with this distribution can be compiled with Microsoft Visual C++ 2008
(you can download it for free) and XCode 3.1.
Detour
Recast is accompanied with Detour, path-finding and spatial reasoning toolkit. You can use any navigation mesh with Detour, but of course the data generated with Recast fits perfectly.
Detour offers simple static navigation mesh which is suitable for many simple cases, as well as tiled navigation mesh which allows you to plug in and out pieces of the mesh. The tiled mesh allows to create systems where you stream new navigation data in and out as the player progresses the level, or you may regenerate tiles as the world changes.
Latest code available at http://code.google.com/p/recastnavigation/
--
Release Notes
----------------
* Recast 1.4
Released August 24th, 2009
- Added detail height mesh generation (RecastDetailMesh.cpp) for single,
tiled statmeshes as well as tilemesh.
- Added feature to contour tracing which detects extra vertices along
tile edges which should be removed later.
- Changed the tiled stat mesh preprocess, so that it first generated
polymeshes per tile and finally combines them.
- Fixed bug in the GUI code where invisible buttons could be pressed.
----------------
* Recast 1.31
Released July 24th, 2009
- Better cost and heuristic functions.
- Fixed tile navmesh raycast on tile borders.
----------------
* Recast 1.3
Released July 14th, 2009
- Added dtTileNavMesh which allows to dynamically add and remove navmesh pieces at runtime.
- Renamed stat navmesh types to dtStat* (i.e. dtPoly is now dtStatPoly).
- Moved common code used by tile and stat navmesh to DetourNode.h/cpp and DetourCommon.h/cpp.
- Refactores the demo code.
----------------
* Recast 1.2
Released June 17th, 2009
- Added tiled mesh generation. The tiled generation allows to generate navigation for
much larger worlds, it removes some of the artifacts that comes from distance fields
in open areas, and allows later streaming and dynamic runtime generation
- Improved and added some debug draw modes
- API change: The helper function rcBuildNavMesh does not exists anymore,
had to change few internal things to cope with the tiled processing,
similar API functionality will be added later once the tiled process matures
- The demo is getting way too complicated, need to split demos
- Fixed several filtering functions so that the mesh is tighter to the geometry,
sometimes there could be up error up to tow voxel units close to walls,
now it should be just one.
----------------
* Recast 1.1
Released April 11th, 2009
This is the first release of Detour.
----------------
* Recast 1.0
Released March 29th, 2009
This is the first release of Recast.
The process is not always as robust as I would wish. The watershed phase sometimes swallows tiny islands
which are close to edges. These droppings are handled in rcBuildContours, but the code is not
particularly robust either.
Another non-robust case is when portal contours (contours shared between two regions) are always
assumed to be straight. That can lead to overlapping contours specially when the level has
large open areas.
Mikko Mononen
memon@inside.org

@ -0,0 +1,501 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef RECAST_H
#define RECAST_H
// The units of the parameters are specified in parenthesis as follows:
// (vx) voxels, (wu) world units
struct rcConfig
{
int width, height; // Dimensions of the rasterized heighfield (vx)
int tileSize; // Width and Height of a tile (vx)
int borderSize; // Non-navigable Border around the heightfield (vx)
float cs, ch; // Grid cell size and height (wu)
float bmin[3], bmax[3]; // Grid bounds (wu)
float walkableSlopeAngle; // Maximum walkble slope angle in degrees.
int walkableHeight; // Minimum height where the agent can still walk (vx)
int walkableClimb; // Maximum height between grid cells the agent can climb (vx)
int walkableRadius; // Radius of the agent in cells (vx)
int maxEdgeLen; // Maximum contour edge length (vx)
float maxSimplificationError; // Maximum distance error from contour to cells (vx)
int minRegionSize; // Minimum regions size. Smaller regions will be deleted (vx)
int mergeRegionSize; // Minimum regions size. Smaller regions will be merged (vx)
int maxVertsPerPoly; // Max number of vertices per polygon
float detailSampleDist; // Detail mesh sample spacing.
float detailSampleMaxError; // Detail mesh simplification max sample error.
};
// Heightfield span.
struct rcSpan
{
unsigned int smin : 15; // Span min height.
unsigned int smax : 15; // Span max height.
unsigned int flags : 2; // Span flags.
rcSpan* next; // Next span in column.
};
static const int RC_SPANS_PER_POOL = 2048;
// Memory pool used for quick span allocation.
struct rcSpanPool
{
rcSpanPool* next; // Pointer to next pool.
rcSpan items[1]; // Array of spans (size RC_SPANS_PER_POOL).
};
// Dynamic span-heightfield.
struct rcHeightfield
{
inline rcHeightfield() : width(0), height(0), spans(0), pools(0), freelist(0) {}
inline ~rcHeightfield()
{
// Delete span array.
delete [] spans;
// Delete span pools.
while (pools)
{
rcSpanPool* next = pools->next;
delete [] reinterpret_cast<unsigned char*>(pools);
pools = next;
}
}
int width, height; // Dimension of the heightfield.
float bmin[3], bmax[3]; // Bounding box of the heightfield
float cs, ch; // Cell size and height.
rcSpan** spans; // Heightfield of spans (width*height).
rcSpanPool* pools; // Linked list of span pools.
rcSpan* freelist; // Pointer to next free span.
};
struct rcCompactCell
{
unsigned int index : 24; // Index to first span in column.
unsigned int count : 8; // Number of spans in this column.
};
struct rcCompactSpan
{
unsigned short y; // Bottom coordinate of the span.
unsigned short reg; // Region ID
unsigned short dist; // Distance to border
unsigned short con; // Connections to neighbour cells.
unsigned char h; // Height of the span.
unsigned char flags; // Flags.
};
// Compact static heightfield.
struct rcCompactHeightfield
{
inline rcCompactHeightfield() : maxDistance(0), maxRegions(0), cells(0), spans(0) {}
inline ~rcCompactHeightfield() { delete [] cells; delete [] spans; }
int width, height; // Width and height of the heighfield.
int spanCount; // Number of spans in the heightfield.
int walkableHeight, walkableClimb; // Agent properties.
unsigned short maxDistance; // Maximum distance value stored in heightfield.
unsigned short maxRegions; // Maximum Region Id stored in heightfield.
float bmin[3], bmax[3]; // Bounding box of the heightfield.
float cs, ch; // Cell size and height.
rcCompactCell* cells; // Pointer to width*height cells.
rcCompactSpan* spans; // Pointer to spans.
};
struct rcContour
{
inline rcContour() : verts(0), nverts(0), rverts(0), nrverts(0) { }
inline ~rcContour() { delete [] verts; delete [] rverts; }
int* verts; // Vertex coordinates, each vertex contains 4 components.
int nverts; // Number of vertices.
int* rverts; // Raw vertex coordinates, each vertex contains 4 components.
int nrverts; // Number of raw vertices.
unsigned short reg; // Region ID of the contour.
};
struct rcContourSet
{
inline rcContourSet() : conts(0), nconts(0) {}
inline ~rcContourSet() { delete [] conts; }
rcContour* conts; // Pointer to all contours.
int nconts; // Number of contours.
float bmin[3], bmax[3]; // Bounding box of the heightfield.
float cs, ch; // Cell size and height.
};
// Polymesh store a connected mesh of polygons.
// The polygons are store in an array where each polygons takes
// 'nvp*2' elements. The first 'nvp' elements are indices to vertices
// and the second 'nvp' elements are indices to neighbour polygons.
// If a polygona has less than 'bvp' vertices, the remaining indices
// are set os 0xffff. If an polygon edge does not have a neighbour
// the neighbour index is set to 0xffff.
// Vertices can be transformed into world space as follows:
// x = bmin[0] + verts[i*3+0]*cs;
// y = bmin[1] + verts[i*3+1]*ch;
// z = bmin[2] + verts[i*3+2]*cs;
struct rcPolyMesh
{
inline rcPolyMesh() : verts(0), polys(0), regs(0), nverts(0), npolys(0), nvp(3) {}
inline ~rcPolyMesh() { delete [] verts; delete [] polys; delete [] regs; }
unsigned short* verts; // Vertices of the mesh, 3 elements per vertex.
unsigned short* polys; // Polygons of the mesh, nvp*2 elements per polygon.
unsigned short* regs; // Regions of the polygons.
int nverts; // Number of vertices.
int npolys; // Number of polygons.
int nvp; // Max number of vertices per polygon.
float bmin[3], bmax[3]; // Bounding box of the mesh.
float cs, ch; // Cell size and height.
};
// Detail mesh generated from a rcPolyMesh.
// Each submesh represents a polygon in the polymesh and they are stored in
// excatly same order. Each submesh is described as 4 values:
// base vertex, vertex count, base triangle, triangle count. That is,
// const unsigned char* t = &dtl.tris[(tbase+i)*3]; and
// const float* v = &dtl.verts[(vbase+t[j])*3];
// If the input polygon has 'n' vertices, those vertices are first in the
// submesh vertex list. This allows to compres the mesh by not storing the
// first vertices and using the polymesh vertices instead.
struct rcPolyMeshDetail
{
inline rcPolyMeshDetail() :
meshes(0), verts(0), tris(0),
nmeshes(0), nverts(0), ntris(0) {}
inline ~rcPolyMeshDetail()
{
delete [] meshes; delete [] verts; delete [] tris;
}
unsigned short* meshes; // Pointer to all mesh data.
float* verts; // Pointer to all vertex data.
unsigned char* tris; // Pointer to all triangle data.
int nmeshes; // Number of meshes.
int nverts; // Number of total vertices.
int ntris; // Number of triangles.
};
// Simple dynamic array ints.
class rcIntArray
{
int* m_data;
int m_size, m_cap;
public:
inline rcIntArray() : m_data(0), m_size(0), m_cap(0) {}
inline rcIntArray(int n) : m_data(0), m_size(0), m_cap(n) { m_data = new int[n]; }
inline ~rcIntArray() { delete [] m_data; }
void resize(int n);
inline void push(int item) { resize(m_size+1); m_data[m_size-1] = item; }
inline int pop() { if (m_size > 0) m_size--; return m_data[m_size]; }
inline const int& operator[](int i) const { return m_data[i]; }
inline int& operator[](int i) { return m_data[i]; }
inline int size() const { return m_size; }
};
enum rcSpanFlags
{
RC_WALKABLE = 0x01,
RC_REACHABLE = 0x02,
};
// If heightfield region ID has the following bit set, the region is on border area
// and excluded from many calculations.
static const unsigned short RC_BORDER_REG = 0x8000;
// If contour region ID has the following bit set, the vertex will be later
// removed in order to match the segments and vertices at tile boundaries.
static const int RC_BORDER_VERTEX = 0x10000;
// Compact span neighbour helpers.
inline int rcGetCon(const rcCompactSpan& s, int dir)
{
return (s.con >> (dir*4)) & 0xf;
}
inline int rcGetDirOffsetX(int dir)
{
const int offset[4] = { -1, 0, 1, 0, };
return offset[dir&0x03];
}
inline int rcGetDirOffsetY(int dir)
{
const int offset[4] = { 0, 1, 0, -1 };
return offset[dir&0x03];
}
// Common helper functions
template<class T> inline void rcSwap(T& a, T& b) { T t = a; a = b; b = t; }
template<class T> inline T rcMin(T a, T b) { return a < b ? a : b; }
template<class T> inline T rcMax(T a, T b) { return a > b ? a : b; }
template<class T> inline T rcAbs(T a) { return a < 0 ? -a : a; }
template<class T> inline T rcSqr(T a) { return a*a; }
template<class T> inline T rcClamp(T v, T mn, T mx) { return v < mn ? mn : (v > mx ? mx : v); }
// Common vector helper functions.
inline void vcross(float* dest, const float* v1, const float* v2)
{
dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
dest[2] = v1[0]*v2[1] - v1[1]*v2[0];
}
inline float vdot(const float* v1, const float* v2)
{
return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
}
inline void vmad(float* dest, const float* v1, const float* v2, const float s)
{
dest[0] = v1[0]+v2[0]*s;
dest[1] = v1[1]+v2[1]*s;
dest[2] = v1[2]+v2[2]*s;
}
inline void vadd(float* dest, const float* v1, const float* v2)
{
dest[0] = v1[0]+v2[0];
dest[1] = v1[1]+v2[1];
dest[2] = v1[2]+v2[2];
}
inline void vsub(float* dest, const float* v1, const float* v2)
{
dest[0] = v1[0]-v2[0];
dest[1] = v1[1]-v2[1];
dest[2] = v1[2]-v2[2];
}
inline void vmin(float* mn, const float* v)
{
mn[0] = rcMin(mn[0], v[0]);
mn[1] = rcMin(mn[1], v[1]);
mn[2] = rcMin(mn[2], v[2]);
}
inline void vmax(float* mx, const float* v)
{
mx[0] = rcMax(mx[0], v[0]);
mx[1] = rcMax(mx[1], v[1]);
mx[2] = rcMax(mx[2], v[2]);
}
inline void vcopy(float* dest, const float* v)
{
dest[0] = v[0];
dest[1] = v[1];
dest[2] = v[2];
}
inline float vdist(const float* v1, const float* v2)
{
float dx = v2[0] - v1[0];
float dy = v2[1] - v1[1];
float dz = v2[2] - v1[2];
return sqrtf(dx*dx + dy*dy + dz*dz);
}
inline float vdistSqr(const float* v1, const float* v2)
{
float dx = v2[0] - v1[0];
float dy = v2[1] - v1[1];
float dz = v2[2] - v1[2];
return dx*dx + dy*dy + dz*dz;
}
inline void vnormalize(float* v)
{
float d = 1.0f / sqrtf(rcSqr(v[0]) + rcSqr(v[1]) + rcSqr(v[2]));
v[0] *= d;
v[1] *= d;
v[2] *= d;
}
inline bool vequal(const float* p0, const float* p1)
{
static const float thr = rcSqr(1.0f/16384.0f);
const float d = vdistSqr(p0, p1);
return d < thr;
}
// Calculated bounding box of array of vertices.
// Params:
// verts - (in) array of vertices
// nv - (in) vertex count
// bmin, bmax - (out) bounding box
void rcCalcBounds(const float* verts, int nv, float* bmin, float* bmax);
// Calculates grid size based on bounding box and grid cell size.
// Params:
// bmin, bmax - (in) bounding box
// cs - (in) grid cell size
// w - (out) grid width
// h - (out) grid height
void rcCalcGridSize(const float* bmin, const float* bmax, float cs, int* w, int* h);
// Creates and initializes new heightfield.
// Params:
// hf - (in/out) heightfield to initialize.
// width - (in) width of the heightfield.
// height - (in) height of the heightfield.
// bmin, bmax - (in) bounding box of the heightfield
// cs - (in) grid cell size
// ch - (in) grid cell height
bool rcCreateHeightfield(rcHeightfield& hf, int width, int height,
const float* bmin, const float* bmax,
float cs, float ch);
// Sets the WALKABLE flag for every triangle whose slope is below
// the maximun walkable slope angle.
// Params:
// walkableSlopeAngle - (in) maximun slope angle in degrees.
// verts - (in) array of vertices
// nv - (in) vertex count
// tris - (in) array of triangle vertex indices
// nt - (in) triangle count
// flags - (out) array of triangle flags
void rcMarkWalkableTriangles(const float walkableSlopeAngle,
const float* verts, int nv,
const int* tris, int nt,
unsigned char* flags);
// Rasterizes a triangle into heightfield spans.
// Params:
// v0,v1,v2 - (in) the vertices of the triangle.
// flags - (in) triangle flags (uses WALKABLE)
// solid - (in) heighfield where the triangle is rasterized
void rcRasterizeTriangle(const float* v0, const float* v1, const float* v2,
unsigned char flags, rcHeightfield& solid);
// Rasterizes the triangles into heightfield spans.
// Params:
// verts - (in) array of vertices
// nv - (in) vertex count
// tris - (in) array of triangle vertex indices
// norms - (in) array of triangle normals
// flags - (in) array of triangle flags (uses WALKABLE)
// nt - (in) triangle count
// solid - (in) heighfield where the triangles are rasterized
void rcRasterizeTriangles(const float* verts, int nv,
const int* tris, const unsigned char* flags, int nt,
rcHeightfield& solid);
// Removes WALKABLE flag from all spans that are at ledges. This filtering
// removes possible overestimation of the conservative voxelization so that
// the resulting mesh will not have regions hanging in air over ledges.
// Params:
// walkableHeight - (in) minimum height where the agent can still walk
// walkableClimb - (in) maximum height between grid cells the agent can climb
// solid - (in/out) heightfield describing the solid space
void rcFilterLedgeSpans(const int walkableHeight,
const int walkableClimb,
rcHeightfield& solid);
// Removes WALKABLE flag from all spans which have smaller than
// 'walkableHeight' clearane above them.
// Params:
// walkableHeight - (in) minimum height where the agent can still walk
// solid - (in/out) heightfield describing the solid space
void rcFilterWalkableLowHeightSpans(int walkableHeight,
rcHeightfield& solid);
// Marks spans which are reachable from any of the topmost spans.
// Params:
// walkableHeight - (in) minimum height where the agent can still walk
// walkableClimb - (in) maximum height between grid cells the agent can climb
// solid - (in/out) heightfield describing the solid space
// Returns false if operation ran out of memory.
bool rcMarkReachableSpans(const int walkableHeight,
const int walkableClimb,
rcHeightfield& solid);
// Builds compact representation of the heightfield.
// Params:
// walkableHeight - (in) minimum height where the agent can still walk
// walkableClimb - (in) maximum height between grid cells the agent can climb
// hf - (in) heightfield to be compacted
// chf - (out) compact heightfield representing the open space.
// Returns false if operation ran out of memory.
bool rcBuildCompactHeightfield(const int walkableHeight, const int walkableClimb,
unsigned char flags,
rcHeightfield& hf,
rcCompactHeightfield& chf);
// Builds distance field and stores it into the combat heightfield.
// Params:
// chf - (in/out) compact heightfield representing the open space.
// Returns false if operation ran out of memory.
bool rcBuildDistanceField(rcCompactHeightfield& chf);
// Divides the walkable heighfied into simple regions.
// Each region has only one contour and no overlaps.
// The regions are stored in the compact heightfield 'reg' field.
// The regions will be shrinked by the radius of the agent.
// The process sometimes creates small regions. The parameter
// 'minRegionSize' specifies the smallest allowed regions size.
// If the area of a regions is smaller than allowed, the regions is
// removed or merged to neighbour region.
// Params:
// chf - (in/out) compact heightfield representing the open space.
// walkableRadius - (in) the radius of the agent.
// minRegionSize - (in) the smallest allowed regions size.
// maxMergeRegionSize - (in) the largest allowed regions size which can be merged.
// Returns false if operation ran out of memory.
bool rcBuildRegions(rcCompactHeightfield& chf,
int walkableRadius, int borderSize,
int minRegionSize, int mergeRegionSize);
// Builds simplified contours from the regions outlines.
// Params:
// chf - (in) compact heightfield which has regions set.
// maxError - (in) maximum allowed distance between simplified countour and cells.
// maxEdgeLen - (in) maximum allowed contour edge length in cells.
// cset - (out) Resulting contour set.
// Returns false if operation ran out of memory.
bool rcBuildContours(rcCompactHeightfield& chf,
const float maxError, const int maxEdgeLen,
rcContourSet& cset);
// Builds connected convex polygon mesh from contour polygons.
// Params:
// cset - (in) contour set.
// nvp - (in) maximum number of vertices per polygon.
// mesh - (out) poly mesh.
// Returns false if operation ran out of memory.
bool rcBuildPolyMesh(rcContourSet& cset, int nvp, rcPolyMesh& mesh);
bool rcMergePolyMeshes(rcPolyMesh** meshes, const int nmeshes, rcPolyMesh& mesh);
// Builds detail triangle mesh for each polygon in the poly mesh.
// Params:
// mesh - (in) poly mesh to detail.
// chf - (in) compacy height field, used to query height for new vertices.
// sampleDist - (in) spacing between height samples used to generate more detail into mesh.
// sampleMaxError - (in) maximum allowed distance between simplified detail mesh and height sample.
// pmdtl - (out) detail mesh.
// Returns false if operation ran out of memory.
bool rcBuildPolyMeshDetail(const rcPolyMesh& mesh, const rcCompactHeightfield& chf,
const float sampleDist, const float sampleMaxError,
rcPolyMeshDetail& dmesh);
bool rcMergePolyMeshDetails(rcPolyMeshDetail** meshes, const int nmeshes, rcPolyMeshDetail& mesh);
bool buildMeshAdjacency(unsigned short* polys, const int npolys, const int nverts, const int vertsPerPoly);
#endif // RECAST_H

@ -0,0 +1,80 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef RECAST_LOG_H
#define RECAST_LOG_H
enum rcLogCategory
{
RC_LOG_PROGRESS = 1,
RC_LOG_WARNING,
RC_LOG_ERROR,
};
class rcLog
{
public:
rcLog();
~rcLog();
void log(rcLogCategory category, const char* format, ...);
inline void clear() { m_messageCount = 0; m_textPoolSize = 0; }
inline int getMessageCount() const { return m_messageCount; }
inline char getMessageType(int i) const { return *m_messages[i]; }
inline const char* getMessageText(int i) const { return m_messages[i]+1; }
private:
static const int MAX_MESSAGES = 1000;
const char* m_messages[MAX_MESSAGES];
int m_messageCount;
static const int TEXT_POOL_SIZE = 8000;
char m_textPool[TEXT_POOL_SIZE];
int m_textPoolSize;
};
struct rcBuildTimes
{
int rasterizeTriangles;
int buildCompact;
int buildContours;
int buildContoursTrace;
int buildContoursSimplify;
int filterBorder;
int filterWalkable;
int filterMarkReachable;
int buildPolymesh;
int buildDistanceField;
int buildDistanceFieldDist;
int buildDistanceFieldBlur;
int buildRegions;
int buildRegionsReg;
int buildRegionsExp;
int buildRegionsFlood;
int buildRegionsFilter;
int buildDetailMesh;
int mergePolyMesh;
int mergePolyMeshDetail;
};
void rcSetLog(rcLog* log);
rcLog* rcGetLog();
void rcSetBuildTimes(rcBuildTimes* btimes);
rcBuildTimes* rcGetBuildTimes();
#endif // RECAST_LOG_H

@ -0,0 +1,31 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef RECAST_TIMER_H
#define RECAST_TIMER_H
#ifdef __GNUC__
#include <stdint.h>
typedef int64_t rcTimeVal;
#else
typedef __int64 rcTimeVal;
#endif
rcTimeVal rcGetPerformanceTimer();
int rcGetDeltaTimeUsec(rcTimeVal start, rcTimeVal end);
#endif // RECAST_TIMER_H

@ -0,0 +1,272 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#include <float.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "Recast.h"
#include "RecastLog.h"
#include "RecastTimer.h"
void rcIntArray::resize(int n)
{
if (n > m_cap)
{
if (!m_cap) m_cap = 8;
while (m_cap < n) m_cap *= 2;
int* newData = new int[m_cap];
if (m_size && newData) memcpy(newData, m_data, m_size*sizeof(int));
delete [] m_data;
m_data = newData;
}
m_size = n;
}
void rcCalcBounds(const float* verts, int nv, float* bmin, float* bmax)
{
// Calculate bounding box.
vcopy(bmin, verts);
vcopy(bmax, verts);
for (int i = 1; i < nv; ++i)
{
const float* v = &verts[i*3];
vmin(bmin, v);
vmax(bmax, v);
}
}
void rcCalcGridSize(const float* bmin, const float* bmax, float cs, int* w, int* h)
{
*w = (int)((bmax[0] - bmin[0])/cs+0.5f);
*h = (int)((bmax[2] - bmin[2])/cs+0.5f);
}
bool rcCreateHeightfield(rcHeightfield& hf, int width, int height,
const float* bmin, const float* bmax,
float cs, float ch)
{
hf.width = width;
hf.height = height;
hf.spans = new rcSpan*[hf.width*hf.height];
vcopy(hf.bmin, bmin);
vcopy(hf.bmax, bmax);
hf.cs = cs;
hf.ch = ch;
if (!hf.spans)
return false;
memset(hf.spans, 0, sizeof(rcSpan*)*hf.width*hf.height);
return true;
}
static void calcTriNormal(const float* v0, const float* v1, const float* v2, float* norm)
{
float e0[3], e1[3];
vsub(e0, v1, v0);
vsub(e1, v2, v0);
vcross(norm, e0, e1);
vnormalize(norm);
}
void rcMarkWalkableTriangles(const float walkableSlopeAngle,
const float* verts, int nv,
const int* tris, int nt,
unsigned char* flags)
{
const float walkableThr = cosf(walkableSlopeAngle/180.0f*(float)M_PI);
float norm[3];
for (int i = 0; i < nt; ++i)
{
const int* tri = &tris[i*3];
calcTriNormal(&verts[tri[0]*3], &verts[tri[1]*3], &verts[tri[2]*3], norm);
// Check if the face is walkable.
if (norm[1] > walkableThr)
flags[i] |= RC_WALKABLE;
}
}
static int getSpanCount(unsigned char flags, rcHeightfield& hf)
{
const int w = hf.width;
const int h = hf.height;
int spanCount = 0;
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
for (rcSpan* s = hf.spans[x + y*w]; s; s = s->next)
{
if (s->flags == flags)
spanCount++;
}
}
}
return spanCount;
}
inline void setCon(rcCompactSpan& s, int dir, int i)
{
s.con &= ~(0xf << (dir*4));
s.con |= (i&0xf) << (dir*4);
}
bool rcBuildCompactHeightfield(const int walkableHeight, const int walkableClimb,
unsigned char flags, rcHeightfield& hf,
rcCompactHeightfield& chf)
{
rcTimeVal startTime = rcGetPerformanceTimer();
const int w = hf.width;
const int h = hf.height;
const int spanCount = getSpanCount(flags, hf);
// Fill in header.
chf.width = w;
chf.height = h;
chf.spanCount = spanCount;
chf.walkableHeight = walkableHeight;
chf.walkableClimb = walkableClimb;
chf.maxRegions = 0;
vcopy(chf.bmin, hf.bmin);
vcopy(chf.bmax, hf.bmax);
chf.bmax[1] += walkableHeight*hf.ch;
chf.cs = hf.cs;
chf.ch = hf.ch;
chf.cells = new rcCompactCell[w*h];
if (!chf.cells)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildCompactHeightfield: Out of memory 'chf.cells' (%d)", w*h);
return false;
}
memset(chf.cells, 0, sizeof(rcCompactCell)*w*h);
chf.spans = new rcCompactSpan[spanCount];
if (!chf.spans)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildCompactHeightfield: Out of memory 'chf.spans' (%d)", spanCount);
return false;
}
memset(chf.spans, 0, sizeof(rcCompactSpan)*spanCount);
const int MAX_HEIGHT = 0xffff;
// Fill in cells and spans.
int idx = 0;
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
const rcSpan* s = hf.spans[x + y*w];
// If there are no spans at this cell, just leave the data to index=0, count=0.
if (!s) continue;
rcCompactCell& c = chf.cells[x+y*w];
c.index = idx;
c.count = 0;
while (s)
{
if (s->flags == flags)
{
const int bot = (int)s->smax;
const int top = s->next ? (int)s->next->smin : MAX_HEIGHT;
chf.spans[idx].y = (unsigned short)rcClamp(bot, 0, 0xffff);
chf.spans[idx].h = (unsigned char)rcClamp(top - bot, 0, 0xff);
idx++;
c.count++;
}
s = s->next;
}
}
}
// Find neighbour connections.
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
const rcCompactCell& c = chf.cells[x+y*w];
for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
{
rcCompactSpan& s = chf.spans[i];
for (int dir = 0; dir < 4; ++dir)
{
setCon(s, dir, 0xf);
const int nx = x + rcGetDirOffsetX(dir);
const int ny = y + rcGetDirOffsetY(dir);
// First check that the neighbour cell is in bounds.
if (nx < 0 || ny < 0 || nx >= w || ny >= h)
continue;
// Iterate over all neighbour spans and check if any of the is
// accessible from current cell.
const rcCompactCell& nc = chf.cells[nx+ny*w];
for (int k = (int)nc.index, nk = (int)(nc.index+nc.count); k < nk; ++k)
{
const rcCompactSpan& ns = chf.spans[k];
const int bot = rcMax(s.y, ns.y);
const int top = rcMin(s.y+s.h, ns.y+ns.h);
// Check that the gap between the spans is walkable,
// and that the climb height between the gaps is not too high.
if ((top - bot) >= walkableHeight && rcAbs((int)ns.y - (int)s.y) <= walkableClimb)
{
// Mark direction as walkable.
setCon(s, dir, k - (int)nc.index);
break;
}
}
}
}
}
}
rcTimeVal endTime = rcGetPerformanceTimer();
if (rcGetBuildTimes())
rcGetBuildTimes()->buildCompact += rcGetDeltaTimeUsec(startTime, endTime);
return true;
}
static int getHeightfieldMemoryUsage(const rcHeightfield& hf)
{
int size = 0;
size += sizeof(hf);
size += hf.width * hf.height * sizeof(rcSpan*);
rcSpanPool* pool = hf.pools;
while (pool)
{
size += (sizeof(rcSpanPool) - sizeof(rcSpan)) + sizeof(rcSpan)*RC_SPANS_PER_POOL;
pool = pool->next;
}
return size;
}
static int getCompactHeightFieldMemoryusage(const rcCompactHeightfield& chf)
{
int size = 0;
size += sizeof(rcCompactHeightfield);
size += sizeof(rcCompactSpan) * chf.spanCount;
size += sizeof(rcCompactCell) * chf.width * chf.height;
return size;
}

@ -0,0 +1,732 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#define _USE_MATH_DEFINES
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "Recast.h"
#include "RecastLog.h"
#include "RecastTimer.h"
static int getCornerHeight(int x, int y, int i, int dir,
const rcCompactHeightfield& chf,
bool& isBorderVertex)
{
const rcCompactSpan& s = chf.spans[i];
int ch = (int)s.y;
int dirp = (dir+1) & 0x3;
unsigned short regs[4] = {0,0,0,0};
regs[0] = s.reg;
if (rcGetCon(s, dir) != 0xf)
{
const int ax = x + rcGetDirOffsetX(dir);
const int ay = y + rcGetDirOffsetY(dir);
const int ai = (int)chf.cells[ax+ay*chf.width].index + rcGetCon(s, dir);
const rcCompactSpan& as = chf.spans[ai];
ch = rcMax(ch, (int)as.y);
regs[1] = as.reg;
if (rcGetCon(as, dirp) != 0xf)
{
const int ax2 = ax + rcGetDirOffsetX(dirp);
const int ay2 = ay + rcGetDirOffsetY(dirp);
const int ai2 = (int)chf.cells[ax2+ay2*chf.width].index + rcGetCon(as, dirp);
const rcCompactSpan& as2 = chf.spans[ai2];
ch = rcMax(ch, (int)as2.y);
regs[2] = as2.reg;
}
}
if (rcGetCon(s, dirp) != 0xf)
{
const int ax = x + rcGetDirOffsetX(dirp);
const int ay = y + rcGetDirOffsetY(dirp);
const int ai = (int)chf.cells[ax+ay*chf.width].index + rcGetCon(s, dirp);
const rcCompactSpan& as = chf.spans[ai];
ch = rcMax(ch, (int)as.y);
regs[3] = as.reg;
if (rcGetCon(as, dir) != 0xf)
{
const int ax2 = ax + rcGetDirOffsetX(dir);
const int ay2 = ay + rcGetDirOffsetY(dir);
const int ai2 = (int)chf.cells[ax2+ay2*chf.width].index + rcGetCon(as, dir);
const rcCompactSpan& as2 = chf.spans[ai2];
ch = rcMax(ch, (int)as2.y);
regs[2] = as2.reg;
}
}
// Check if the vertex is special edge vertex, these vertices will be removed later.
for (int j = 0; j < 4; ++j)
{
const int a = j;
const int b = (j+1) & 0x3;
const int c = (j+2) & 0x3;
const int d = (j+3) & 0x3;
// The vertex is a border vertex there are two same exterior cells in a row,
// followed by two interior cells and none of the regions are out of bounds.
const bool twoSameExts = (regs[a] & regs[b] & RC_BORDER_REG) != 0 && regs[a] == regs[b];
const bool twoInts = ((regs[c] | regs[d]) & RC_BORDER_REG) == 0;
const bool noZeros = regs[a] != 0 && regs[b] != 0 && regs[c] != 0 && regs[d] != 0;
if (twoSameExts && twoInts && noZeros)
{
isBorderVertex = true;
break;
}
}
return ch;
}
static void walkContour(int x, int y, int i,
rcCompactHeightfield& chf,
unsigned char* flags, rcIntArray& points)
{
// Choose the first non-connected edge
unsigned char dir = 0;
while ((flags[i] & (1 << dir)) == 0)
dir++;
unsigned char startDir = dir;
int starti = i;
int iter = 0;
while (++iter < 40000)
{
if (flags[i] & (1 << dir))
{
// Choose the edge corner
bool isBorderVertex = false;
int px = x;
int py = getCornerHeight(x, y, i, dir, chf, isBorderVertex);
int pz = y;
switch(dir)
{
case 0: pz++; break;
case 1: px++; pz++; break;
case 2: px++; break;
}
int r = 0;
const rcCompactSpan& s = chf.spans[i];
if (rcGetCon(s, dir) != 0xf)
{
const int ax = x + rcGetDirOffsetX(dir);
const int ay = y + rcGetDirOffsetY(dir);
const int ai = (int)chf.cells[ax+ay*chf.width].index + rcGetCon(s, dir);
const rcCompactSpan& as = chf.spans[ai];
r = (int)as.reg;
}
if (isBorderVertex)
r |= RC_BORDER_VERTEX;
points.push(px);
points.push(py);
points.push(pz);
points.push(r);
flags[i] &= ~(1 << dir); // Remove visited edges
dir = (dir+1) & 0x3; // Rotate CW
}
else
{
int ni = -1;
const int nx = x + rcGetDirOffsetX(dir);
const int ny = y + rcGetDirOffsetY(dir);
const rcCompactSpan& s = chf.spans[i];
if (rcGetCon(s, dir) != 0xf)
{
const rcCompactCell& nc = chf.cells[nx+ny*chf.width];
ni = (int)nc.index + rcGetCon(s, dir);
}
if (ni == -1)
{
// Should not happen.
return;
}
x = nx;
y = ny;
i = ni;
dir = (dir+3) & 0x3; // Rotate CCW
}
if (starti == i && startDir == dir)
{
break;
}
}
}
static float distancePtSeg(int x, int y, int z,
int px, int py, int pz,
int qx, int qy, int qz)
{
/* float pqx = (float)(qx - px);
float pqy = (float)(qy - py);
float pqz = (float)(qz - pz);
float dx = (float)(x - px);
float dy = (float)(y - py);
float dz = (float)(z - pz);
float d = pqx*pqx + pqy*pqy + pqz*pqz;
float t = pqx*dx + pqy*dy + pqz*dz;
if (d > 0)
t /= d;
if (t < 0)
t = 0;
else if (t > 1)
t = 1;
dx = px + t*pqx - x;
dy = py + t*pqy - y;
dz = pz + t*pqz - z;
return dx*dx + dy*dy + dz*dz;*/
float pqx = (float)(qx - px);
float pqz = (float)(qz - pz);
float dx = (float)(x - px);
float dz = (float)(z - pz);
float d = pqx*pqx + pqz*pqz;
float t = pqx*dx + pqz*dz;
if (d > 0)
t /= d;
if (t < 0)
t = 0;
else if (t > 1)
t = 1;
dx = px + t*pqx - x;
dz = pz + t*pqz - z;
return dx*dx + dz*dz;
}
static void simplifyContour(rcIntArray& points, rcIntArray& simplified, float maxError, int maxEdgeLen)
{
// Add initial points.
bool noConnections = true;
for (int i = 0; i < points.size(); i += 4)
{
if ((points[i+3] & 0xffff) != 0)
{
noConnections = false;
break;
}
}
if (noConnections)
{
// If there is no connections at all,
// create some initial points for the simplification process.
// Find lower-left and upper-right vertices of the contour.
int llx = points[0];
int lly = points[1];
int llz = points[2];
int lli = 0;
int urx = points[0];
int ury = points[1];
int urz = points[2];
int uri = 0;
for (int i = 0; i < points.size(); i += 4)
{
int x = points[i+0];
int y = points[i+1];
int z = points[i+2];
if (x < llx || (x == llx && z < llz))
{
llx = x;
lly = y;
llz = z;
lli = i/4;
}
if (x >= urx || (x == urx && z > urz))
{
urx = x;
ury = y;
urz = z;
uri = i/4;
}
}
simplified.push(llx);
simplified.push(lly);
simplified.push(llz);
simplified.push(lli);
simplified.push(urx);
simplified.push(ury);
simplified.push(urz);
simplified.push(uri);
}
else
{
// The contour has some portals to other regions.
// Add a new point to every location where the region changes.
for (int i = 0, ni = points.size()/4; i < ni; ++i)
{
int ii = (i+1) % ni;
if ((points[i*4+3] & 0xffff) != (points[ii*4+3] & 0xffff))
{
simplified.push(points[i*4+0]);
simplified.push(points[i*4+1]);
simplified.push(points[i*4+2]);
simplified.push(i);
}
}
}
// Add points until all raw points are within
// error tolerance to the simplified shape.
const int pn = points.size()/4;
for (int i = 0; i < simplified.size()/4; )
{
int ii = (i+1) % (simplified.size()/4);
int ax = simplified[i*4+0];
int ay = simplified[i*4+1];
int az = simplified[i*4+2];
int ai = simplified[i*4+3];
int bx = simplified[ii*4+0];
int by = simplified[ii*4+1];
int bz = simplified[ii*4+2];
int bi = simplified[ii*4+3];
// Find maximum deviation from the segment.
float maxd = 0;
int maxi = -1;
int ci = (ai+1) % pn;
// Tesselate only outer edges.
if ((points[ci*4+3] & 0xffff) == 0)
{
while (ci != bi)
{
float d = distancePtSeg(points[ci*4+0], points[ci*4+1]/4, points[ci*4+2],
ax, ay/4, az, bx, by/4, bz);
if (d > maxd)
{
maxd = d;
maxi = ci;
}
ci = (ci+1) % pn;
}
}
// If the max deviation is larger than accepted error,
// add new point, else continue to next segment.
if (maxi != -1 && maxd > (maxError*maxError))
{
// Add space for the new point.
simplified.resize(simplified.size()+4);
int n = simplified.size()/4;
for (int j = n-1; j > i; --j)
{
simplified[j*4+0] = simplified[(j-1)*4+0];
simplified[j*4+1] = simplified[(j-1)*4+1];
simplified[j*4+2] = simplified[(j-1)*4+2];
simplified[j*4+3] = simplified[(j-1)*4+3];
}
// Add the point.
simplified[(i+1)*4+0] = points[maxi*4+0];
simplified[(i+1)*4+1] = points[maxi*4+1];
simplified[(i+1)*4+2] = points[maxi*4+2];
simplified[(i+1)*4+3] = maxi;
}
else
{
++i;
}
}
// Split too long edges.
if (maxEdgeLen > 0)
{
for (int i = 0; i < simplified.size()/4; )
{
int ii = (i+1) % (simplified.size()/4);
int ax = simplified[i*4+0];
int az = simplified[i*4+2];
int ai = simplified[i*4+3];
int bx = simplified[ii*4+0];
int bz = simplified[ii*4+2];
int bi = simplified[ii*4+3];
// Find maximum deviation from the segment.
int maxi = -1;
int ci = (ai+1) % pn;
// Tesselate only outer edges.
if ((points[ci*4+3] & 0xffff) == 0)
{
int dx = bx - ax;
int dz = bz - az;
if (dx*dx + dz*dz > maxEdgeLen*maxEdgeLen)
{
int n = bi < ai ? (bi+pn - ai) : (bi - ai);
maxi = (ai + n/2) % pn;
}
}
// If the max deviation is larger than accepted error,
// add new point, else continue to next segment.
if (maxi != -1)
{
// Add space for the new point.
simplified.resize(simplified.size()+4);
int n = simplified.size()/4;
for (int j = n-1; j > i; --j)
{
simplified[j*4+0] = simplified[(j-1)*4+0];
simplified[j*4+1] = simplified[(j-1)*4+1];
simplified[j*4+2] = simplified[(j-1)*4+2];
simplified[j*4+3] = simplified[(j-1)*4+3];
}
// Add the point.
simplified[(i+1)*4+0] = points[maxi*4+0];
simplified[(i+1)*4+1] = points[maxi*4+1];
simplified[(i+1)*4+2] = points[maxi*4+2];
simplified[(i+1)*4+3] = maxi;
}
else
{
++i;
}
}
}
for (int i = 0; i < simplified.size()/4; ++i)
{
// The edge vertex flag is take from the current raw point,
// and the neighbour region is take from the next raw point.
const int ai = (simplified[i*4+3]+1) % pn;
const int bi = simplified[i*4+3];
simplified[i*4+3] = (points[ai*4+3] & 0xffff) | (points[bi*4+3] & RC_BORDER_VERTEX);
}
}
static void removeDegenerateSegments(rcIntArray& simplified)
{
// Remove adjacent vertices which are equal on xz-plane,
// or else the triangulator will get confused.
for (int i = 0; i < simplified.size()/4; ++i)
{
int ni = i+1;
if (ni >= (simplified.size()/4))
ni = 0;
if (simplified[i*4+0] == simplified[ni*4+0] &&
simplified[i*4+2] == simplified[ni*4+2])
{
// Degenerate segment, remove.
for (int j = i; j < simplified.size()/4-1; ++j)
{
simplified[j*4+0] = simplified[(j+1)*4+0];
simplified[j*4+1] = simplified[(j+1)*4+1];
simplified[j*4+2] = simplified[(j+1)*4+2];
simplified[j*4+3] = simplified[(j+1)*4+3];
}
simplified.pop();
}
}
}
static int calcAreaOfPolygon2D(const int* verts, const int nverts)
{
int area = 0;
for (int i = 0, j = nverts-1; i < nverts; j=i++)
{
const int* vi = &verts[i*4];
const int* vj = &verts[j*4];
area += vi[0] * vj[2] - vj[0] * vi[2];
}
return (area+1) / 2;
}
static void getClosestIndices(const int* vertsa, const int nvertsa,
const int* vertsb, const int nvertsb,
int& ia, int& ib)
{
int closestDist = 0xfffffff;
for (int i = 0; i < nvertsa; ++i)
{
const int* va = &vertsa[i*4];
for (int j = 0; j < nvertsb; ++j)
{
const int* vb = &vertsb[j*4];
const int dx = vb[0] - va[0];
const int dz = vb[2] - va[2];
const int d = dx*dx + dz*dz;
if (d < closestDist)
{
ia = i;
ib = j;
closestDist = d;
}
}
}
}
static bool mergeContours(rcContour& ca, rcContour& cb, int ia, int ib)
{
const int maxVerts = ca.nverts + cb.nverts + 2;
int* verts = new int[maxVerts*4];
if (!verts)
return false;
int nv = 0;
// Copy contour A.
for (int i = 0; i <= ca.nverts; ++i)
{
int* dst = &verts[nv*4];
const int* src = &ca.verts[((ia+i)%ca.nverts)*4];
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst[3] = src[3];
nv++;
}
// Copy contour B
for (int i = 0; i <= cb.nverts; ++i)
{
int* dst = &verts[nv*4];
const int* src = &cb.verts[((ib+i)%cb.nverts)*4];
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst[3] = src[3];
nv++;
}
delete [] ca.verts;
ca.verts = verts;
ca.nverts = nv;
delete [] cb.verts;
cb.verts = 0;
cb.nverts = 0;
return true;
}
bool rcBuildContours(rcCompactHeightfield& chf,
const float maxError, const int maxEdgeLen,
rcContourSet& cset)
{
const int w = chf.width;
const int h = chf.height;
rcTimeVal startTime = rcGetPerformanceTimer();
vcopy(cset.bmin, chf.bmin);
vcopy(cset.bmax, chf.bmax);
cset.cs = chf.cs;
cset.ch = chf.ch;
const int maxContours = chf.maxRegions*2;
cset.conts = new rcContour[maxContours];
if (!cset.conts)
return false;
cset.nconts = 0;
unsigned char* flags = new unsigned char[chf.spanCount];
if (!flags)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildContours: Out of memory 'flags'.");
return false;
}
rcTimeVal traceStartTime = rcGetPerformanceTimer();
// Mark boundaries.
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
const rcCompactCell& c = chf.cells[x+y*w];
for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
{
unsigned char res = 0;
const rcCompactSpan& s = chf.spans[i];
if (!s.reg || (s.reg & RC_BORDER_REG))
{
flags[i] = 0;
continue;
}
for (int dir = 0; dir < 4; ++dir)
{
unsigned short r = 0;
if (rcGetCon(s, dir) != 0xf)
{
const int ax = x + rcGetDirOffsetX(dir);
const int ay = y + rcGetDirOffsetY(dir);
const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, dir);
const rcCompactSpan& as = chf.spans[ai];
r = as.reg;
}
if (r == s.reg)
res |= (1 << dir);
}
flags[i] = res ^ 0xf; // Inverse, mark non connected edges.
}
}
}
rcTimeVal traceEndTime = rcGetPerformanceTimer();
rcTimeVal simplifyStartTime = rcGetPerformanceTimer();
rcIntArray verts(256);
rcIntArray simplified(64);
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
const rcCompactCell& c = chf.cells[x+y*w];
for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
{
if (flags[i] == 0 || flags[i] == 0xf)
{
flags[i] = 0;
continue;
}
unsigned short reg = chf.spans[i].reg;
if (!reg || (reg & RC_BORDER_REG))
continue;
verts.resize(0);
simplified.resize(0);
walkContour(x, y, i, chf, flags, verts);
simplifyContour(verts, simplified, maxError, maxEdgeLen);
removeDegenerateSegments(simplified);
// Store region->contour remap info.
// Create contour.
if (simplified.size()/4 >= 3)
{
if (cset.nconts >= maxContours)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildContours: Too many contours %d, max %d.", cset.nconts, maxContours);
return false;
}
rcContour* cont = &cset.conts[cset.nconts++];
cont->nverts = simplified.size()/4;
cont->verts = new int[cont->nverts*4];
memcpy(cont->verts, &simplified[0], sizeof(int)*cont->nverts*4);
cont->nrverts = verts.size()/4;
cont->rverts = new int[cont->nrverts*4];
memcpy(cont->rverts, &verts[0], sizeof(int)*cont->nrverts*4);
/* cont->cx = cont->cy = cont->cz = 0;
for (int i = 0; i < cont->nverts; ++i)
{
cont->cx += cont->verts[i*4+0];
cont->cy += cont->verts[i*4+1];
cont->cz += cont->verts[i*4+2];
}
cont->cx /= cont->nverts;
cont->cy /= cont->nverts;
cont->cz /= cont->nverts;*/
cont->reg = reg;
}
}
}
}
// Check and merge droppings.
// Sometimes the previous algorithms can fail and create several countours
// per area. This pass will try to merge the holes into the main region.
for (int i = 0; i < cset.nconts; ++i)
{
rcContour& cont = cset.conts[i];
// Check if the contour is would backwards.
if (calcAreaOfPolygon2D(cont.verts, cont.nverts) < 0)
{
// Find another contour which has the same region ID.
int mergeIdx = -1;
for (int j = 0; j < cset.nconts; ++j)
{
if (i == j) continue;
if (cset.conts[j].nverts && cset.conts[j].reg == cont.reg)
{
// Make sure the polygon is correctly oriented.
if (calcAreaOfPolygon2D(cset.conts[j].verts, cset.conts[j].nverts))
{
mergeIdx = j;
break;
}
}
}
if (mergeIdx == -1)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_WARNING, "rcBuildContours: Could not find merge target for bad contour %d.", i);
}
else
{
rcContour& mcont = cset.conts[mergeIdx];
// Merge by closest points.
int ia, ib;
getClosestIndices(mcont.verts, mcont.nverts, cont.verts, cont.nverts, ia, ib);
if (!mergeContours(mcont, cont, ia, ib))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_WARNING, "rcBuildContours: Failed to merge contours %d and %d.", i, mergeIdx);
}
}
}
}
delete [] flags;
rcTimeVal simplifyEndTime = rcGetPerformanceTimer();
rcTimeVal endTime = rcGetPerformanceTimer();
// if (rcGetLog())
// {
// rcGetLog()->log(RC_LOG_PROGRESS, "Create contours: %.3f ms", rcGetDeltaTimeUsec(startTime, endTime)/1000.0f);
// rcGetLog()->log(RC_LOG_PROGRESS, " - boundary: %.3f ms", rcGetDeltaTimeUsec(boundaryStartTime, boundaryEndTime)/1000.0f);
// rcGetLog()->log(RC_LOG_PROGRESS, " - contour: %.3f ms", rcGetDeltaTimeUsec(contourStartTime, contourEndTime)/1000.0f);
// }
if (rcGetBuildTimes())
{
rcGetBuildTimes()->buildContours += rcGetDeltaTimeUsec(startTime, endTime);
rcGetBuildTimes()->buildContoursTrace += rcGetDeltaTimeUsec(traceStartTime, traceEndTime);
rcGetBuildTimes()->buildContoursSimplify += rcGetDeltaTimeUsec(simplifyStartTime, simplifyEndTime);
}
return true;
}

@ -0,0 +1,249 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include "Recast.h"
#include "RecastLog.h"
#include "RecastTimer.h"
void rcFilterLedgeSpans(const int walkableHeight,
const int walkableClimb,
rcHeightfield& solid)
{
rcTimeVal startTime = rcGetPerformanceTimer();
const int w = solid.width;
const int h = solid.height;
const int MAX_HEIGHT = 0xffff;
// Mark border spans.
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
for (rcSpan* s = solid.spans[x + y*w]; s; s = s->next)
{
// Skip non walkable spans.
if ((s->flags & RC_WALKABLE) == 0)
continue;
const int bot = (int)s->smax;
const int top = s->next ? (int)s->next->smin : MAX_HEIGHT;
// Find neighbours minimum height.
int minh = MAX_HEIGHT;
for (int dir = 0; dir < 4; ++dir)
{
int dx = x + rcGetDirOffsetX(dir);
int dy = y + rcGetDirOffsetY(dir);
// Skip neighbours which are out of bounds.
if (dx < 0 || dy < 0 || dx >= w || dy >= h)
{
minh = rcMin(minh, -walkableClimb - bot);
continue;
}
// From minus infinity to the first span.
rcSpan* ns = solid.spans[dx + dy*w];
int nbot = -walkableClimb;
int ntop = ns ? (int)ns->smin : MAX_HEIGHT;
// Skip neightbour if the gap between the spans is too small.
if (rcMin(top,ntop) - rcMax(bot,nbot) > walkableHeight)
minh = rcMin(minh, nbot - bot);
// Rest of the spans.
for (ns = solid.spans[dx + dy*w]; ns; ns = ns->next)
{
nbot = (int)ns->smax;
ntop = ns->next ? (int)ns->next->smin : MAX_HEIGHT;
// Skip neightbour if the gap between the spans is too small.
if (rcMin(top,ntop) - rcMax(bot,nbot) > walkableHeight)
minh = rcMin(minh, nbot - bot);
}
}
// The current span is close to a ledge if the drop to any
// neighbour span is less than the walkableClimb.
if (minh < -walkableClimb)
s->flags &= ~RC_WALKABLE;
}
}
}
rcTimeVal endTime = rcGetPerformanceTimer();
// if (rcGetLog())
// rcGetLog()->log(RC_LOG_PROGRESS, "Filter border: %.3f ms", rcGetDeltaTimeUsec(startTime, endTime)/1000.0f);
if (rcGetBuildTimes())
rcGetBuildTimes()->filterBorder += rcGetDeltaTimeUsec(startTime, endTime);
}
void rcFilterWalkableLowHeightSpans(int walkableHeight,
rcHeightfield& solid)
{
rcTimeVal startTime = rcGetPerformanceTimer();
const int w = solid.width;
const int h = solid.height;
const int MAX_HEIGHT = 0xffff;
// Remove walkable flag from spans which do not have enough
// space above them for the agent to stand there.
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
for (rcSpan* s = solid.spans[x + y*w]; s; s = s->next)
{
const int bot = (int)s->smax;
const int top = s->next ? (int)s->next->smin : MAX_HEIGHT;
if ((top - bot) <= walkableHeight)
s->flags &= ~RC_WALKABLE;
}
}
}
rcTimeVal endTime = rcGetPerformanceTimer();
// if (rcGetLog())
// rcGetLog()->log(RC_LOG_PROGRESS, "Filter walkable: %.3f ms", rcGetDeltaTimeUsec(startTime, endTime)/1000.0f);
if (rcGetBuildTimes())
rcGetBuildTimes()->filterWalkable += rcGetDeltaTimeUsec(startTime, endTime);
}
struct rcReachableSeed
{
inline void set(int ix, int iy, rcSpan* is)
{
x = (unsigned short)ix;
y = (unsigned short)iy;
s = is;
}
unsigned short x, y;
rcSpan* s;
};
bool rcMarkReachableSpans(const int walkableHeight,
const int walkableClimb,
rcHeightfield& solid)
{
const int w = solid.width;
const int h = solid.height;
const int MAX_HEIGHT = 0xffff;
rcTimeVal startTime = rcGetPerformanceTimer();
// Build navigable space.
const int MAX_SEEDS = w*h;
rcReachableSeed* stack = new rcReachableSeed[MAX_SEEDS];
if (!stack)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcMarkReachableSpans: Out of memory 'stack' (%d).", MAX_SEEDS);
return false;
}
int stackSize = 0;
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
rcSpan* topSpan = solid.spans[x + y*w];
if (!topSpan)
continue;
while (topSpan->next)
topSpan = topSpan->next;
// If the span is not walkable, skip it.
if ((topSpan->flags & RC_WALKABLE) == 0)
continue;
// If the span has been visited already, skip it.
if (topSpan->flags & RC_REACHABLE)
continue;
// Start flood fill.
topSpan->flags |= RC_REACHABLE;
stackSize = 0;
stack[stackSize].set(x, y, topSpan);
stackSize++;
while (stackSize)
{
// Pop a seed from the stack.
stackSize--;
rcReachableSeed cur = stack[stackSize];
const int bot = (int)cur.s->smax;
const int top = cur.s->next ? (int)cur.s->next->smin : MAX_HEIGHT;
// Visit neighbours in all 4 directions.
for (int dir = 0; dir < 4; ++dir)
{
int dx = (int)cur.x + rcGetDirOffsetX(dir);
int dy = (int)cur.y + rcGetDirOffsetY(dir);
// Skip neighbour which are out of bounds.
if (dx < 0 || dy < 0 || dx >= w || dy >= h)
continue;
for (rcSpan* ns = solid.spans[dx + dy*w]; ns; ns = ns->next)
{
// Skip neighbour if it is not walkable.
if ((ns->flags & RC_WALKABLE) == 0)
continue;
// Skip the neighbour if it has been visited already.
if (ns->flags & RC_REACHABLE)
continue;
const int nbot = (int)ns->smax;
const int ntop = ns->next ? (int)ns->next->smin : MAX_HEIGHT;
// Skip neightbour if the gap between the spans is too small.
if (rcMin(top,ntop) - rcMax(bot,nbot) < walkableHeight)
continue;
// Skip neightbour if the climb height to the neighbour is too high.
if (rcAbs(nbot - bot) >= walkableClimb)
continue;
// This neighbour has not been visited yet.
// Mark it as reachable and add it to the seed stack.
ns->flags |= RC_REACHABLE;
if (stackSize < MAX_SEEDS)
{
stack[stackSize].set(dx, dy, ns);
stackSize++;
}
}
}
}
}
}
delete [] stack;
rcTimeVal endTime = rcGetPerformanceTimer();
// if (rcGetLog())
// rcGetLog()->log(RC_LOG_PROGRESS, "Mark reachable: %.3f ms", rcGetDeltaTimeUsec(startTime, endTime)/1000.0f);
if (rcGetBuildTimes())
rcGetBuildTimes()->filterMarkReachable += rcGetDeltaTimeUsec(startTime, endTime);
return true;
}

@ -0,0 +1,77 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#include "RecastLog.h"
#include <stdio.h>
#include <stdarg.h>
static rcLog* g_log = 0;
static rcBuildTimes* g_btimes = 0;
rcLog::rcLog() :
m_messageCount(0),
m_textPoolSize(0)
{
}
rcLog::~rcLog()
{
if (g_log == this)
g_log = 0;
}
void rcLog::log(rcLogCategory category, const char* format, ...)
{
if (m_messageCount >= MAX_MESSAGES)
return;
char* dst = &m_textPool[m_textPoolSize];
int n = TEXT_POOL_SIZE - m_textPoolSize;
if (n < 2)
return;
// Store category
*dst = (char)category;
n--;
// Store message
va_list ap;
va_start(ap, format);
int ret = vsnprintf(dst+1, n-1, format, ap);
va_end(ap);
if (ret > 0)
m_textPoolSize += ret+2;
m_messages[m_messageCount++] = dst;
}
void rcSetLog(rcLog* log)
{
g_log = log;
}
rcLog* rcGetLog()
{
return g_log;
}
void rcSetBuildTimes(rcBuildTimes* btimes)
{
g_btimes = btimes;
}
rcBuildTimes* rcGetBuildTimes()
{
return g_btimes;
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,989 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#include <float.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "Recast.h"
#include "RecastLog.h"
#include "RecastTimer.h"
struct rcHeightPatch
{
inline rcHeightPatch() : data(0) {}
inline ~rcHeightPatch() { delete [] data; }
unsigned short* data;
int xmin, ymin, width, height;
};
static int circumCircle(const float xp, const float yp,
const float x1, const float y1,
const float x2, const float y2,
const float x3, const float y3,
float& xc, float& yc, float& rsqr)
{
static const float EPSILON = 1e-6f;
const float fabsy1y2 = rcAbs(y1-y2);
const float fabsy2y3 = rcAbs(y2-y3);
/* Check for coincident points */
if (fabsy1y2 < EPSILON && fabsy2y3 < EPSILON)
return 0;
if (fabsy1y2 < EPSILON)
{
const float m2 = - (x3-x2) / (y3-y2);
const float mx2 = (x2 + x3) / 2.0f;
const float my2 = (y2 + y3) / 2.0f;
xc = (x2 + x1) / 2.0f;
yc = m2 * (xc - mx2) + my2;
}
else if (fabsy2y3 < EPSILON)
{
const float m1 = - (x2-x1) / (y2-y1);
const float mx1 = (x1 + x2) / 2.0f;
const float my1 = (y1 + y2) / 2.0f;
xc = (x3 + x2) / 2.0f;
yc = m1 * (xc - mx1) + my1;
}
else
{
const float m1 = - (x2-x1) / (y2-y1);
const float m2 = - (x3-x2) / (y3-y2);
const float mx1 = (x1 + x2) / 2.0f;
const float mx2 = (x2 + x3) / 2.0f;
const float my1 = (y1 + y2) / 2.0f;
const float my2 = (y2 + y3) / 2.0f;
xc = (m1 * mx1 - m2 * mx2 + my2 - my1) / (m1 - m2);
if (fabsy1y2 > fabsy2y3)
yc = m1 * (xc - mx1) + my1;
else
yc = m2 * (xc - mx2) + my2;
}
float dx,dy;
dx = x2 - xc;
dy = y2 - yc;
rsqr = dx*dx + dy*dy;
dx = xp - xc;
dy = yp - yc;
const float drsqr = dx*dx + dy*dy;
return (drsqr <= rsqr) ? 1 : 0;
}
#if defined(_MSC_VER)
static int ptcmp(void* up, const void *v1, const void *v2)
#else
static int ptcmp(const void *v1, const void *v2, void* up)
#endif
{
const float* verts = (const float*)up;
const float* p1 = &verts[(*(const int*)v1)*3];
const float* p2 = &verts[(*(const int*)v2)*3];
if (p1[0] < p2[0])
return -1;
else if (p1[0] > p2[0])
return 1;
else
return 0;
}
// Based on Paul Bourke's triangulate.c
// http://astronomy.swin.edu.au/~pbourke/terrain/triangulate/triangulate.c
static void delaunay(const int nv, float *verts, rcIntArray& idx, rcIntArray& tris, rcIntArray& edges)
{
// Sort vertices
idx.resize(nv);
for (int i = 0; i < nv; ++i)
idx[i] = i;
#if defined(_MSC_VER)
qsort_s(&idx[0], idx.size(), sizeof(int), ptcmp, verts);
#else
qsort_r(&idx[0], idx.size(), sizeof(int), ptcmp, verts);
#endif
// Find the maximum and minimum vertex bounds.
// This is to allow calculation of the bounding triangle
float xmin = verts[0];
float ymin = verts[2];
float xmax = xmin;
float ymax = ymin;
for (int i = 1; i < nv; ++i)
{
xmin = rcMin(xmin, verts[i*3+0]);
xmax = rcMax(xmax, verts[i*3+0]);
ymin = rcMin(ymin, verts[i*3+2]);
ymax = rcMax(ymax, verts[i*3+2]);
}
float dx = xmax - xmin;
float dy = ymax - ymin;
float dmax = (dx > dy) ? dx : dy;
float xmid = (xmax + xmin) / 2.0f;
float ymid = (ymax + ymin) / 2.0f;
// Set up the supertriangle
// This is a triangle which encompasses all the sample points.
// The supertriangle coordinates are added to the end of the
// vertex list. The supertriangle is the first triangle in
// the triangle list.
float sv[3*3];
sv[0] = xmid - 20 * dmax;
sv[1] = 0;
sv[2] = ymid - dmax;
sv[3] = xmid;
sv[4] = 0;
sv[5] = ymid + 20 * dmax;
sv[6] = xmid + 20 * dmax;
sv[7] = 0;
sv[8] = ymid - dmax;
tris.push(-3);
tris.push(-2);
tris.push(-1);
tris.push(0); // not completed
for (int i = 0; i < nv; ++i)
{
const float xp = verts[idx[i]*3+0];
const float yp = verts[idx[i]*3+2];
edges.resize(0);
// Set up the edge buffer.
// If the point (xp,yp) lies inside the circumcircle then the
// three edges of that triangle are added to the edge buffer
// and that triangle is removed.
for (int j = 0; j < tris.size()/4; ++j)
{
int* t = &tris[j*4];
if (t[3]) // completed?
continue;
const float* v1 = t[0] < 0 ? &sv[(t[0]+3)*3] : &verts[idx[t[0]]*3];
const float* v2 = t[1] < 0 ? &sv[(t[1]+3)*3] : &verts[idx[t[1]]*3];
const float* v3 = t[2] < 0 ? &sv[(t[2]+3)*3] : &verts[idx[t[2]]*3];
float xc,yc,rsqr;
int inside = circumCircle(xp,yp, v1[0],v1[2], v2[0],v2[2], v3[0],v3[2], xc,yc,rsqr);
if (xc < xp && rcSqr(xp-xc) > rsqr)
t[3] = 1;
if (inside)
{
// Collect triangle edges.
edges.push(t[0]);
edges.push(t[1]);
edges.push(t[1]);
edges.push(t[2]);
edges.push(t[2]);
edges.push(t[0]);
// Remove triangle j.
t[0] = tris[tris.size()-4];
t[1] = tris[tris.size()-3];
t[2] = tris[tris.size()-2];
t[3] = tris[tris.size()-1];
tris.resize(tris.size()-4);
j--;
}
}
// Remove duplicate edges.
const int ne = edges.size()/2;
for (int j = 0; j < ne-1; ++j)
{
for (int k = j+1; k < ne; ++k)
{
// Dupe?, make null.
if ((edges[j*2+0] == edges[k*2+1]) && (edges[j*2+1] == edges[k*2+0]))
{
edges[j*2+0] = 0;
edges[j*2+1] = 0;
edges[k*2+0] = 0;
edges[k*2+1] = 0;
}
}
}
// Form new triangles for the current point
// Skipping over any null.
// All edges are arranged in clockwise order.
for (int j = 0; j < ne; ++j)
{
if (edges[j*2+0] == edges[j*2+1]) continue;
tris.push(edges[j*2+0]);
tris.push(edges[j*2+1]);
tris.push(i);
tris.push(0); // not completed
}
}
// Remove triangles with supertriangle vertices
// These are triangles which have a vertex number greater than nv
for (int i = 0; i < tris.size()/4; ++i)
{
int* t = &tris[i*4];
if (t[0] < 0 || t[1] < 0 || t[2] < 0)
{
t[0] = tris[tris.size()-4];
t[1] = tris[tris.size()-3];
t[2] = tris[tris.size()-2];
t[3] = tris[tris.size()-1];
tris.resize(tris.size()-4);
i--;
}
}
// Triangle vertices are pointing to sorted vertices, remap indices.
for (int i = 0; i < tris.size(); ++i)
tris[i] = idx[tris[i]];
}
inline float vdot2(const float* a, const float* b)
{
return a[0]*b[0] + a[2]*b[2];
}
static float distPtTri(const float* p, const float* a, const float* b, const float* c)
{
float v0[3], v1[3], v2[3];
vsub(v0, c,a);
vsub(v1, b,a);
vsub(v2, p,a);
const float dot00 = vdot2(v0, v0);
const float dot01 = vdot2(v0, v1);
const float dot02 = vdot2(v0, v2);
const float dot11 = vdot2(v1, v1);
const float dot12 = vdot2(v1, v2);
// Compute barycentric coordinates
float invDenom = 1.0f / (dot00 * dot11 - dot01 * dot01);
float u = (dot11 * dot02 - dot01 * dot12) * invDenom;
float v = (dot00 * dot12 - dot01 * dot02) * invDenom;
// If point lies inside the triangle, return interpolated y-coord.
static const float EPS = 1e-4f;
if (u >= -EPS && v >= -EPS && (u+v) <= 1+EPS)
{
float y = a[1] + v0[1]*u + v1[1]*v;
return fabsf(y-p[1]);
}
return FLT_MAX;
}
static float distancePtSeg(const float* pt, const float* p, const float* q)
{
float pqx = q[0] - p[0];
float pqy = q[1] - p[1];
float pqz = q[2] - p[2];
float dx = pt[0] - p[0];
float dy = pt[1] - p[1];
float dz = pt[2] - p[2];
float d = pqx*pqx + pqy*pqy + pqz*pqz;
float t = pqx*dx + pqy*dy + pqz*dz;
if (d > 0)
t /= d;
if (t < 0)
t = 0;
else if (t > 1)
t = 1;
dx = p[0] + t*pqx - pt[0];
dy = p[1] + t*pqy - pt[1];
dz = p[2] + t*pqz - pt[2];
return dx*dx + dy*dy + dz*dz;
}
static float distancePtSeg2d(const float* pt, const float* p, const float* q)
{
float pqx = q[0] - p[0];
float pqz = q[2] - p[2];
float dx = pt[0] - p[0];
float dz = pt[2] - p[2];
float d = pqx*pqx + pqz*pqz;
float t = pqx*dx + pqz*dz;
if (d > 0)
t /= d;
if (t < 0)
t = 0;
else if (t > 1)
t = 1;
dx = p[0] + t*pqx - pt[0];
dz = p[2] + t*pqz - pt[2];
return dx*dx + dz*dz;
}
static float distToTriMesh(const float* p, const float* verts, int nverts, const int* tris, int ntris)
{
float dmin = FLT_MAX;
for (int i = 0; i < ntris; ++i)
{
const float* va = &verts[tris[i*4+0]*3];
const float* vb = &verts[tris[i*4+1]*3];
const float* vc = &verts[tris[i*4+2]*3];
float d = distPtTri(p, va,vb,vc);
if (d < dmin)
dmin = d;
}
if (dmin == FLT_MAX) return -1;
return dmin;
}
static float distToPoly(int nvert, const float* verts, const float* p)
{
float dmin = FLT_MAX;
int i, j, c = 0;
for (i = 0, j = nvert-1; i < nvert; j = i++)
{
const float* vi = &verts[i*3];
const float* vj = &verts[j*3];
if (((vi[2] > p[2]) != (vj[2] > p[2])) &&
(p[0] < (vj[0]-vi[0]) * (p[2]-vi[2]) / (vj[2]-vi[2]) + vi[0]) )
c = !c;
dmin = rcMin(dmin, distancePtSeg2d(p, vj, vi));
}
return c ? -dmin : dmin;
}
static unsigned short getHeight(const float* pos, const float* bmin, const float ics, const rcHeightPatch& hp)
{
int ix = (int)floorf((pos[0]-bmin[0])*ics + 0.01f);
int iz = (int)floorf((pos[2]-bmin[2])*ics + 0.01f);
ix = rcClamp(ix-hp.xmin, 0, hp.width);
iz = rcClamp(iz-hp.ymin, 0, hp.height);
unsigned short h = hp.data[ix+iz*hp.width];
return h;
}
static bool buildPolyDetail(const float* in, const int nin, unsigned short reg,
const float sampleDist, const float sampleMaxError,
const rcCompactHeightfield& chf, const rcHeightPatch& hp,
float* verts, int& nverts, rcIntArray& tris,
rcIntArray& edges, rcIntArray& idx, rcIntArray& samples)
{
static const int MAX_VERTS = 256;
static const int MAX_EDGE = 64;
float edge[(MAX_EDGE+1)*3];
nverts = 0;
for (int i = 0; i < nin; ++i)
vcopy(&verts[i*3], &in[i*3]);
nverts = nin;
const float ics = 1.0f/chf.cs;
// Tesselate outlines.
// This is done in separate pass in order to ensure
// seamless height values across the ply boundaries.
if (sampleDist > 0)
{
for (int i = 0, j = nin-1; i < nin; j=i++)
{
const float* vj = &in[j*3];
const float* vi = &in[i*3];
// Make sure the segments are always handled in same order
// using lexological sort or else there will be seams.
if (fabsf(vj[0]-vi[0]) < 1e-6f)
{
if (vj[2] > vi[2])
rcSwap(vj,vi);
}
else
{
if (vj[0] > vi[0])
rcSwap(vj,vi);
}
// Create samples along the edge.
float dx = vi[0] - vj[0];
float dy = vi[1] - vj[1];
float dz = vi[2] - vj[2];
float d = sqrtf(dx*dx + dz*dz);
int nn = 1 + (int)floorf(d/sampleDist);
if (nn > MAX_EDGE) nn = MAX_EDGE;
if (nverts+nn >= MAX_VERTS)
nn = MAX_VERTS-1-nverts;
for (int k = 0; k <= nn; ++k)
{
float u = (float)k/(float)nn;
float* pos = &edge[k*3];
pos[0] = vj[0] + dx*u;
pos[1] = vj[1] + dy*u;
pos[2] = vj[2] + dz*u;
pos[1] = chf.bmin[1] + getHeight(pos, chf.bmin, ics, hp)*chf.ch;
}
// Simplify samples.
int idx[MAX_EDGE] = {0,nn};
int nidx = 2;
for (int k = 0; k < nidx-1; )
{
const int a = idx[k];
const int b = idx[k+1];
const float* va = &edge[a*3];
const float* vb = &edge[b*3];
// Find maximum deviation along the segment.
float maxd = 0;
int maxi = -1;
for (int m = a+1; m < b; ++m)
{
float d = distancePtSeg(&edge[m*3],va,vb);
if (d > maxd)
{
maxd = d;
maxi = m;
}
}
// If the max deviation is larger than accepted error,
// add new point, else continue to next segment.
if (maxi != -1 && maxd > rcSqr(sampleMaxError))
{
for (int m = nidx; m > k; --m)
idx[m] = idx[m-1];
idx[k+1] = maxi;
nidx++;
}
else
{
++k;
}
}
// Add new vertices.
for (int k = 1; k < nidx-1; ++k)
{
vcopy(&verts[nverts*3], &edge[idx[k]*3]);
nverts++;
}
}
}
// Tesselate the base mesh.
edges.resize(0);
tris.resize(0);
idx.resize(0);
delaunay(nverts, verts, idx, tris, edges);
if (sampleDist > 0)
{
// Create sample locations in a grid.
float bmin[3], bmax[3];
vcopy(bmin, in);
vcopy(bmax, in);
for (int i = 1; i < nin; ++i)
{
vmin(bmin, &in[i*3]);
vmax(bmax, &in[i*3]);
}
int x0 = (int)floorf(bmin[0]/sampleDist);
int x1 = (int)ceilf(bmax[0]/sampleDist);
int z0 = (int)floorf(bmin[2]/sampleDist);
int z1 = (int)ceilf(bmax[2]/sampleDist);
samples.resize(0);
for (int z = z0; z < z1; ++z)
{
for (int x = x0; x < x1; ++x)
{
float pt[3];
pt[0] = x*sampleDist;
pt[2] = z*sampleDist;
// Make sure the samples are not too close to the edges.
if (distToPoly(nin,in,pt) > -sampleDist/2) continue;
samples.push(x);
samples.push(getHeight(pt, chf.bmin, ics, hp));
samples.push(z);
}
}
// Add the samples starting from the one that has the most
// error. The procedure stops when all samples are added
// or when the max error is within treshold.
const int nsamples = samples.size()/3;
for (int iter = 0; iter < nsamples; ++iter)
{
// Find sample with most error.
float bestpt[3];
float bestd = 0;
for (int i = 0; i < nsamples; ++i)
{
float pt[3];
pt[0] = samples[i*3+0]*sampleDist;
pt[1] = chf.bmin[1] + samples[i*3+1]*chf.ch;
pt[2] = samples[i*3+2]*sampleDist;
float d = distToTriMesh(pt, verts, nverts, &tris[0], tris.size()/4);
if (d < 0) continue; // did not hit the mesh.
if (d > bestd)
{
bestd = d;
vcopy(bestpt,pt);
}
}
// If the max error is within accepted threshold, stop tesselating.
if (bestd <= sampleMaxError)
break;
// Add the new sample point.
vcopy(&verts[nverts*3],bestpt);
nverts++;
// Create new triangulation.
// TODO: Incremental add instead of full rebuild.
edges.resize(0);
tris.resize(0);
idx.resize(0);
delaunay(nverts, verts, idx, tris, edges);
if (nverts >= MAX_VERTS)
break;
}
}
return true;
}
static void getHeightData(const rcCompactHeightfield& chf,
const unsigned short* poly, const int npoly,
const unsigned short* verts,
rcHeightPatch& hp, rcIntArray& stack)
{
// Floodfill the heightfield to get 2D height data,
// starting at vertex locations as seeds.
memset(hp.data, 0xff, sizeof(unsigned short)*hp.width*hp.height);
stack.resize(0);
// Use poly vertices as seed points for the flood fill.
for (int j = 0; j < npoly; ++j)
{
const int ax = (int)verts[poly[j]*3+0];
const int ay = (int)verts[poly[j]*3+1];
const int az = (int)verts[poly[j]*3+2];
if (ax < hp.xmin || ax >= hp.xmin+hp.width ||
az < hp.ymin || az >= hp.ymin+hp.height)
continue;
const rcCompactCell& c = chf.cells[ax+az*chf.width];
int dmin = 0xffff;
int ai = -1;
for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
{
const rcCompactSpan& s = chf.spans[i];
int d = rcAbs(ay - (int)s.y);
if (d < dmin)
{
ai = i;
dmin = d;
}
}
if (ai != -1)
{
stack.push(ax);
stack.push(az);
stack.push(ai);
}
}
while (stack.size() > 0)
{
int ci = stack.pop();
int cy = stack.pop();
int cx = stack.pop();
// Skip already visited locations.
int idx = cx-hp.xmin+(cy-hp.ymin)*hp.width;
if (hp.data[idx] != 0xffff)
continue;
const rcCompactSpan& cs = chf.spans[ci];
hp.data[idx] = cs.y;
for (int dir = 0; dir < 4; ++dir)
{
if (rcGetCon(cs, dir) == 0xf) continue;
const int ax = cx + rcGetDirOffsetX(dir);
const int ay = cy + rcGetDirOffsetY(dir);
if (ax < hp.xmin || ax >= (hp.xmin+hp.width) ||
ay < hp.ymin || ay >= (hp.ymin+hp.height))
continue;
if (hp.data[ax-hp.xmin+(ay-hp.ymin)*hp.width] != 0xffff)
continue;
const int ai = (int)chf.cells[ax+ay*chf.width].index + rcGetCon(cs, dir);
stack.push(ax);
stack.push(ay);
stack.push(ai);
}
}
}
static unsigned char getEdgeFlags(const float* va, const float* vb,
const float* vpoly, const int npoly)
{
// Return true if edge (va,vb) is part of the polygon.
static const float thrSqr = rcSqr(0.001f);
for (int i = 0, j = npoly-1; i < npoly; j=i++)
{
if (distancePtSeg2d(va, &vpoly[j*3], &vpoly[i*3]) < thrSqr &&
distancePtSeg2d(vb, &vpoly[j*3], &vpoly[i*3]) < thrSqr)
return 1;
}
return 0;
}
static unsigned char getTriFlags(const float* va, const float* vb, const float* vc,
const float* vpoly, const int npoly)
{
unsigned char flags = 0;
flags |= getEdgeFlags(va,vb,vpoly,npoly) << 0;
flags |= getEdgeFlags(vb,vc,vpoly,npoly) << 2;
flags |= getEdgeFlags(vc,va,vpoly,npoly) << 4;
return flags;
}
bool rcBuildPolyMeshDetail(const rcPolyMesh& mesh, const rcCompactHeightfield& chf,
const float sampleDist, const float sampleMaxError,
rcPolyMeshDetail& dmesh)
{
if (mesh.nverts == 0 || mesh.npolys == 0)
return true;
rcTimeVal startTime = rcGetPerformanceTimer();
rcTimeVal endTime;
int vcap;
int tcap;
const int nvp = mesh.nvp;
const float cs = mesh.cs;
const float ch = mesh.ch;
const float* orig = mesh.bmin;
rcIntArray edges(64);
rcIntArray tris(512);
rcIntArray idx(512);
rcIntArray stack(512);
rcIntArray samples(512);
float verts[256*3];
float* poly = 0;
int* bounds = 0;
rcHeightPatch hp;
int nPolyVerts = 0;
int maxhw = 0, maxhh = 0;
bounds = new int[mesh.npolys*4];
if (!bounds)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'bounds' (%d).", mesh.npolys*4);
goto failure;
}
poly = new float[nvp*3];
if (!bounds)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'poly' (%d).", nvp*3);
goto failure;
}
// Find max size for a polygon area.
for (int i = 0; i < mesh.npolys; ++i)
{
const unsigned short* p = &mesh.polys[i*nvp*2];
int& xmin = bounds[i*4+0];
int& xmax = bounds[i*4+1];
int& ymin = bounds[i*4+2];
int& ymax = bounds[i*4+3];
xmin = chf.width;
xmax = 0;
ymin = chf.height;
ymax = 0;
for (int j = 0; j < nvp; ++j)
{
if(p[j] == 0xffff) break;
const unsigned short* v = &mesh.verts[p[j]*3];
xmin = rcMin(xmin, (int)v[0]);
xmax = rcMax(xmax, (int)v[0]);
ymin = rcMin(ymin, (int)v[2]);
ymax = rcMax(ymax, (int)v[2]);
nPolyVerts++;
}
xmin = rcMax(0,xmin-1);
xmax = rcMin(chf.width,xmax+1);
ymin = rcMax(0,ymin-1);
ymax = rcMin(chf.height,ymax+1);
if (xmin >= xmax || ymin >= ymax) continue;
maxhw = rcMax(maxhw, xmax-xmin);
maxhh = rcMax(maxhh, ymax-ymin);
}
hp.data = new unsigned short[maxhw*maxhh];
if (!hp.data)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'hp.data' (%d).", maxhw*maxhh);
goto failure;
}
dmesh.nmeshes = mesh.npolys;
dmesh.nverts = 0;
dmesh.ntris = 0;
dmesh.meshes = new unsigned short[dmesh.nmeshes*4];
if (!dmesh.meshes)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'dmesh.meshes' (%d).", dmesh.nmeshes*4);
goto failure;
}
vcap = nPolyVerts+nPolyVerts/2;
tcap = vcap*2;
dmesh.nverts = 0;
dmesh.verts = new float[vcap*3];
if (!dmesh.verts)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'dmesh.verts' (%d).", vcap*3);
goto failure;
}
dmesh.ntris = 0;
dmesh.tris = new unsigned char[tcap*4];
if (!dmesh.tris)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'dmesh.tris' (%d).", tcap*4);
goto failure;
}
for (int i = 0; i < mesh.npolys; ++i)
{
const unsigned short* p = &mesh.polys[i*nvp*2];
// Find polygon bounding box.
int npoly = 0;
for (int j = 0; j < nvp; ++j)
{
if(p[j] == 0xffff) break;
const unsigned short* v = &mesh.verts[p[j]*3];
poly[j*3+0] = orig[0] + v[0]*cs;
poly[j*3+1] = orig[1] + v[1]*ch;
poly[j*3+2] = orig[2] + v[2]*cs;
npoly++;
}
// Get the height data from the area of the polygon.
hp.xmin = bounds[i*4+0];
hp.ymin = bounds[i*4+2];
hp.width = bounds[i*4+1]-bounds[i*4+0];
hp.height = bounds[i*4+3]-bounds[i*4+2];
getHeightData(chf, p, npoly, mesh.verts, hp, stack);
// Build detail mesh.
int nverts = 0;
if (!buildPolyDetail(poly, npoly, mesh.regs[i],
sampleDist, sampleMaxError,
chf, hp, verts, nverts, tris,
edges, idx, samples))
{
goto failure;
}
// Offset detail vertices, unnecassary?
for (int j = 0; j < nverts; ++j)
verts[j*3+1] += chf.ch;
// Store detail submesh.
const int ntris = tris.size()/4;
dmesh.meshes[i*4+0] = dmesh.nverts;
dmesh.meshes[i*4+1] = (unsigned short)nverts;
dmesh.meshes[i*4+2] = dmesh.ntris;
dmesh.meshes[i*4+3] = (unsigned short)ntris;
// Store vertices, allocate more memory if necessary.
if (dmesh.nverts+nverts > vcap)
{
while (dmesh.nverts+nverts > vcap)
vcap += 256;
float* newv = new float[vcap*3];
if (!newv)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'newv' (%d).", vcap*3);
goto failure;
}
if (dmesh.nverts)
memcpy(newv, dmesh.verts, sizeof(float)*3*dmesh.nverts);
delete [] dmesh.verts;
dmesh.verts = newv;
}
for (int j = 0; j < nverts; ++j)
{
dmesh.verts[dmesh.nverts*3+0] = verts[j*3+0];
dmesh.verts[dmesh.nverts*3+1] = verts[j*3+1];
dmesh.verts[dmesh.nverts*3+2] = verts[j*3+2];
dmesh.nverts++;
}
// Store triangles, allocate more memory if necessary.
if (dmesh.ntris+ntris > tcap)
{
while (dmesh.ntris+ntris > tcap)
tcap += 256;
unsigned char* newt = new unsigned char[tcap*4];
if (!newt)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'newt' (%d).", tcap*4);
goto failure;
}
if (dmesh.ntris)
memcpy(newt, dmesh.tris, sizeof(unsigned char)*4*dmesh.ntris);
delete [] dmesh.tris;
dmesh.tris = newt;
}
for (int j = 0; j < ntris; ++j)
{
const int* t = &tris[j*4];
dmesh.tris[dmesh.ntris*4+0] = (unsigned char)t[0];
dmesh.tris[dmesh.ntris*4+1] = (unsigned char)t[1];
dmesh.tris[dmesh.ntris*4+2] = (unsigned char)t[2];
dmesh.tris[dmesh.ntris*4+3] = getTriFlags(&verts[t[0]*3], &verts[t[1]*3], &verts[t[2]*3], poly, npoly);
dmesh.ntris++;
}
}
delete [] bounds;
delete [] poly;
endTime = rcGetPerformanceTimer();
if (rcGetBuildTimes())
rcGetBuildTimes()->buildDetailMesh += rcGetDeltaTimeUsec(startTime, endTime);
return true;
failure:
delete [] bounds;
delete [] poly;
return false;
}
bool rcMergePolyMeshDetails(rcPolyMeshDetail** meshes, const int nmeshes, rcPolyMeshDetail& mesh)
{
rcTimeVal startTime = rcGetPerformanceTimer();
int maxVerts = 0;
int maxTris = 0;
int maxMeshes = 0;
for (int i = 0; i < nmeshes; ++i)
{
if (!meshes[i]) continue;
maxVerts += meshes[i]->nverts;
maxTris += meshes[i]->ntris;
maxMeshes += meshes[i]->nmeshes;
}
mesh.nmeshes = 0;
mesh.meshes = new unsigned short[maxMeshes*4];
if (!mesh.meshes)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'pmdtl.meshes' (%d).", maxMeshes*4);
return false;
}
mesh.ntris = 0;
mesh.tris = new unsigned char[maxTris*4];
if (!mesh.tris)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'dmesh.tris' (%d).", maxTris*4);
return false;
}
mesh.nverts = 0;
mesh.verts = new float[maxVerts*3];
if (!mesh.verts)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'dmesh.verts' (%d).", maxVerts*3);
return false;
}
// Merge datas.
for (int i = 0; i < nmeshes; ++i)
{
rcPolyMeshDetail* dm = meshes[i];
if (!dm) continue;
for (int j = 0; j < dm->nmeshes; ++j)
{
unsigned short* dst = &mesh.meshes[mesh.nmeshes*4];
unsigned short* src = &dm->meshes[j*4];
dst[0] = mesh.nverts+src[0];
dst[1] = src[1];
dst[2] = mesh.ntris+src[2];
dst[3] = src[3];
mesh.nmeshes++;
}
for (int k = 0; k < dm->nverts; ++k)
{
vcopy(&mesh.verts[mesh.nverts*3], &dm->verts[k*3]);
mesh.nverts++;
}
for (int k = 0; k < dm->ntris; ++k)
{
mesh.tris[mesh.ntris*4+0] = dm->tris[k*4+0];
mesh.tris[mesh.ntris*4+1] = dm->tris[k*4+1];
mesh.tris[mesh.ntris*4+2] = dm->tris[k*4+2];
mesh.tris[mesh.ntris*4+3] = dm->tris[k*4+3];
mesh.ntris++;
}
}
rcTimeVal endTime = rcGetPerformanceTimer();
if (rcGetBuildTimes())
rcGetBuildTimes()->mergePolyMeshDetail += rcGetDeltaTimeUsec(startTime, endTime);
return true;
}

@ -0,0 +1,308 @@
//
// Copyright (c) 2009 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include "Recast.h"
#include "RecastTimer.h"
#include "RecastLog.h"
inline bool overlapBounds(const float* amin, const float* amax, const float* bmin, const float* bmax)
{
bool overlap = true;
overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap;
overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap;
overlap = (amin[2] > bmax[2] || amax[2] < bmin[2]) ? false : overlap;
return overlap;
}
inline bool overlapInterval(unsigned short amin, unsigned short amax,
unsigned short bmin, unsigned short bmax)
{
if (amax < bmin) return false;
if (amin > bmax) return false;
return true;
}
static rcSpan* allocSpan(rcHeightfield& hf)
{
// If running out of memory, allocate new page and update the freelist.
if (!hf.freelist || !hf.freelist->next)
{
// Create new page.
// Allocate memory for the new pool.
const int size = (sizeof(rcSpanPool)-sizeof(rcSpan)) + sizeof(rcSpan)*RC_SPANS_PER_POOL;
rcSpanPool* pool = reinterpret_cast<rcSpanPool*>(new unsigned char[size]);
if (!pool) return 0;
pool->next = 0;
// Add the pool into the list of pools.
pool->next = hf.pools;
hf.pools = pool;
// Add new items to the free list.
rcSpan* freelist = hf.freelist;
rcSpan* head = &pool->items[0];
rcSpan* it = &pool->items[RC_SPANS_PER_POOL];
do
{
--it;
it->next = freelist;
freelist = it;
}
while (it != head);
hf.freelist = it;
}
// Pop item from in front of the free list.
rcSpan* it = hf.freelist;
hf.freelist = hf.freelist->next;
return it;
}
static void freeSpan(rcHeightfield& hf, rcSpan* ptr)
{
if (!ptr) return;
// Add the node in front of the free list.
ptr->next = hf.freelist;
hf.freelist = ptr;
}
static void addSpan(rcHeightfield& hf, int x, int y,
unsigned short smin, unsigned short smax,
unsigned short flags)
{
int idx = x + y*hf.width;
rcSpan* s = allocSpan(hf);
s->smin = smin;
s->smax = smax;
s->flags = flags;
s->next = 0;
// Empty cell, add he first span.
if (!hf.spans[idx])
{
hf.spans[idx] = s;
return;
}
rcSpan* prev = 0;
rcSpan* cur = hf.spans[idx];
// Insert and merge spans.
while (cur)
{
if (cur->smin > s->smax)
{
// Current span is further than the new span, break.
break;
}
else if (cur->smax < s->smin)
{
// Current span is before the new span advance.
prev = cur;
cur = cur->next;
}
else
{
// Merge spans.
if (cur->smin < s->smin)
s->smin = cur->smin;
if (cur->smax > s->smax)
s->smax = cur->smax;
// Merge flags.
// if (s->smax == cur->smax)
if (rcAbs((int)s->smax - (int)cur->smax) <= 1)
s->flags |= cur->flags;
// Remove current span.
rcSpan* next = cur->next;
freeSpan(hf, cur);
if (prev)
prev->next = next;
else
hf.spans[idx] = next;
cur = next;
}
}
// Insert new span.
if (prev)
{
s->next = prev->next;
prev->next = s;
}
else
{
s->next = hf.spans[idx];
hf.spans[idx] = s;
}
}
static int clipPoly(const float* in, int n, float* out, float pnx, float pnz, float pd)
{
float d[12];
for (int i = 0; i < n; ++i)
d[i] = pnx*in[i*3+0] + pnz*in[i*3+2] + pd;
int m = 0;
for (int i = 0, j = n-1; i < n; j=i, ++i)
{
bool ina = d[j] >= 0;
bool inb = d[i] >= 0;
if (ina != inb)
{
float s = d[j] / (d[j] - d[i]);
out[m*3+0] = in[j*3+0] + (in[i*3+0] - in[j*3+0])*s;
out[m*3+1] = in[j*3+1] + (in[i*3+1] - in[j*3+1])*s;
out[m*3+2] = in[j*3+2] + (in[i*3+2] - in[j*3+2])*s;
m++;
}
if (inb)
{
out[m*3+0] = in[i*3+0];
out[m*3+1] = in[i*3+1];
out[m*3+2] = in[i*3+2];
m++;
}
}
return m;
}
static void rasterizeTri(const float* v0, const float* v1, const float* v2,
unsigned char flags, rcHeightfield& hf,
const float* bmin, const float* bmax,
const float cs, const float ics, const float ich)
{
const int w = hf.width;
const int h = hf.height;
float tmin[3], tmax[3];
const float by = bmax[1] - bmin[1];
// Calculate the bounding box of the triangle.
vcopy(tmin, v0);
vcopy(tmax, v0);
vmin(tmin, v1);
vmin(tmin, v2);
vmax(tmax, v1);
vmax(tmax, v2);
// If the triangle does not touch the bbox of the heightfield, skip the triagle.
if (!overlapBounds(bmin, bmax, tmin, tmax))
return;
// Calculate the footpring of the triangle on the grid.
int x0 = (int)((tmin[0] - bmin[0])*ics);
int y0 = (int)((tmin[2] - bmin[2])*ics);
int x1 = (int)((tmax[0] - bmin[0])*ics);
int y1 = (int)((tmax[2] - bmin[2])*ics);
x0 = rcClamp(x0, 0, w-1);
y0 = rcClamp(y0, 0, h-1);
x1 = rcClamp(x1, 0, w-1);
y1 = rcClamp(y1, 0, h-1);
// Clip the triangle into all grid cells it touches.
float in[7*3], out[7*3], inrow[7*3];
for (int y = y0; y <= y1; ++y)
{
// Clip polygon to row.
vcopy(&in[0], v0);
vcopy(&in[1*3], v1);
vcopy(&in[2*3], v2);
int nvrow = 3;
const float cz = bmin[2] + y*cs;
nvrow = clipPoly(in, nvrow, out, 0, 1, -cz);
if (nvrow < 3) continue;
nvrow = clipPoly(out, nvrow, inrow, 0, -1, cz+cs);
if (nvrow < 3) continue;
for (int x = x0; x <= x1; ++x)
{
// Clip polygon to column.
int nv = nvrow;
const float cx = bmin[0] + x*cs;
nv = clipPoly(inrow, nv, out, 1, 0, -cx);
if (nv < 3) continue;
nv = clipPoly(out, nv, in, -1, 0, cx+cs);
if (nv < 3) continue;
// Calculate min and max of the span.
float smin = in[1], smax = in[1];
for (int i = 1; i < nv; ++i)
{
smin = rcMin(smin, in[i*3+1]);
smax = rcMax(smax, in[i*3+1]);
}
smin -= bmin[1];
smax -= bmin[1];
// Skip the span if it is outside the heightfield bbox
if (smax < 0.0f) continue;
if (smin > by) continue;
// Clamp the span to the heightfield bbox.
if (smin < 0.0f) smin = bmin[1];
if (smax > by) smax = bmax[1];
// Snap the span to the heightfield height grid.
unsigned short ismin = (unsigned short)rcClamp((int)floorf(smin * ich), 0, 0x7fff);
unsigned short ismax = (unsigned short)rcClamp((int)ceilf(smax * ich), 0, 0x7fff);
addSpan(hf, x, y, ismin, ismax, flags);
}
}
}
void rcRasterizeTriangle(const float* v0, const float* v1, const float* v2,
unsigned char flags, rcHeightfield& solid)
{
rcTimeVal startTime = rcGetPerformanceTimer();
const float ics = 1.0f/solid.cs;
const float ich = 1.0f/solid.ch;
rasterizeTri(v0, v1, v2, flags, solid, solid.bmin, solid.bmax, solid.cs, ics, ich);
rcTimeVal endTime = rcGetPerformanceTimer();
if (rcGetBuildTimes())
rcGetBuildTimes()->rasterizeTriangles += rcGetDeltaTimeUsec(startTime, endTime);
}
void rcRasterizeTriangles(const float* verts, int nv,
const int* tris, const unsigned char* flags, int nt,
rcHeightfield& solid)
{
rcTimeVal startTime = rcGetPerformanceTimer();
const float ics = 1.0f/solid.cs;
const float ich = 1.0f/solid.ch;
// Rasterize triangles.
for (int i = 0; i < nt; ++i)
{
const float* v0 = &verts[tris[i*3+0]*3];
const float* v1 = &verts[tris[i*3+1]*3];
const float* v2 = &verts[tris[i*3+2]*3];
// Rasterize.
rasterizeTri(v0, v1, v2, flags[i], solid, solid.bmin, solid.bmax, solid.cs, ics, ich);
}
rcTimeVal endTime = rcGetPerformanceTimer();
if (rcGetBuildTimes())
rcGetBuildTimes()->rasterizeTriangles += rcGetDeltaTimeUsec(startTime, endTime);
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,58 @@
#include "RecastTimer.h"
#if defined(WIN32)
// Win32
#include <windows.h>
rcTimeVal rcGetPerformanceTimer()
{
__int64 count;
QueryPerformanceCounter((LARGE_INTEGER*)&count);
return count;
}
int rcGetDeltaTimeUsec(rcTimeVal start, rcTimeVal end)
{
static __int64 freq = 0;
if (freq == 0)
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
__int64 elapsed = end - start;
return (int)(elapsed*1000000 / freq);
}
#elif defined(__MACH__)
// OSX
#include <mach/mach_time.h>
rcTimeVal rcGetPerformanceTimer()
{
return mach_absolute_time();
}
int rcGetDeltaTimeUsec(rcTimeVal start, rcTimeVal end)
{
static mach_timebase_info_data_t timebaseInfo;
if (timebaseInfo.denom == 0)
mach_timebase_info(&timebaseInfo);
uint64_t elapsed = end - start;
uint64_t nanosec = elapsed * timebaseInfo.numer / timebaseInfo.denom;
return (int)(nanosec / 1000);
}
#else
// TODO: Linux, etc
rcTimeVal rcGetPerformanceTimer()
{
return 0;
}
int rcGetDeltaTimeUsec(rcTimeVal start, rcTimeVal end)
{
return 0;
}
#endif

11
extern/recastnavigation/SConscript vendored Normal file

@ -0,0 +1,11 @@
#!/usr/bin/python
Import('env')
sources = env.Glob('Recast/Source/*.cpp') + env.Glob('Detour/Source/*.cpp')
incs = 'Recast/Include Detour/Include'
env.BlenderLib ( 'extern_recastnavigation', sources, Split(incs), [],
libtype=['extern','player'],
priority=[10,185])

@ -366,11 +366,11 @@ void GHOST_NDOFManager::setDeadZone(float dz)
} }
else if (dz > 0.5f) { else if (dz > 0.5f) {
// warn the rogue user/programmer, but allow it // warn the rogue user/programmer, but allow it
printf("ndof: dead zone of %.2f is rather high...\n", dz); GHOST_PRINTF("ndof: dead zone of %.2f is rather high...\n", dz);
} }
m_deadZone = dz; m_deadZone = dz;
printf("ndof: dead zone set to %.2f\n", dz); GHOST_PRINTF("ndof: dead zone set to %.2f\n", dz);
} }
static bool atHomePosition(GHOST_TEventNDOFMotionData* ndof) static bool atHomePosition(GHOST_TEventNDOFMotionData* ndof)

@ -98,7 +98,8 @@ typedef unsigned long uintptr_t;
#include <inttypes.h> #include <inttypes.h>
#elif defined(FREE_WINDOWS) #elif defined(FREE_WINDOWS)
/* define htoln here, there must be a syntax error in winsock2.h in MinGW */
unsigned long __attribute__((__stdcall__)) htonl(unsigned long);
#include <stdint.h> #include <stdint.h>
#else #else
@ -109,12 +110,14 @@ typedef unsigned long uintptr_t;
#endif /* ifdef platform for types */ #endif /* ifdef platform for types */
#ifdef _WIN32 #ifdef _WIN32
#ifndef FREE_WINDOWS
#ifndef htonl #ifndef htonl
#define htonl(x) correctByteOrder(x) #define htonl(x) correctByteOrder(x)
#endif #endif
#ifndef ntohl #ifndef ntohl
#define ntohl(x) correctByteOrder(x) #define ntohl(x) correctByteOrder(x)
#endif #endif
#endif
#elif defined (__FreeBSD__) || defined (__OpenBSD__) #elif defined (__FreeBSD__) || defined (__OpenBSD__)
#include <sys/param.h> #include <sys/param.h>
#elif defined (__APPLE__) #elif defined (__APPLE__)

@ -31,6 +31,13 @@ remove_strict_flags()
# and debug gives a lot of prints on UV unwrapping. developers can enable if they need to. # and debug gives a lot of prints on UV unwrapping. developers can enable if they need to.
remove_flag("-DDEBUG") remove_flag("-DDEBUG")
# quiet compiler warnings about undefined defines
add_definitions(
-DDEBUGlevel=0
-DPRNTlevel=0
)
set(INC set(INC
extern extern
superlu superlu

@ -88,7 +88,7 @@ if(WITH_OPENMP)
endif() endif()
if(WITH_FFTW3) if(WITH_FFTW3)
add_definitions(-DFFTW3=1) add_definitions(-DWITH_FFTW3)
list(APPEND INC list(APPEND INC
${FFTW3_INCLUDE_DIRS} ${FFTW3_INCLUDE_DIRS}
) )

@ -16,7 +16,7 @@ incs += ' ' + env['BF_PNG_INC'] + ' ' + env['BF_ZLIB_INC']
incs += ' intern ../../extern/bullet2/src ../memutil ../guardealloc ' incs += ' intern ../../extern/bullet2/src ../memutil ../guardealloc '
if env['WITH_BF_FFTW3']: if env['WITH_BF_FFTW3']:
defs += ' FFTW3=1' defs += ' WITH_FFTW3'
incs += env['BF_FFTW3_INC'] incs += env['BF_FFTW3_INC']
env.BlenderLib ('bf_intern_smoke', sources, Split(incs), Split(defs), libtype=['intern'], priority=[40] ) env.BlenderLib ('bf_intern_smoke', sources, Split(incs), Split(defs), libtype=['intern'], priority=[40] )

@ -25,7 +25,7 @@
#ifndef FFT_NOISE_H_ #ifndef FFT_NOISE_H_
#define FFT_NOISE_H_ #define FFT_NOISE_H_
#if FFTW3==1 #ifdef WITH_FFTW3
#include <iostream> #include <iostream>
#include <fftw3.h> #include <fftw3.h>
#include <MERSENNETWISTER.h> #include <MERSENNETWISTER.h>

@ -155,7 +155,7 @@ void WTURBULENCE::setNoise(int type)
if(type == (1<<1)) // FFT if(type == (1<<1)) // FFT
{ {
// needs fft // needs fft
#if FFTW3==1 #ifdef WITH_FFTW3
std::string noiseTileFilename = std::string("noise.fft"); std::string noiseTileFilename = std::string("noise.fft");
generatTile_FFT(_noiseTile, noiseTileFilename); generatTile_FFT(_noiseTile, noiseTileFilename);
#endif #endif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 210 KiB

After

Width:  |  Height:  |  Size: 210 KiB

@ -356,7 +356,7 @@ class Mesh(bpy_types.ID):
@property @property
def edge_keys(self): def edge_keys(self):
return [edge_key for face in self.faces for edge_key in face.edge_keys] return [ed.key for ed in self.edges]
class MeshEdge(StructRNA): class MeshEdge(StructRNA):
@ -376,17 +376,31 @@ class MeshFace(StructRNA):
face_verts = self.vertices[:] face_verts = self.vertices[:]
mesh_verts = self.id_data.vertices mesh_verts = self.id_data.vertices
if len(face_verts) == 3: if len(face_verts) == 3:
return (mesh_verts[face_verts[0]].co + mesh_verts[face_verts[1]].co + mesh_verts[face_verts[2]].co) / 3.0 return (mesh_verts[face_verts[0]].co +
mesh_verts[face_verts[1]].co +
mesh_verts[face_verts[2]].co
) / 3.0
else: else:
return (mesh_verts[face_verts[0]].co + mesh_verts[face_verts[1]].co + mesh_verts[face_verts[2]].co + mesh_verts[face_verts[3]].co) / 4.0 return (mesh_verts[face_verts[0]].co +
mesh_verts[face_verts[1]].co +
mesh_verts[face_verts[2]].co +
mesh_verts[face_verts[3]].co
) / 4.0
@property @property
def edge_keys(self): def edge_keys(self):
verts = self.vertices[:] verts = self.vertices[:]
if len(verts) == 3: if len(verts) == 3:
return ord_ind(verts[0], verts[1]), ord_ind(verts[1], verts[2]), ord_ind(verts[2], verts[0]) return (ord_ind(verts[0], verts[1]),
ord_ind(verts[1], verts[2]),
return ord_ind(verts[0], verts[1]), ord_ind(verts[1], verts[2]), ord_ind(verts[2], verts[3]), ord_ind(verts[3], verts[0]) ord_ind(verts[2], verts[0]),
)
else:
return (ord_ind(verts[0], verts[1]),
ord_ind(verts[1], verts[2]),
ord_ind(verts[2], verts[3]),
ord_ind(verts[3], verts[0]),
)
class Text(bpy_types.ID): class Text(bpy_types.ID):

@ -685,7 +685,6 @@ data_path_update = [
] ]
import bpy
from bpy.types import Operator from bpy.types import Operator

@ -271,7 +271,8 @@ class BakeAction(Operator):
class ClearUselessActions(Operator): class ClearUselessActions(Operator):
'''Mark actions with no F-Curves for deletion after save+reload of file preserving "action libraries"''' '''Mark actions with no F-Curves for deletion after save+reload of ''' \
'''file preserving "action libraries"'''
bl_idname = "anim.clear_useless_actions" bl_idname = "anim.clear_useless_actions"
bl_label = "Clear Useless Actions" bl_label = "Clear Useless Actions"
bl_options = {'REGISTER', 'UNDO'} bl_options = {'REGISTER', 'UNDO'}
@ -292,12 +293,14 @@ class ClearUselessActions(Operator):
if ((self.only_unused is False) or if ((self.only_unused is False) or
(action.use_fake_user and action.users == 1)): (action.use_fake_user and action.users == 1)):
# if it has F-Curves, then it's a "action library" (i.e. walk, wave, jump, etc.) # if it has F-Curves, then it's a "action library"
# (i.e. walk, wave, jump, etc.)
# and should be left alone as that's what fake users are for! # and should be left alone as that's what fake users are for!
if not action.fcurves: if not action.fcurves:
# mark action for deletion # mark action for deletion
action.user_clear() action.user_clear()
removed += 1 removed += 1
self.report({'INFO'}, "Removed %d empty and/or fake-user only Actions" % (removed)) self.report({'INFO'}, "Removed %d empty and/or fake-user only Actions"
% removed)
return {'FINISHED'} return {'FINISHED'}

@ -74,6 +74,7 @@ class DATA_PT_skeleton(ArmatureButtonsPanel, Panel):
if context.scene.render.engine == "BLENDER_GAME": if context.scene.render.engine == "BLENDER_GAME":
layout.row().prop(arm, "vert_deformer", expand=True) layout.row().prop(arm, "vert_deformer", expand=True)
class DATA_PT_display(ArmatureButtonsPanel, Panel): class DATA_PT_display(ArmatureButtonsPanel, Panel):
bl_label = "Display" bl_label = "Display"
@ -185,11 +186,10 @@ class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
layout.template_ID(ob, "pose_library", new="poselib.new", unlink="poselib.unlink") layout.template_ID(ob, "pose_library", new="poselib.new", unlink="poselib.unlink")
if poselib: if poselib:
# list of poses in pose library
# list of poses in pose library
row = layout.row() row = layout.row()
row.template_list(poselib, "pose_markers", poselib.pose_markers, "active_index", rows=5) row.template_list(poselib, "pose_markers", poselib.pose_markers, "active_index", rows=5)
# column of operators for active pose # column of operators for active pose
# - goes beside list # - goes beside list
col = row.column(align=True) col = row.column(align=True)
@ -206,9 +206,9 @@ class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
if pose_marker_active is not None: if pose_marker_active is not None:
col.operator("poselib.pose_remove", icon='ZOOMOUT', text="").pose = pose_marker_active.name col.operator("poselib.pose_remove", icon='ZOOMOUT', text="").pose = pose_marker_active.name
col.operator("poselib.apply_pose", icon='ZOOM_SELECTED', text="").pose_index = poselib.pose_markers.active_index col.operator("poselib.apply_pose", icon='ZOOM_SELECTED', text="").pose_index = poselib.pose_markers.active_index
col.operator("poselib.action_sanitise", icon='HELP', text="") # XXX: put in menu? col.operator("poselib.action_sanitise", icon='HELP', text="") # XXX: put in menu?
# properties for active marker # properties for active marker
if pose_marker_active is not None: if pose_marker_active is not None:
layout.prop(pose_marker_active, "name") layout.prop(pose_marker_active, "name")

@ -379,6 +379,10 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
col.label(text="Mirror Object:") col.label(text="Mirror Object:")
col.prop(md, "mirror_object", text="") col.prop(md, "mirror_object", text="")
def NAVMESH(self, layout, ob, md):
layout.operator("object.assign_navpolygon")
layout.operator("object.assign_new_navpolygon")
def MULTIRES(self, layout, ob, md): def MULTIRES(self, layout, ob, md):
layout.row().prop(md, "subdivision_type", expand=True) layout.row().prop(md, "subdivision_type", expand=True)
@ -608,32 +612,31 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
layout.label(text="Settings can be found inside the Physics context") layout.label(text="Settings can be found inside the Physics context")
def UV_PROJECT(self, layout, ob, md): def UV_PROJECT(self, layout, ob, md):
if ob.type == 'MESH': split = layout.split()
split = layout.split()
col = split.column() col = split.column()
col.label(text="Image:") col.label(text="Image:")
col.prop(md, "image", text="") col.prop(md, "image", text="")
col = split.column() col = split.column()
col.label(text="UV Layer:") col.label(text="UV Layer:")
col.prop_search(md, "uv_layer", ob.data, "uv_textures", text="") col.prop_search(md, "uv_layer", ob.data, "uv_textures", text="")
split = layout.split() split = layout.split()
col = split.column() col = split.column()
col.prop(md, "use_image_override") col.prop(md, "use_image_override")
col.prop(md, "projector_count", text="Projectors") col.prop(md, "projector_count", text="Projectors")
for proj in md.projectors: for proj in md.projectors:
col.prop(proj, "object", text="") col.prop(proj, "object", text="")
col = split.column() col = split.column()
sub = col.column(align=True) sub = col.column(align=True)
sub.prop(md, "aspect_x", text="Aspect X") sub.prop(md, "aspect_x", text="Aspect X")
sub.prop(md, "aspect_y", text="Aspect Y") sub.prop(md, "aspect_y", text="Aspect Y")
sub = col.column(align=True) sub = col.column(align=True)
sub.prop(md, "scale_x", text="Scale X") sub.prop(md, "scale_x", text="Scale X")
sub.prop(md, "scale_y", text="Scale Y") sub.prop(md, "scale_y", text="Scale Y")
def WARP(self, layout, ob, md): def WARP(self, layout, ob, md):
use_falloff = (md.falloff_type != 'NONE') use_falloff = (md.falloff_type != 'NONE')
@ -737,5 +740,119 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
col.prop(md, "width", slider=True) col.prop(md, "width", slider=True)
col.prop(md, "narrowness", slider=True) col.prop(md, "narrowness", slider=True)
@staticmethod
def vertex_weight_mask(layout, ob, md):
layout.label(text="Influence/Mask Options:")
split = layout.split(percentage=0.4)
split.label(text="Global Influence:")
split.prop(md, "mask_constant", text="")
if not md.mask_texture:
split = layout.split(percentage=0.4)
split.label(text="Vertex Group Mask:")
split.prop_search(md, "mask_vertex_group", ob, "vertex_groups", text="")
if not md.mask_vertex_group:
split = layout.split(percentage=0.4)
split.label(text="Texture Mask:")
split.template_ID(md, "mask_texture", new="texture.new")
if md.mask_texture:
split = layout.split()
col = split.column()
col.label(text="Texture Coordinates:")
col.prop(md, "mask_tex_mapping", text="")
col = split.column()
col.label(text="Use Channel:")
col.prop(md, "mask_tex_use_channel", text="")
if md.mask_tex_mapping == 'OBJECT':
layout.prop(md, "mask_tex_map_object", text="Object")
elif md.mask_tex_mapping == 'UV' and ob.type == 'MESH':
layout.prop_search(md, "mask_tex_uv_layer", ob.data, "uv_textures")
def VERTEX_WEIGHT_EDIT(self, layout, ob, md):
split = layout.split()
col = split.column()
col.label(text="Vertex Group:")
col.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
col = split.column()
col.label(text="Default Weight:")
col.prop(md, "default_weight", text="")
layout.prop(md, "falloff_type")
if md.falloff_type == 'CURVE':
col = layout.column()
col.template_curve_mapping(md, "map_curve")
split = layout.split(percentage=0.4)
split.prop(md, "use_add")
row = split.row()
row.active = md.use_add
row.prop(md, "add_threshold")
split = layout.split(percentage=0.4)
split.prop(md, "use_remove")
row = split.row()
row.active = md.use_remove
row.prop(md, "remove_threshold")
# Common mask options
layout.separator()
self.vertex_weight_mask(layout, ob, md)
def VERTEX_WEIGHT_MIX(self, layout, ob, md):
split = layout.split()
col = split.column()
col.label(text="Vertex Group A:")
col.prop_search(md, "vertex_group_a", ob, "vertex_groups", text="")
col.label(text="Default Weight A:")
col.prop(md, "default_weight_a", text="")
col.label(text="Mix Mode:")
col.prop(md, "mix_mode", text="")
col = split.column()
col.label(text="Vertex Group B:")
col.prop_search(md, "vertex_group_b", ob, "vertex_groups", text="")
col.label(text="Default Weight B:")
col.prop(md, "default_weight_b", text="")
col.label(text="Mix Set:")
col.prop(md, "mix_set", text="")
# Common mask options
layout.separator()
self.vertex_weight_mask(layout, ob, md)
def VERTEX_WEIGHT_PROXIMITY(self, layout, ob, md):
split = layout.split()
col = split.column()
col.label(text="Vertex Group:")
col.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
col = split.column()
col.label(text="Target Object:")
col.prop(md, "target", text="")
layout.row().prop(md, "proximity_mode", expand=True)
if md.proximity_mode == 'GEOMETRY':
layout.row().prop(md, "proximity_geometry", expand=True)
row = layout.row()
row.prop(md, "min_dist")
row.prop(md, "max_dist")
layout.prop(md, "falloff_type")
# Common mask options
layout.separator()
self.vertex_weight_mask(layout, ob, md)
if __name__ == "__main__": # only for live edit. if __name__ == "__main__": # only for live edit.
bpy.utils.register_module(__name__) bpy.utils.register_module(__name__)

@ -81,7 +81,7 @@ class DATA_PT_distance(DataButtonsPanel, bpy.types.Panel):
speaker = context.speaker speaker = context.speaker
split = layout.split() split = layout.split()
col = split.column() col = split.column()
col.label("Volume:") col.label("Volume:")
col.prop(speaker, "volume_min", text="Minimum") col.prop(speaker, "volume_min", text="Minimum")

@ -195,6 +195,31 @@ class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel, Panel):
row.prop(game, "collision_margin", text="Margin", slider=True) row.prop(game, "collision_margin", text="Margin", slider=True)
row.prop(game, "use_collision_compound", text="Compound") row.prop(game, "use_collision_compound", text="Compound")
class PHYSICS_PT_game_obstacles(PhysicsButtonsPanel, Panel):
bl_label = "Create Obstacle"
COMPAT_ENGINES = {'BLENDER_GAME'}
@classmethod
def poll(cls, context):
game = context.object.game
rd = context.scene.render
return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC')) and (rd.engine in cls.COMPAT_ENGINES)
def draw_header(self, context):
game = context.active_object.game
self.layout.prop(game, "create_obstacle", text="")
def draw(self, context):
layout = self.layout
game = context.active_object.game
layout.active = game.create_obstacle
row = layout.row()
row.prop(game, "obstacle_radius", text="Radius")
row.label()
class RenderButtonsPanel(): class RenderButtonsPanel():
bl_space_type = 'PROPERTIES' bl_space_type = 'PROPERTIES'
@ -344,7 +369,7 @@ class RENDER_PT_game_performance(RenderButtonsPanel, Panel):
row = col.row() row = col.row()
row.prop(gs, "use_frame_rate") row.prop(gs, "use_frame_rate")
row.prop(gs, "use_display_lists") row.prop(gs, "use_display_lists")
col.prop(gs, "restrict_animation_updates") col.prop(gs, "restrict_animation_updates")
@ -362,6 +387,68 @@ class RENDER_PT_game_display(RenderButtonsPanel, Panel):
flow.prop(gs, "show_physics_visualization", text="Physics Visualization") flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
flow.prop(gs, "use_deprecation_warnings") flow.prop(gs, "use_deprecation_warnings")
flow.prop(gs, "show_mouse", text="Mouse Cursor") flow.prop(gs, "show_mouse", text="Mouse Cursor")
class SceneButtonsPanel():
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
class SCENE_PT_game_navmesh(SceneButtonsPanel, bpy.types.Panel):
bl_label = "Navigation mesh"
bl_default_closed = True
COMPAT_ENGINES = {'BLENDER_GAME'}
@classmethod
def poll(cls, context):
scene = context.scene
return (scene and scene.render.engine in cls.COMPAT_ENGINES)
def draw(self, context):
layout = self.layout
rd = context.scene.game_settings.recast_data
layout.operator("object.create_navmesh", text='Build navigation mesh')
col = layout.column()
col.label(text="Rasterization:")
row = col.row()
row.prop(rd, "cell_size")
row.prop(rd, "cell_height")
col = layout.column()
col.label(text="Agent:")
split = col.split()
col = split.column()
col.prop(rd, "agent_height", text="Height")
col.prop(rd, "agent_radius", text="Radius")
col = split.column()
col.prop(rd, "max_slope")
col.prop(rd, "max_climb")
col = layout.column()
col.label(text="Region:")
row = col.row()
row.prop(rd, "region_min_size")
row.prop(rd, "region_merge_size")
col = layout.column()
col.label(text="Polygonization:")
split = col.split()
col = split.column()
col.prop(rd, "edge_max_len")
col.prop(rd, "edge_max_error")
split.prop(rd, "verts_per_poly")
col = layout.column()
col.label(text="Detail Mesh:")
row = col.row()
row.prop(rd, "sample_dist")
row.prop(rd, "sample_max_error")
class WorldButtonsPanel(): class WorldButtonsPanel():
@ -487,5 +574,24 @@ class WORLD_PT_game_physics(WorldButtonsPanel, Panel):
col.label(text="Logic Steps:") col.label(text="Logic Steps:")
col.prop(gs, "logic_step_max", text="Max") col.prop(gs, "logic_step_max", text="Max")
class WORLD_PT_game_physics_obstacles(WorldButtonsPanel, Panel):
bl_label = "Obstacle simulation"
COMPAT_ENGINES = {'BLENDER_GAME'}
@classmethod
def poll(cls, context):
scene = context.scene
return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
def draw(self, context):
layout = self.layout
gs = context.scene.game_settings
layout.prop(gs, "obstacle_simulation", text = "Type")
if gs.obstacle_simulation != 'NONE':
layout.prop(gs, "level_height")
layout.prop(gs, "show_obstacle_simulation")
if __name__ == "__main__": # only for live edit. if __name__ == "__main__": # only for live edit.
bpy.utils.register_module(__name__) bpy.utils.register_module(__name__)

@ -46,7 +46,7 @@ class PHYSICS_PT_fluid(PhysicButtonsPanel, Panel):
row = layout.row() row = layout.row()
if fluid is None: if fluid is None:
row.label("built without fluids") row.label("Built without fluids")
return return
row.prop(fluid, "type") row.prop(fluid, "type")

@ -773,7 +773,18 @@ class USERPREF_MT_ndof_settings(Menu):
layout.separator() layout.separator()
layout.label(text="orbit options") layout.label(text="orbit options")
layout.prop(input_prefs, "ndof_orbit_invert_axes") if input_prefs.view_rotate_method == 'TRACKBALL':
layout.prop(input_prefs, "ndof_roll_invert_axis")
layout.prop(input_prefs, "ndof_tilt_invert_axis")
layout.prop(input_prefs, "ndof_rotate_invert_axis")
else:
layout.prop(input_prefs, "ndof_orbit_invert_axes")
layout.separator()
layout.label(text="pan options")
layout.prop(input_prefs, "ndof_panx_invert_axis")
layout.prop(input_prefs, "ndof_pany_invert_axis")
layout.prop(input_prefs, "ndof_panz_invert_axis")
layout.separator() layout.separator()
layout.label(text="fly options") layout.label(text="fly options")

@ -54,6 +54,9 @@ def draw_gpencil_tools(context, layout):
row = col.row() row = col.row()
row.operator("gpencil.draw", text="Draw").mode = 'DRAW' row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT' row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
row = col.row()
row.operator("gpencil.draw", text="Poly").mode = 'DRAW_POLY'
row.operator("gpencil.draw", text="Erase").mode = 'ERASER' row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
row = col.row() row = col.row()
@ -765,9 +768,9 @@ class VIEW3D_PT_tools_brush_texture(PaintPanel, Panel):
col = row.column() col = row.column()
if brush.use_texture_overlay: if brush.use_texture_overlay:
col.prop(brush, "use_texture_overlay", toggle=True, text="", icon='MUTE_IPO_OFF') col.prop(brush, "use_texture_overlay", toggle=True, text="", icon='RESTRICT_VIEW_OFF')
else: else:
col.prop(brush, "use_texture_overlay", toggle=True, text="", icon='MUTE_IPO_ON') col.prop(brush, "use_texture_overlay", toggle=True, text="", icon='RESTRICT_VIEW_ON')
col.active = tex_slot.map_mode in {'FIXED', 'TILED'} col.active = tex_slot.map_mode in {'FIXED', 'TILED'}

@ -44,7 +44,7 @@ extern "C" {
* and keep comment above the defines. * and keep comment above the defines.
* Use STRINGIFY() rather than defining with quotes */ * Use STRINGIFY() rather than defining with quotes */
#define BLENDER_VERSION 259 #define BLENDER_VERSION 259
#define BLENDER_SUBVERSION 1 #define BLENDER_SUBVERSION 2
#define BLENDER_MINVERSION 250 #define BLENDER_MINVERSION 250
#define BLENDER_MINSUBVERSION 0 #define BLENDER_MINSUBVERSION 0

@ -111,7 +111,7 @@ typedef struct Global {
#define G_SCRIPT_OVERRIDE_PREF (1 << 14) /* when this flag is set ignore the userprefs */ #define G_SCRIPT_OVERRIDE_PREF (1 << 14) /* when this flag is set ignore the userprefs */
/* #define G_NOFROZEN (1 << 17) also removed */ /* #define G_NOFROZEN (1 << 17) also removed */
#define G_GREASEPENCIL (1 << 17) /* #define G_GREASEPENCIL (1 << 17) also removed */
/* #define G_AUTOMATKEYS (1 << 30) also removed */ /* #define G_AUTOMATKEYS (1 << 30) also removed */

@ -37,6 +37,10 @@
* \ingroup bke * \ingroup bke
*/ */
#include "DNA_listBase.h"
#include "RNA_types.h"
/* not very important, but the stack solver likes to know a maximum */ /* not very important, but the stack solver likes to know a maximum */
#define MAX_SOCKET 64 #define MAX_SOCKET 64
@ -46,63 +50,151 @@ struct bNodeLink;
struct bNodeSocket; struct bNodeSocket;
struct bNodeStack; struct bNodeStack;
struct bNodeTree; struct bNodeTree;
struct bNodeTreeExec;
struct GPUMaterial; struct GPUMaterial;
struct GPUNode; struct GPUNode;
struct GPUNodeStack; struct GPUNodeStack;
struct ID; struct ID;
struct ListBase; struct ListBase;
struct Main; struct Main;
struct uiBlock;
struct uiLayout;
struct MTex; struct MTex;
struct PointerRNA; struct PointerRNA;
struct rctf; struct rctf;
struct RenderData; struct RenderData;
struct Scene; struct Scene;
struct Tex; struct Tex;
struct uiLayout; struct SpaceNode;
struct ARegion;
struct Object;
/* ************** NODE TYPE DEFINITIONS ***** */ /* ************** NODE TYPE DEFINITIONS ***** */
typedef struct bNodeSocketType { /** Compact definition of a node socket.
* Can be used to quickly define a list of static sockets for a node,
* which are added to each new node of that type.
*
* \deprecated New nodes should add default sockets in the initialization
* function instead. This struct is mostly kept for old nodes and should
* be removed some time.
*/
typedef struct bNodeSocketTemplate {
int type, limit; int type, limit;
const char *name; char name[32];
float val1, val2, val3, val4; /* default alloc value for inputs */ float val1, val2, val3, val4; /* default alloc value for inputs */
float min, max; /* default range for inputs */ float min, max;
PropertySubType subtype;
/* after this line is used internal only */ /* after this line is used internal only */
struct bNodeSocket *sock; /* used during verify_types */ struct bNodeSocket *sock; /* used to hold verified socket */
} bNodeSocketTemplate;
typedef void (*NodeSocketButtonFunction)(const struct bContext *C, struct uiBlock *block,
struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock,
const char *name, int x, int y, int width);
/** Defines a socket type.
* Defines the appearance and behavior of a socket in the UI.
*/
typedef struct bNodeSocketType {
int type;
char ui_name[32];
char ui_description[128];
int ui_icon;
char ui_color[4];
const char *value_structname;
int value_structsize;
NodeSocketButtonFunction buttonfunc;
} bNodeSocketType; } bNodeSocketType;
/** Template for creating a node.
* Stored required parameters to make a new node of a specific type.
*/
typedef struct bNodeTemplate {
int type;
/* group tree */
struct bNodeTree *ngroup;
} bNodeTemplate;
/** Defines a node type.
* Initial attributes and constants for a node as well as callback functions
* implementing the node behavior.
*/
typedef struct bNodeType { typedef struct bNodeType {
void *next,*prev; void *next,*prev;
short needs_free; /* set for allocated types that need to be freed */
int type; int type;
const char *name; /* can be allocated too */ char name[32];
float width, minwidth, maxwidth; float width, minwidth, maxwidth;
float height, minheight, maxheight;
short nclass, flag; short nclass, flag;
bNodeSocketType *inputs, *outputs; /* templates for static sockets */
bNodeSocketTemplate *inputs, *outputs;
char storagename[64]; /* struct name for DNA */ char storagename[64]; /* struct name for DNA */
void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **); /// Main draw function for the node.
void (*drawfunc)(const struct bContext *C, struct ARegion *ar, struct SpaceNode *snode, struct bNodeTree *ntree, struct bNode *node);
/* this line is set on startup of blender */ /// Updates the node geometry attributes according to internal state before actual drawing.
void (*drawupdatefunc)(const struct bContext *C, struct bNodeTree *ntree, struct bNode *node);
/// Draw the option buttons on the node.
void (*uifunc)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr); void (*uifunc)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
/// Additional parameters in the side panel.
void (*uifuncbut)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr); void (*uifuncbut)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
/// Optional custom label function for the node header.
const char *(*labelfunc)(struct bNode *); const char *(*labelfunc)(struct bNode *);
/// Optional custom resize handle polling.
void (*initfunc)(struct bNode *); int (*resize_area_func)(struct bNode *node, int x, int y);
void (*freestoragefunc)(struct bNode *);
void (*copystoragefunc)(struct bNode *, struct bNode *);
/* for use with dynamic typedefs */ /// Called when the node is updated in the editor.
ID *id; void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node);
void *pynode; /* holds pointer to python script */ /// Check and update if internal ID data has changed.
void *pydict; /* holds pointer to python script dictionary (scope)*/ void (*verifyfunc)(struct bNodeTree *ntree, struct bNode *node, struct ID *id);
/// Initialize a new node instance of this type after creation.
void (*initfunc)(struct bNodeTree *ntree, struct bNode *node, struct bNodeTemplate *ntemp);
/// Free the custom storage data.
void (*freestoragefunc)(struct bNode *node);
/// Make a copy of the custom storage data.
void (*copystoragefunc)(struct bNode *node, struct bNode *target);
/// Create a template from an existing node.
struct bNodeTemplate (*templatefunc)(struct bNode *);
/** If a node can be made from the template in the given node tree.
* \example Node groups can not be created inside their own node tree.
*/
int (*validfunc)(struct bNodeTree *ntree, struct bNodeTemplate *ntemp);
/// Initialize a node tree associated to this node type.
void (*inittreefunc)(struct bNodeTree *ntree);
/// Update a node tree associated to this node type.
void (*updatetreefunc)(struct bNodeTree *ntree);
/* group edit callbacks for operators */
/* XXX this is going to be changed as required by the UI */
struct bNodeTree *(*group_edit_get)(struct bNode *node);
struct bNodeTree *(*group_edit_set)(struct bNode *node, int edit);
void (*group_edit_clear)(struct bNode *node);
/* **** execution callbacks **** */
void *(*initexecfunc)(struct bNode *node);
void (*freeexecfunc)(struct bNode *node, void *nodedata);
void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **);
/* XXX this alternative exec function has been added to avoid changing all node types.
* when a final generic version of execution code is defined, this will be changed anyway
*/
void (*newexecfunc)(void *data, int thread, struct bNode *, void *nodedata, struct bNodeStack **, struct bNodeStack **);
/* gpu */ /* gpu */
int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out); int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out);
/* extended gpu function */
int (*gpuextfunc)(struct GPUMaterial *mat, struct bNode *node, void *nodedata, struct GPUNodeStack *in, struct GPUNodeStack *out);
} bNodeType; } bNodeType;
/* node->exec, now in use for composites (#define for break is same as ready yes) */ /* node->exec, now in use for composites (#define for break is same as ready yes) */
@ -113,72 +205,124 @@ typedef struct bNodeType {
#define NODE_FREEBUFS 8 #define NODE_FREEBUFS 8
#define NODE_SKIPPED 16 #define NODE_SKIPPED 16
/* sim_exec return value */
#define NODE_EXEC_FINISHED 0
#define NODE_EXEC_SUSPEND 1
/* nodetype->nclass, for add-menu and themes */ /* nodetype->nclass, for add-menu and themes */
#define NODE_CLASS_INPUT 0 #define NODE_CLASS_INPUT 0
#define NODE_CLASS_OUTPUT 1 #define NODE_CLASS_OUTPUT 1
#define NODE_CLASS_OP_COLOR 3 #define NODE_CLASS_OP_COLOR 3
#define NODE_CLASS_OP_VECTOR 4 #define NODE_CLASS_OP_VECTOR 4
#define NODE_CLASS_OP_FILTER 5 #define NODE_CLASS_OP_FILTER 5
#define NODE_CLASS_GROUP 6 #define NODE_CLASS_GROUP 6
#define NODE_CLASS_FILE 7 #define NODE_CLASS_FILE 7
#define NODE_CLASS_CONVERTOR 8 #define NODE_CLASS_CONVERTOR 8
#define NODE_CLASS_MATTE 9 #define NODE_CLASS_MATTE 9
#define NODE_CLASS_DISTORT 10 #define NODE_CLASS_DISTORT 10
#define NODE_CLASS_OP_DYNAMIC 11 #define NODE_CLASS_OP_DYNAMIC 11
#define NODE_CLASS_PATTERN 12 #define NODE_CLASS_PATTERN 12
#define NODE_CLASS_TEXTURE 13 #define NODE_CLASS_TEXTURE 13
#define NODE_CLASS_EXECUTION 14
#define NODE_CLASS_GETDATA 15
#define NODE_CLASS_SETDATA 16
#define NODE_CLASS_MATH 17
#define NODE_CLASS_MATH_VECTOR 18
#define NODE_CLASS_MATH_ROTATION 19
#define NODE_CLASS_PARTICLES 25
#define NODE_CLASS_TRANSFORM 30
#define NODE_CLASS_COMBINE 31
#define NODE_CLASS_LAYOUT 100
/* enum values for input/output */ /* enum values for input/output */
#define SOCK_IN 1 #define SOCK_IN 1
#define SOCK_OUT 2 #define SOCK_OUT 2
struct bNodeTreeExec;
typedef void (*bNodeTreeCallback)(void *calldata, struct ID *owner_id, struct bNodeTree *ntree);
typedef struct bNodeTreeType
{
int type; /* type identifier */
char idname[64]; /* id name for RNA identification */
ListBase node_types; /* type definitions */
/* callbacks */
void (*free_cache)(struct bNodeTree *ntree);
void (*free_node_cache)(struct bNodeTree *ntree, struct bNode *node);
void (*foreach_nodetree)(struct Main *main, void *calldata, bNodeTreeCallback func); /* iteration over all node trees */
/* calls allowing threaded composite */
void (*localize)(struct bNodeTree *localtree, struct bNodeTree *ntree);
void (*local_sync)(struct bNodeTree *localtree, struct bNodeTree *ntree);
void (*local_merge)(struct bNodeTree *localtree, struct bNodeTree *ntree);
/* Tree update. Overrides nodetype->updatetreefunc! */
void (*update)(struct bNodeTree *ntree);
/* Node update. Overrides nodetype->updatefunc! */
void (*update_node)(struct bNodeTree *ntree, struct bNode *node);
int (*validate_link)(struct bNodeTree *ntree, struct bNodeLink *link);
} bNodeTreeType;
/* ************** GENERIC API, TREES *************** */ /* ************** GENERIC API, TREES *************** */
void ntreeVerifyTypes(struct bNodeTree *ntree); struct bNodeTreeType *ntreeGetType(int type);
struct bNodeType *ntreeGetNodeType(struct bNodeTree *ntree);
struct bNodeSocketType *ntreeGetSocketType(int type);
struct bNodeTree *ntreeAddTree(const char *name, int type, const short is_group); struct bNodeTree *ntreeAddTree(const char *name, int type, int nodetype);
void ntreeInitTypes(struct bNodeTree *ntree); void ntreeInitTypes(struct bNodeTree *ntree);
//void ntreeMakeGroupSockets(struct bNodeTree *ntree);
void ntreeUpdateType(struct bNodeTree *ntree, struct bNodeType *ntype);
void ntreeFreeTree(struct bNodeTree *ntree); void ntreeFreeTree(struct bNodeTree *ntree);
struct bNodeTree *ntreeCopyTree(struct bNodeTree *ntree); struct bNodeTree *ntreeCopyTree(struct bNodeTree *ntree);
void ntreeSwitchID(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sce_to); void ntreeSwitchID(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sce_to);
void ntreeMakeLocal(struct bNodeTree *ntree); void ntreeMakeLocal(struct bNodeTree *ntree);
int ntreeHasType(struct bNodeTree *ntree, int type);
void ntreeSocketUseFlags(struct bNodeTree *ntree); void ntreeSocketUseFlags(struct bNodeTree *ntree);
void ntreeSolveOrder(struct bNodeTree *ntree); void ntreeUpdateTree(struct bNodeTree *ntree);
/* XXX Currently each tree update call does call to ntreeVerifyNodes too.
* Some day this should be replaced by a decent depsgraph automatism!
*/
void ntreeVerifyNodes(struct Main *main, struct ID *id);
void ntreeBeginExecTree(struct bNodeTree *ntree); void ntreeGetDependencyList(struct bNodeTree *ntree, struct bNode ***deplist, int *totnodes);
void ntreeExecTree(struct bNodeTree *ntree, void *callerdata, int thread);
void ntreeCompositExecTree(struct bNodeTree *ntree, struct RenderData *rd, int do_previews);
void ntreeEndExecTree(struct bNodeTree *ntree);
/* XXX old trees handle output flags automatically based on special output node types and last active selection.
* new tree types have a per-output socket flag to indicate the final output to use explicitly.
*/
void ntreeSetOutput(struct bNodeTree *ntree);
void ntreeInitPreview(struct bNodeTree *, int xsize, int ysize); void ntreeInitPreview(struct bNodeTree *, int xsize, int ysize);
void ntreeClearPreview(struct bNodeTree *ntree); void ntreeClearPreview(struct bNodeTree *ntree);
void ntreeFreeCache(struct bNodeTree *ntree); void ntreeFreeCache(struct bNodeTree *ntree);
/* calls allowing threaded composite */ int ntreeNodeExists(struct bNodeTree *ntree, struct bNode *testnode);
int ntreeOutputExists(struct bNode *node, struct bNodeSocket *testsock);
struct bNodeTree *ntreeLocalize(struct bNodeTree *ntree); struct bNodeTree *ntreeLocalize(struct bNodeTree *ntree);
void ntreeLocalSync(struct bNodeTree *localtree, struct bNodeTree *ntree); void ntreeLocalSync(struct bNodeTree *localtree, struct bNodeTree *ntree);
void ntreeLocalMerge(struct bNodeTree *localtree, struct bNodeTree *ntree); void ntreeLocalMerge(struct bNodeTree *localtree, struct bNodeTree *ntree);
/* ************** GENERIC API, NODES *************** */ /* ************** GENERIC API, NODES *************** */
void nodeVerifyType(struct bNodeTree *ntree, struct bNode *node); struct bNodeSocket *nodeAddSocket(struct bNodeTree *ntree, struct bNode *node, int in_out, const char *name, int type);
struct bNodeSocket *nodeInsertSocket(struct bNodeTree *ntree, struct bNode *node, int in_out, struct bNodeSocket *next_sock, const char *name, int type);
void nodeRemoveSocket(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock);
void nodeRemoveAllSockets(struct bNodeTree *ntree, struct bNode *node);
void nodeAddToPreview(struct bNode *, float *, int, int, int); void nodeAddToPreview(struct bNode *, float *, int, int, int);
struct bNode *nodeAddNode(struct bNodeTree *ntree, struct bNodeTemplate *ntemp);
void nodeUnlinkNode(struct bNodeTree *ntree, struct bNode *node); void nodeUnlinkNode(struct bNodeTree *ntree, struct bNode *node);
void nodeUniqueName(struct bNodeTree *ntree, struct bNode *node); void nodeUniqueName(struct bNodeTree *ntree, struct bNode *node);
void nodeAddSockets(struct bNode *node, struct bNodeType *ntype);
struct bNode *nodeAddNodeType(struct bNodeTree *ntree, int type, struct bNodeTree *ngroup, struct ID *id); void nodeRegisterType(struct ListBase *typelist, struct bNodeType *ntype) ;
void nodeRegisterType(struct ListBase *typelist, const struct bNodeType *ntype) ;
void nodeUpdateType(struct bNodeTree *ntree, struct bNode* node, struct bNodeType *ntype);
void nodeMakeDynamicType(struct bNode *node); void nodeMakeDynamicType(struct bNode *node);
int nodeDynamicUnlinkText(struct ID *txtid); int nodeDynamicUnlinkText(struct ID *txtid);
void nodeFreeNode(struct bNodeTree *ntree, struct bNode *node); void nodeFreeNode(struct bNodeTree *ntree, struct bNode *node);
struct bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node); struct bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node);
@ -186,6 +330,10 @@ struct bNodeLink *nodeAddLink(struct bNodeTree *ntree, struct bNode *fromnode, s
void nodeRemLink(struct bNodeTree *ntree, struct bNodeLink *link); void nodeRemLink(struct bNodeTree *ntree, struct bNodeLink *link);
void nodeRemSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock); void nodeRemSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock);
void nodeSpaceCoords(struct bNode *node, float *locx, float *locy);
void nodeAttachNode(struct bNode *node, struct bNode *parent);
void nodeDetachNode(struct bNode *node);
struct bNode *nodeFindNodebyName(struct bNodeTree *ntree, const char *name); struct bNode *nodeFindNodebyName(struct bNodeTree *ntree, const char *name);
int nodeFindNode(struct bNodeTree *ntree, struct bNodeSocket *sock, struct bNode **nodep, int *sockindex, int *in_out); int nodeFindNode(struct bNodeTree *ntree, struct bNodeSocket *sock, struct bNode **nodep, int *sockindex, int *in_out);
@ -202,41 +350,71 @@ void NodeTagChanged(struct bNodeTree *ntree, struct bNode *node);
int NodeTagIDChanged(struct bNodeTree *ntree, struct ID *id); int NodeTagIDChanged(struct bNodeTree *ntree, struct ID *id);
void ntreeClearTags(struct bNodeTree *ntree); void ntreeClearTags(struct bNodeTree *ntree);
/* ************** Groups ****************** */ void nodeFreePreview(struct bNode *node);
struct bNode *nodeMakeGroupFromSelected(struct bNodeTree *ntree); /* ************** NODE TYPE ACCESS *************** */
int nodeGroupUnGroup(struct bNodeTree *ntree, struct bNode *gnode);
void nodeGroupVerify(struct bNodeTree *ngroup); struct bNodeTemplate nodeMakeTemplate(struct bNode *node);
void nodeGroupSocketUseFlags(struct bNodeTree *ngroup); int nodeValid(struct bNodeTree *ntree, struct bNodeTemplate *ntemp);
const char* nodeLabel(struct bNode *node);
void nodeGroupCopy(struct bNode *gnode); struct bNodeTree *nodeGroupEditGet(struct bNode *node);
struct bNodeTree *nodeGroupEditSet(struct bNode *node, int edit);
struct bNodeSocket *nodeGroupAddSocket(struct bNodeTree *ngroup, const char *name, int type, int in_out); void nodeGroupEditClear(struct bNode *node);
struct bNodeSocket *nodeGroupExposeSocket(struct bNodeTree *ngroup, struct bNodeSocket *sock, int in_out);
void nodeGroupExposeAllSockets(struct bNodeTree *ngroup);
void nodeGroupRemoveSocket(struct bNodeTree *ngroup, struct bNodeSocket *gsock, int in_out);
/* ************** COMMON NODES *************** */
/* Init a new node type struct with default values and callbacks */ /* Init a new node type struct with default values and callbacks */
void node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag, void node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag);
struct bNodeSocketType *inputs, struct bNodeSocketType *outputs); void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs);
void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth); void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth);
void node_type_init(struct bNodeType *ntype, void (*initfunc)(struct bNode *)); void node_type_init(struct bNodeType *ntype, void (*initfunc)(struct bNodeTree *ntree, struct bNode *node, struct bNodeTemplate *ntemp));
void node_type_valid(struct bNodeType *ntype, int (*validfunc)(struct bNodeTree *ntree, struct bNodeTemplate *ntemp));
void node_type_storage(struct bNodeType *ntype, void node_type_storage(struct bNodeType *ntype,
const char *storagename, const char *storagename,
void (*freestoragefunc)(struct bNode *), void (*freestoragefunc)(struct bNode *),
void (*copystoragefunc)(struct bNode *, struct bNode *)); void (*copystoragefunc)(struct bNode *, struct bNode *));
void node_type_exec(struct bNodeType *ntype, void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **));
void node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out));
void node_type_label(struct bNodeType *ntype, const char *(*labelfunc)(struct bNode *)); void node_type_label(struct bNodeType *ntype, const char *(*labelfunc)(struct bNode *));
void node_type_template(struct bNodeType *ntype, struct bNodeTemplate (*templatefunc)(struct bNode *));
void node_type_update(struct bNodeType *ntype,
void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node),
void (*verifyfunc)(struct bNodeTree *ntree, struct bNode *node, struct ID *id));
void node_type_tree(struct bNodeType *ntype,
void (*inittreefunc)(struct bNodeTree *),
void (*updatetreefunc)(struct bNodeTree *));
void node_type_group_edit(struct bNodeType *ntype,
struct bNodeTree *(*group_edit_get)(struct bNode *node),
struct bNodeTree *(*group_edit_set)(struct bNode *node, int edit),
void (*group_edit_clear)(struct bNode *node));
void node_type_exec(struct bNodeType *ntype, void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **));
void node_type_exec_new(struct bNodeType *ntype,
void *(*initexecfunc)(struct bNode *node),
void (*freeexecfunc)(struct bNode *node, void *nodedata),
void (*newexecfunc)(void *data, int thread, struct bNode *, void *nodedata, struct bNodeStack **, struct bNodeStack **));
void node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out));
void node_type_gpu_ext(struct bNodeType *ntype, int (*gpuextfunc)(struct GPUMaterial *mat, struct bNode *node, void *nodedata, struct GPUNodeStack *in, struct GPUNodeStack *out));
/* ************** COMMON NODES *************** */
#define NODE_GROUP 2 #define NODE_GROUP 2
#define NODE_GROUP_MENU 1000 #define NODE_FORLOOP 3
#define NODE_DYNAMIC_MENU 4000 #define NODE_WHILELOOP 4
#define NODE_FRAME 5
#define NODE_GROUP_MENU 10000
#define NODE_DYNAMIC_MENU 20000
void register_node_type_group(ListBase *lb); /* look up a socket on a group node by the internal group socket */
struct bNodeSocket *node_group_find_input(struct bNode *gnode, struct bNodeSocket *gsock);
struct bNodeSocket *node_group_find_output(struct bNode *gnode, struct bNodeSocket *gsock);
struct bNodeSocket *node_group_add_socket(struct bNodeTree *ngroup, const char *name, int type, int in_out);
struct bNodeSocket *node_group_expose_socket(struct bNodeTree *ngroup, struct bNodeSocket *sock, int in_out);
void node_group_expose_all_sockets(struct bNodeTree *ngroup);
void node_group_remove_socket(struct bNodeTree *ngroup, struct bNodeSocket *gsock, int in_out);
struct bNode *node_group_make_from_selected(struct bNodeTree *ntree);
int node_group_ungroup(struct bNodeTree *ntree, struct bNode *gnode);
/* in node_common.c */
void register_node_type_frame(ListBase *lb);
/* ************** SHADER NODES *************** */ /* ************** SHADER NODES *************** */
@ -286,11 +464,10 @@ struct ShadeResult;
#define NODE_DYNAMIC_REPARSE 6 /* 64 */ #define NODE_DYNAMIC_REPARSE 6 /* 64 */
#define NODE_DYNAMIC_SET 15 /* sign */ #define NODE_DYNAMIC_SET 15 /* sign */
/* the type definitions array */
extern struct ListBase node_all_shaders;
/* API */ /* API */
struct bNodeTreeExec *ntreeShaderBeginExecTree(struct bNodeTree *ntree, int use_tree_data);
void ntreeShaderEndExecTree(struct bNodeTreeExec *exec, int use_tree_data);
void ntreeShaderExecTree(struct bNodeTree *ntree, struct ShadeInput *shi, struct ShadeResult *shr); void ntreeShaderExecTree(struct bNodeTree *ntree, struct ShadeInput *shi, struct ShadeResult *shr);
void ntreeShaderGetTexcoMode(struct bNodeTree *ntree, int osa, short *texco, int *mode); void ntreeShaderGetTexcoMode(struct bNodeTree *ntree, int osa, short *texco, int *mode);
void nodeShaderSynchronizeID(struct bNode *node, int copyto); void nodeShaderSynchronizeID(struct bNode *node, int copyto);
@ -415,11 +592,11 @@ void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat);
#define CMP_SCALE_RENDERPERCENT 3 #define CMP_SCALE_RENDERPERCENT 3
/* the type definitions array */
extern struct ListBase node_all_composit;
/* API */ /* API */
struct CompBuf; struct CompBuf;
struct bNodeTreeExec *ntreeCompositBeginExecTree(struct bNodeTree *ntree, int use_tree_data);
void ntreeCompositEndExecTree(struct bNodeTreeExec *exec, int use_tree_data);
void ntreeCompositExecTree(struct bNodeTree *ntree, struct RenderData *rd, int do_previews);
void ntreeCompositTagRender(struct Scene *sce); void ntreeCompositTagRender(struct Scene *sce);
int ntreeCompositTagAnimated(struct bNodeTree *ntree); int ntreeCompositTagAnimated(struct bNodeTree *ntree);
void ntreeCompositTagGenerators(struct bNodeTree *ntree); void ntreeCompositTagGenerators(struct bNodeTree *ntree);
@ -459,23 +636,22 @@ struct TexResult;
#define TEX_NODE_PROC 500 #define TEX_NODE_PROC 500
#define TEX_NODE_PROC_MAX 600 #define TEX_NODE_PROC_MAX 600
extern struct ListBase node_all_textures;
/* API */ /* API */
int ntreeTexTagAnimated(struct bNodeTree *ntree); int ntreeTexTagAnimated(struct bNodeTree *ntree);
void ntreeTexSetPreviewFlag(int); void ntreeTexSetPreviewFlag(int);
int ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, float *dxt, float *dyt, int osatex, short thread, struct Tex *tex, short which_output, int cfra, int preview, struct ShadeInput *shi, struct MTex *mtex);
void ntreeTexCheckCyclics(struct bNodeTree *ntree); void ntreeTexCheckCyclics(struct bNodeTree *ntree);
char* ntreeTexOutputMenu(struct bNodeTree *ntree); char* ntreeTexOutputMenu(struct bNodeTree *ntree);
struct bNodeTreeExec *ntreeTexBeginExecTree(struct bNodeTree *ntree, int use_tree_data);
void ntreeTexEndExecTree(struct bNodeTreeExec *exec, int use_tree_data);
int ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, float *dxt, float *dyt, int osatex, short thread, struct Tex *tex, short which_output, int cfra, int preview, struct ShadeInput *shi, struct MTex *mtex);
/**/
/*************************************************/
void init_nodesystem(void); void init_nodesystem(void);
void free_nodesystem(void); void free_nodesystem(void);
/**/
void clear_scene_in_nodes(struct Main *bmain, struct Scene *sce); void clear_scene_in_nodes(struct Main *bmain, struct Scene *sce);
#endif #endif

@ -39,7 +39,6 @@
struct PackedFile; struct PackedFile;
struct bSound; struct bSound;
struct bContext;
struct ListBase; struct ListBase;
struct Main; struct Main;
struct Sequence; struct Sequence;
@ -65,12 +64,12 @@ struct bSound* sound_new_file(struct Main *main, const char *filename);
// XXX unused currently // XXX unused currently
#if 0 #if 0
struct bSound* sound_new_buffer(struct bContext *C, struct bSound *source); struct bSound* sound_new_buffer(struct Main *bmain, struct bSound *source);
struct bSound* sound_new_limiter(struct bContext *C, struct bSound *source, float start, float end); struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, float start, float end);
#endif #endif
void sound_delete(struct bContext *C, struct bSound* sound); void sound_delete(struct Main *bmain, struct bSound* sound);
void sound_cache(struct bSound* sound); void sound_cache(struct bSound* sound);
@ -124,7 +123,7 @@ void sound_play_scene(struct Scene *scene);
void sound_stop_scene(struct Scene *scene); void sound_stop_scene(struct Scene *scene);
void sound_seek_scene(struct bContext *C); void sound_seek_scene(struct Main *bmain, struct Scene *scene);
float sound_sync_scene(struct Scene *scene); float sound_sync_scene(struct Scene *scene);

@ -324,17 +324,14 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath
MEM_freeN(bfd); MEM_freeN(bfd);
} }
static int handle_subversion_warning(Main *main) static int handle_subversion_warning(Main *main, ReportList *reports)
{ {
if(main->minversionfile > BLENDER_VERSION || if(main->minversionfile > BLENDER_VERSION ||
(main->minversionfile == BLENDER_VERSION && (main->minversionfile == BLENDER_VERSION &&
main->minsubversionfile > BLENDER_SUBVERSION)) { main->minsubversionfile > BLENDER_SUBVERSION)) {
BKE_reportf(reports, RPT_ERROR, "File written by newer Blender binary: %d.%d , expect loss of data!", main->minversionfile, main->minsubversionfile);
char str[128];
BLI_snprintf(str, sizeof(str), "File written by newer Blender binary: %d.%d , expect loss of data!", main->minversionfile, main->minsubversionfile);
// XXX error(str);
} }
return 1; return 1;
} }
@ -392,7 +389,7 @@ int BKE_read_file(bContext *C, const char *filepath, ReportList *reports)
if (bfd) { if (bfd) {
if(bfd->user) retval= BKE_READ_FILE_OK_USERPREFS; if(bfd->user) retval= BKE_READ_FILE_OK_USERPREFS;
if(0==handle_subversion_warning(bfd->main)) { if(0==handle_subversion_warning(bfd->main, reports)) {
free_main(bfd->main); free_main(bfd->main);
MEM_freeN(bfd); MEM_freeN(bfd);
bfd= NULL; bfd= NULL;

@ -867,7 +867,9 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
{sizeof(MCol)*4, "MCol", 4, "TexturedCol", NULL, NULL, layerInterp_mcol, {sizeof(MCol)*4, "MCol", 4, "TexturedCol", NULL, NULL, layerInterp_mcol,
layerSwap_mcol, layerDefault_mcol}, layerSwap_mcol, layerDefault_mcol},
/* 23: CD_CLOTH_ORCO */ /* 23: CD_CLOTH_ORCO */
{sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL} {sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
/* 24: CD_RECAST */
{sizeof(MRecast), "MRecast", 1,"Recast",NULL,NULL,NULL,NULL}
}; };
static const char *LAYERTYPENAMES[CD_NUMTYPES] = { static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
@ -875,7 +877,7 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
/* 5-9 */ "CDMTFace", "CDMCol", "CDOrigIndex", "CDNormal", "CDFlags", /* 5-9 */ "CDMTFace", "CDMCol", "CDOrigIndex", "CDNormal", "CDFlags",
/* 10-14 */ "CDMFloatProperty", "CDMIntProperty","CDMStringProperty", "CDOrigSpace", "CDOrco", /* 10-14 */ "CDMFloatProperty", "CDMIntProperty","CDMStringProperty", "CDOrigSpace", "CDOrco",
/* 15-19 */ "CDMTexPoly", "CDMLoopUV", "CDMloopCol", "CDTangent", "CDMDisps", /* 15-19 */ "CDMTexPoly", "CDMLoopUV", "CDMloopCol", "CDTangent", "CDMDisps",
/* 20-23 */"CDWeightMCol", "CDIDMCol", "CDTextureMCol", "CDClothOrco" /* 20-24 */"CDWeightMCol", "CDIDMCol", "CDTextureMCol", "CDClothOrco", "CDMRecast"
}; };
const CustomDataMask CD_MASK_BAREMESH = const CustomDataMask CD_MASK_BAREMESH =
@ -883,14 +885,14 @@ const CustomDataMask CD_MASK_BAREMESH =
const CustomDataMask CD_MASK_MESH = const CustomDataMask CD_MASK_MESH =
CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE | CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE |
CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL |
CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS; CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | CD_MASK_RECAST;
const CustomDataMask CD_MASK_EDITMESH = const CustomDataMask CD_MASK_EDITMESH =
CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE |
CD_MASK_MCOL|CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS; CD_MASK_MCOL|CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | CD_MASK_RECAST;
const CustomDataMask CD_MASK_DERIVEDMESH = const CustomDataMask CD_MASK_DERIVEDMESH =
CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE |
CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO | CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO |
CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORCO | CD_MASK_TANGENT | CD_MASK_WEIGHT_MCOL; CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORCO | CD_MASK_TANGENT | CD_MASK_WEIGHT_MCOL | CD_MASK_RECAST;
const CustomDataMask CD_MASK_BMESH = const CustomDataMask CD_MASK_BMESH =
CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR; CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR;
const CustomDataMask CD_MASK_FACECORNERS = const CustomDataMask CD_MASK_FACECORNERS =

@ -926,7 +926,8 @@ void init_render_material(Material *mat, int r_mode, float *amb)
if(mat->nodetree && mat->use_nodes) { if(mat->nodetree && mat->use_nodes) {
init_render_nodetree(mat->nodetree, mat, r_mode, amb); init_render_nodetree(mat->nodetree, mat, r_mode, amb);
ntreeBeginExecTree(mat->nodetree); /* has internal flag to detect it only does it once */ if (!mat->nodetree->execdata)
mat->nodetree->execdata = ntreeShaderBeginExecTree(mat->nodetree, 1);
} }
} }
@ -958,8 +959,10 @@ void init_render_materials(Main *bmain, int r_mode, float *amb)
/* only needed for nodes now */ /* only needed for nodes now */
void end_render_material(Material *mat) void end_render_material(Material *mat)
{ {
if(mat && mat->nodetree && mat->use_nodes) if(mat && mat->nodetree && mat->use_nodes) {
ntreeEndExecTree(mat->nodetree); /* has internal flag to detect it only does it once */ if (mat->nodetree->execdata)
ntreeShaderEndExecTree(mat->nodetree->execdata, 1);
}
} }
void end_render_materials(Main *bmain) void end_render_materials(Main *bmain)

File diff suppressed because it is too large Load Diff

@ -1092,6 +1092,7 @@ Object *add_only_object(int type, const char *name)
ob->state=1; ob->state=1;
/* ob->pad3 == Contact Processing Threshold */ /* ob->pad3 == Contact Processing Threshold */
ob->m_contactProcessingThreshold = 1.; ob->m_contactProcessingThreshold = 1.;
ob->obstacleRad = 1.;
/* NT fluid sim defaults */ /* NT fluid sim defaults */
ob->fluidsimFlag = 0; ob->fluidsimFlag = 0;

@ -396,6 +396,7 @@ void init_actuator(bActuator *act)
bObjectActuator *oa; bObjectActuator *oa;
bRandomActuator *ra; bRandomActuator *ra;
bSoundActuator *sa; bSoundActuator *sa;
bSteeringActuator *sta;
if(act->data) MEM_freeN(act->data); if(act->data) MEM_freeN(act->data);
act->data= NULL; act->data= NULL;
@ -470,6 +471,16 @@ void init_actuator(bActuator *act)
case ACT_ARMATURE: case ACT_ARMATURE:
act->data = MEM_callocN(sizeof( bArmatureActuator ), "armature act"); act->data = MEM_callocN(sizeof( bArmatureActuator ), "armature act");
break; break;
case ACT_STEERING:
act->data = MEM_callocN(sizeof( bSteeringActuator), "steering act");
sta = act->data;
sta->acceleration = 3.f;
sta->turnspeed = 120.f;
sta->dist = 1.f;
sta->velocity= 3.f;
sta->flag = ACT_STEERING_AUTOMATICFACING;
sta->facingaxis = 1;
break;
default: default:
; /* this is very severe... I cannot make any memory for this */ ; /* this is very severe... I cannot make any memory for this */
/* logic brick... */ /* logic brick... */
@ -595,6 +606,11 @@ void set_sca_new_poins_ob(Object *ob)
bPropertyActuator *pa= act->data; bPropertyActuator *pa= act->data;
ID_NEW(pa->ob); ID_NEW(pa->ob);
} }
else if(act->type==ACT_STEERING) {
bSteeringActuator *sta = act->data;
ID_NEW(sta->navmesh);
ID_NEW(sta->target);
}
} }
act= act->next; act= act->next;
} }

@ -521,6 +521,23 @@ Scene *add_scene(const char *name)
sce->gm.flag = GAME_DISPLAY_LISTS; sce->gm.flag = GAME_DISPLAY_LISTS;
sce->gm.matmode = GAME_MAT_MULTITEX; sce->gm.matmode = GAME_MAT_MULTITEX;
sce->gm.obstacleSimulation= OBSTSIMULATION_NONE;
sce->gm.levelHeight = 2.f;
sce->gm.recastData.cellsize = 0.3f;
sce->gm.recastData.cellheight = 0.2f;
sce->gm.recastData.agentmaxslope = M_PI/2;
sce->gm.recastData.agentmaxclimb = 0.9f;
sce->gm.recastData.agentheight = 2.0f;
sce->gm.recastData.agentradius = 0.6f;
sce->gm.recastData.edgemaxlen = 12.0f;
sce->gm.recastData.edgemaxerror = 1.3f;
sce->gm.recastData.regionminsize = 50.f;
sce->gm.recastData.regionmergesize = 20.f;
sce->gm.recastData.vertsperpoly = 6;
sce->gm.recastData.detailsampledist = 6.0f;
sce->gm.recastData.detailsamplemaxerror = 1.0f;
sound_create_scene(sce); sound_create_scene(sce);
return sce; return sce;

@ -3603,6 +3603,7 @@ Sequence *sequencer_add_image_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo
#ifdef WITH_AUDASPACE #ifdef WITH_AUDASPACE
Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load) Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load)
{ {
Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C); /* only for sound */ Scene *scene= CTX_data_scene(C); /* only for sound */
Editing *ed= seq_give_editing(scene, TRUE); Editing *ed= seq_give_editing(scene, TRUE);
bSound *sound; bSound *sound;
@ -3624,7 +3625,7 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo
info = AUD_getInfo(sound->playback_handle); info = AUD_getInfo(sound->playback_handle);
if (info.specs.channels == AUD_CHANNELS_INVALID) { if (info.specs.channels == AUD_CHANNELS_INVALID) {
sound_delete(C, sound); sound_delete(bmain, sound);
//if(op) //if(op)
// BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); // BKE_report(op->reports, RPT_ERROR, "Unsupported audio format");
return NULL; return NULL;

@ -203,7 +203,7 @@ void sound_exit(void)
// XXX unused currently // XXX unused currently
#if 0 #if 0
struct bSound* sound_new_buffer(struct bContext *C, struct bSound *source) struct bSound* sound_new_buffer(struct Main *bmain, struct bSound *source)
{ {
bSound* sound = NULL; bSound* sound = NULL;
@ -211,23 +211,23 @@ struct bSound* sound_new_buffer(struct bContext *C, struct bSound *source)
strcpy(name, "buf_"); strcpy(name, "buf_");
strcpy(name + 4, source->id.name); strcpy(name + 4, source->id.name);
sound = alloc_libblock(&CTX_data_main(C)->sound, ID_SO, name); sound = alloc_libblock(&bmain->sound, ID_SO, name);
sound->child_sound = source; sound->child_sound = source;
sound->type = SOUND_TYPE_BUFFER; sound->type = SOUND_TYPE_BUFFER;
sound_load(CTX_data_main(C), sound); sound_load(bmain, sound);
if(!sound->playback_handle) if(!sound->playback_handle)
{ {
free_libblock(&CTX_data_main(C)->sound, sound); free_libblock(&bmain->sound, sound);
sound = NULL; sound = NULL;
} }
return sound; return sound;
} }
struct bSound* sound_new_limiter(struct bContext *C, struct bSound *source, float start, float end) struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, float start, float end)
{ {
bSound* sound = NULL; bSound* sound = NULL;
@ -235,18 +235,18 @@ struct bSound* sound_new_limiter(struct bContext *C, struct bSound *source, floa
strcpy(name, "lim_"); strcpy(name, "lim_");
strcpy(name + 4, source->id.name); strcpy(name + 4, source->id.name);
sound = alloc_libblock(&CTX_data_main(C)->sound, ID_SO, name); sound = alloc_libblock(&bmain->sound, ID_SO, name);
sound->child_sound = source; sound->child_sound = source;
sound->start = start; sound->start = start;
sound->end = end; sound->end = end;
sound->type = SOUND_TYPE_LIMITER; sound->type = SOUND_TYPE_LIMITER;
sound_load(CTX_data_main(C), sound); sound_load(bmain, sound);
if(!sound->playback_handle) if(!sound->playback_handle)
{ {
free_libblock(&CTX_data_main(C)->sound, sound); free_libblock(&bmain->sound, sound);
sound = NULL; sound = NULL;
} }
@ -254,13 +254,13 @@ struct bSound* sound_new_limiter(struct bContext *C, struct bSound *source, floa
} }
#endif #endif
void sound_delete(struct bContext *C, struct bSound* sound) void sound_delete(struct Main *bmain, struct bSound* sound)
{ {
if(sound) if(sound)
{ {
sound_free(sound); sound_free(sound);
free_libblock(&CTX_data_main(C)->sound, sound); free_libblock(&bmain->sound, sound);
} }
} }
@ -538,10 +538,11 @@ void sound_stop_scene(struct Scene *scene)
} }
} }
void sound_seek_scene(struct bContext *C) void sound_seek_scene(struct Main *bmain, struct Scene *scene)
{ {
struct Scene *scene = CTX_data_scene(C);
AUD_Status status; AUD_Status status;
bScreen *screen;
int animation_playing;
AUD_lock(); AUD_lock();
@ -560,7 +561,12 @@ void sound_seek_scene(struct bContext *C)
AUD_pause(scene->sound_scene_handle); AUD_pause(scene->sound_scene_handle);
} }
if(scene->audio.flag & AUDIO_SCRUB && !CTX_wm_screen(C)->animtimer) animation_playing = 0;
for(screen=bmain->screen.first; screen; screen=screen->id.next)
if(screen->animtimer)
animation_playing = 1;
if(scene->audio.flag & AUDIO_SCRUB && !animation_playing)
{ {
if(scene->audio.flag & AUDIO_SYNC) if(scene->audio.flag & AUDIO_SYNC)
{ {
@ -758,7 +764,7 @@ void sound_move_scene_sound(struct Scene *UNUSED(scene), void* UNUSED(handle), i
static void sound_start_play_scene(struct Scene *UNUSED(scene)) {} static void sound_start_play_scene(struct Scene *UNUSED(scene)) {}
void sound_play_scene(struct Scene *UNUSED(scene)) {} void sound_play_scene(struct Scene *UNUSED(scene)) {}
void sound_stop_scene(struct Scene *UNUSED(scene)) {} void sound_stop_scene(struct Scene *UNUSED(scene)) {}
void sound_seek_scene(struct bContext *UNUSED(C)) {} void sound_seek_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) {}
float sound_sync_scene(struct Scene *UNUSED(scene)) { return 0.0f; } float sound_sync_scene(struct Scene *UNUSED(scene)) { return 0.0f; }
int sound_scene_playing(struct Scene *UNUSED(scene)) { return -1; } int sound_scene_playing(struct Scene *UNUSED(scene)) { return -1; }
int sound_read_sound_buffer(struct bSound* UNUSED(sound), float* UNUSED(buffer), int UNUSED(length), float UNUSED(start), float UNUSED(end)) { return 0; } int sound_read_sound_buffer(struct bSound* UNUSED(sound), float* UNUSED(buffer), int UNUSED(length), float UNUSED(start), float UNUSED(end)) { return 0; }

@ -766,7 +766,9 @@ Tex *copy_texture(Tex *tex)
if(tex->preview) texn->preview = BKE_previewimg_copy(tex->preview); if(tex->preview) texn->preview = BKE_previewimg_copy(tex->preview);
if(tex->nodetree) { if(tex->nodetree) {
ntreeEndExecTree(tex->nodetree); if (tex->nodetree->execdata) {
ntreeTexEndExecTree(tex->nodetree->execdata, 1);
}
texn->nodetree= ntreeCopyTree(tex->nodetree); texn->nodetree= ntreeCopyTree(tex->nodetree);
} }

@ -45,7 +45,12 @@ extern "C" {
#define MALWAYS_INLINE MINLINE #define MALWAYS_INLINE MINLINE
#else #else
#define MINLINE static inline #define MINLINE static inline
#if (defined(__APPLE__) && defined(__ppc__))
/* static inline __attribute__ here breaks osx ppc gcc42 build */
#define MALWAYS_INLINE static __attribute__((always_inline)) #define MALWAYS_INLINE static __attribute__((always_inline))
#else
#define MALWAYS_INLINE static inline __attribute__((always_inline))
#endif
#endif #endif
#else #else
#define MINLINE #define MINLINE

@ -66,6 +66,9 @@ void swap_m4m4(float A[4][4], float B[4][4]);
void add_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]); void add_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
void add_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]); void add_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
void sub_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
void sub_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
void mul_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]); void mul_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
void mul_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]); void mul_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
void mul_m4_m3m4(float R[4][4], float A[3][3], float B[4][4]); void mul_m4_m3m4(float R[4][4], float A[3][3], float B[4][4]);

@ -124,6 +124,7 @@ void interp_v3_v3v3v3(float p[3], const float v1[3], const float v2[3], const fl
void interp_v3_v3v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3], const float w[4]); void interp_v3_v3v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3], const float w[4]);
void interp_v4_v4v4(float r[4], const float a[4], const float b[4], const float t); void interp_v4_v4v4(float r[4], const float a[4], const float b[4], const float t);
void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float w[3]); void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float w[3]);
void interp_v4_v4v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float v4[4], const float w[4]);
void mid_v3_v3v3(float r[3], const float a[3], const float b[3]); void mid_v3_v3v3(float r[3], const float a[3], const float b[3]);

@ -176,6 +176,12 @@
/* useful for debugging */ /* useful for debugging */
#define AT __FILE__ ":" STRINGIFY(__LINE__) #define AT __FILE__ ":" STRINGIFY(__LINE__)
/* so we can use __func__ everywhere */
#if defined(_MSC_VER)
# define __func__ __FUNCTION__
#endif
/* UNUSED macro, for function argument */ /* UNUSED macro, for function argument */
#ifdef __GNUC__ #ifdef __GNUC__
# define UNUSED(x) UNUSED_ ## x __attribute__((__unused__)) # define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))

@ -451,6 +451,24 @@ void add_m4_m4m4(float m1[][4], float m2[][4], float m3[][4])
m1[i][j]= m2[i][j] + m3[i][j]; m1[i][j]= m2[i][j] + m3[i][j];
} }
void sub_m3_m3m3(float m1[][3], float m2[][3], float m3[][3])
{
int i, j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
m1[i][j]= m2[i][j] - m3[i][j];
}
void sub_m4_m4m4(float m1[][4], float m2[][4], float m3[][4])
{
int i, j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
m1[i][j]= m2[i][j] - m3[i][j];
}
int invert_m3(float m[3][3]) int invert_m3(float m[3][3])
{ {
float tmp[3][3]; float tmp[3][3];

@ -96,6 +96,14 @@ void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const fl
p[3] = v1[3]*w[0] + v2[3]*w[1] + v3[3]*w[2]; p[3] = v1[3]*w[0] + v2[3]*w[1] + v3[3]*w[2];
} }
void interp_v4_v4v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float v4[4], const float w[4])
{
p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2] + v4[0]*w[3];
p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2] + v4[1]*w[3];
p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2] + v4[2]*w[3];
p[3] = v1[3]*w[0] + v2[3]*w[1] + v3[3]*w[2] + v4[3]*w[3];
}
void mid_v3_v3v3(float v[3], const float v1[3], const float v2[3]) void mid_v3_v3v3(float v[3], const float v1[3], const float v2[3])
{ {
v[0]= 0.5f*(v1[0] + v2[0]); v[0]= 0.5f*(v1[0] + v2[0]);

@ -263,13 +263,21 @@ static float newPerlinU(float x, float y, float z)
static float orgBlenderNoise(float x, float y, float z) static float orgBlenderNoise(float x, float y, float z)
{ {
register float cn1, cn2, cn3, cn4, cn5, cn6, i, *h; register float cn1, cn2, cn3, cn4, cn5, cn6, i, *h;
float ox, oy, oz, jx, jy, jz; float fx, fy, fz, ox, oy, oz, jx, jy, jz;
float n= 0.5; float n= 0.5;
int ix, iy, iz, b00, b01, b10, b11, b20, b21; int ix, iy, iz, b00, b01, b10, b11, b20, b21;
ox= (x- (ix= (int)floor(x)) ); fx= floor(x);
oy= (y- (iy= (int)floor(y)) ); fy= floor(y);
oz= (z- (iz= (int)floor(z)) ); fz= floor(z);
ox= x- fx;
oy= y- fy;
oz= z- fz;
ix= (int)fx;
iy= (int)fy;
iz= (int)fz;
jx= ox-1; jx= ox-1;
jy= oy-1; jy= oy-1;

@ -129,7 +129,7 @@ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen)
while(len < maxlen) { while(len < maxlen) {
switch(*src) { switch(*src) {
case '\0': case '\0':
break; goto escape_finish;
case '\\': case '\\':
case '"': case '"':
@ -154,6 +154,8 @@ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen)
len++; len++;
} }
escape_finish:
*dst= '\0'; *dst= '\0';
return len; return len;

@ -93,7 +93,8 @@ typedef unsigned long uintptr_t;
#include <inttypes.h> #include <inttypes.h>
#elif defined(FREE_WINDOWS) #elif defined(FREE_WINDOWS)
/* define htoln here, there must be a syntax error in winsock2.h in MinGW */
unsigned long __attribute__((__stdcall__)) htonl(unsigned long);
#include <stdint.h> #include <stdint.h>
#else #else
@ -105,8 +106,14 @@ typedef unsigned long uintptr_t;
#ifdef _WIN32 #ifdef _WIN32
#ifndef FREE_WINDOWS
#ifndef htonl
#define htonl(x) correctByteOrder(x) #define htonl(x) correctByteOrder(x)
#endif
#ifndef ntohl
#define ntohl(x) correctByteOrder(x) #define ntohl(x) correctByteOrder(x)
#endif
#endif
#elif defined (__FreeBSD__) || defined (__OpenBSD__) #elif defined (__FreeBSD__) || defined (__OpenBSD__)
#include <sys/param.h> #include <sys/param.h>
#elif defined (__APPLE__) #elif defined (__APPLE__)

@ -30,6 +30,7 @@ set(INC
../blenlib ../blenlib
../makesdna ../makesdna
../makesrna ../makesrna
../nodes
../render/extern/include ../render/extern/include
../../../intern/guardedalloc ../../../intern/guardedalloc
) )

@ -5,7 +5,7 @@ sources = env.Glob('intern/*.c')
incs = '. #/intern/guardedalloc ../blenlib ../blenkernel' incs = '. #/intern/guardedalloc ../blenlib ../blenkernel'
incs += ' ../makesdna ../editors/include' incs += ' ../makesdna ../editors/include'
incs += ' ../render/extern/include ../makesrna' incs += ' ../render/extern/include ../makesrna ../nodes'
incs += ' ' + env['BF_ZLIB_INC'] incs += ' ' + env['BF_ZLIB_INC']

@ -135,6 +135,8 @@
#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
#include "BKE_sound.h" #include "BKE_sound.h"
#include "NOD_socket.h"
//XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes //XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes
//XXX #include "BIF_filelist.h" // badlevel too, where to move this? - elubie //XXX #include "BIF_filelist.h" // badlevel too, where to move this? - elubie
//XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo //XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo
@ -2053,10 +2055,21 @@ static void lib_link_nodetree(FileData *fd, Main *main)
} }
} }
static void lib_nodetree_init_types_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
{
bNode *node;
ntreeInitTypes(ntree);
/* XXX could be replaced by do_versions for new nodes */
for (node=ntree->nodes.first; node; node=node->next)
node_verify_socket_templates(ntree, node);
}
/* updates group node socket own_index so that /* updates group node socket own_index so that
* external links to/from the group node are preserved. * external links to/from the group node are preserved.
*/ */
static void lib_node_do_versions_group(bNode *gnode) static void lib_node_do_versions_group_indices(bNode *gnode)
{ {
bNodeTree *ngroup= (bNodeTree*)gnode->id; bNodeTree *ngroup= (bNodeTree*)gnode->id;
bNode *intnode; bNode *intnode;
@ -2089,92 +2102,101 @@ static void lib_node_do_versions_group(bNode *gnode)
} }
/* updates external links for all group nodes in a tree */ /* updates external links for all group nodes in a tree */
static void lib_nodetree_do_versions_group(bNodeTree *ntree) static void lib_nodetree_do_versions_group_indices_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
{ {
bNode *node; bNode *node;
for (node=ntree->nodes.first; node; node=node->next) { for (node=ntree->nodes.first; node; node=node->next) {
if (node->type==NODE_GROUP) { if (node->type==NODE_GROUP) {
bNodeTree *ngroup= (bNodeTree*)node->id; bNodeTree *ngroup= (bNodeTree*)node->id;
if (ngroup && (ngroup->flag & NTREE_DO_VERSIONS)) if (ngroup && (ngroup->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE))
lib_node_do_versions_group(node); lib_node_do_versions_group_indices(node);
} }
} }
} }
/* make an update call for the tree */
static void lib_nodetree_do_versions_update_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
{
if (ntree->update)
ntreeUpdateTree(ntree);
}
/* verify types for nodes and groups, all data has to be read */ /* verify types for nodes and groups, all data has to be read */
/* open = 0: appending/linking, open = 1: open new file (need to clean out dynamic /* open = 0: appending/linking, open = 1: open new file (need to clean out dynamic
* typedefs*/ * typedefs*/
static void lib_verify_nodetree(Main *main, int UNUSED(open)) static void lib_verify_nodetree(Main *main, int UNUSED(open))
{ {
Scene *sce;
Material *ma;
Tex *tx;
bNodeTree *ntree; bNodeTree *ntree;
int i;
bNodeTreeType *ntreetype;
/* this crashes blender on undo/redo /* this crashes blender on undo/redo
if(open==1) { if(open==1) {
reinit_nodesystem(); reinit_nodesystem();
}*/ }*/
/* now create the own typeinfo structs an verify nodes */ /* set node->typeinfo pointers */
/* here we still assume no groups in groups */ for (i=0; i < NUM_NTREE_TYPES; ++i) {
for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) { ntreetype= ntreeGetType(i);
ntreeVerifyTypes(ntree); /* internal nodes, no groups! */ if (ntreetype && ntreetype->foreach_nodetree)
ntreetype->foreach_nodetree(main, NULL, lib_nodetree_init_types_cb);
} }
for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
ntreeInitTypes(ntree);
{ {
/*int has_old_groups=0;*/ /*UNUSED*/ int has_old_groups=0;
/* XXX this should actually be part of do_versions, but since we need /* XXX this should actually be part of do_versions, but since we need
* finished library linking, it is not possible there. Instead in do_versions * finished library linking, it is not possible there. Instead in do_versions
* we have set the NTREE_DO_VERSIONS flag, so at this point we can do the * we have set the NTREE_DO_VERSIONS flag, so at this point we can do the
* actual group node updates. * actual group node updates.
*/ */
for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) { for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
if (ntree->flag & NTREE_DO_VERSIONS) { if (ntree->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE) {
/* this adds copies and links from all unlinked internal sockets to group inputs/outputs. */ /* this adds copies and links from all unlinked internal sockets to group inputs/outputs. */
nodeGroupExposeAllSockets(ntree); node_group_expose_all_sockets(ntree);
/*has_old_groups = 1;*/ /*UNUSED*/ has_old_groups = 1;
} }
} }
/* now verify all types in material trees, groups are set OK now */
for(ma= main->mat.first; ma; ma= ma->id.next) { if (has_old_groups) {
if(ma->nodetree) for (i=0; i < NUM_NTREE_TYPES; ++i) {
lib_nodetree_do_versions_group(ma->nodetree); ntreetype= ntreeGetType(i);
} if (ntreetype && ntreetype->foreach_nodetree)
/* and scene trees */ ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_group_indices_cb);
for(sce= main->scene.first; sce; sce= sce->id.next) { }
if(sce->nodetree)
lib_nodetree_do_versions_group(sce->nodetree);
}
/* and texture trees */
for(tx= main->tex.first; tx; tx= tx->id.next) {
if(tx->nodetree)
lib_nodetree_do_versions_group(tx->nodetree);
} }
for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
ntree->flag &= ~NTREE_DO_VERSIONS; ntree->flag &= ~NTREE_DO_VERSIONS_GROUP_EXPOSE;
} }
/* now verify all types in material trees, groups are set OK now */ /* verify all group user nodes */
for(ma= main->mat.first; ma; ma= ma->id.next) { for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
if(ma->nodetree) ntreeVerifyNodes(main, &ntree->id);
ntreeVerifyTypes(ma->nodetree);
} }
/* and scene trees */
for(sce= main->scene.first; sce; sce= sce->id.next) { /* make update calls where necessary */
if(sce->nodetree) {
ntreeVerifyTypes(sce->nodetree); for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
} if (ntree->update)
/* and texture trees */ ntreeUpdateTree(ntree);
for(tx= main->tex.first; tx; tx= tx->id.next) { for (i=0; i < NUM_NTREE_TYPES; ++i) {
if(tx->nodetree) ntreetype= ntreeGetType(i);
ntreeVerifyTypes(tx->nodetree); if (ntreetype && ntreetype->foreach_nodetree)
ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_update_cb);
}
} }
} }
static void direct_link_node_socket(FileData *fd, bNodeSocket *sock)
{
sock->link= newdataadr(fd, sock->link);
sock->storage= newdataadr(fd, sock->storage);
sock->default_value= newdataadr(fd, sock->default_value);
sock->cache= NULL;
}
/* ntree itself has been read! */ /* ntree itself has been read! */
static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
@ -2186,6 +2208,7 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
ntree->init= 0; /* to set callbacks and force setting types */ ntree->init= 0; /* to set callbacks and force setting types */
ntree->progress= NULL; ntree->progress= NULL;
ntree->execdata= NULL;
ntree->adt= newdataadr(fd, ntree->adt); ntree->adt= newdataadr(fd, ntree->adt);
direct_link_animdata(fd, ntree->adt); direct_link_animdata(fd, ntree->adt);
@ -2195,12 +2218,15 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
if(node->type == NODE_DYNAMIC) { if(node->type == NODE_DYNAMIC) {
node->custom1= 0; node->custom1= 0;
node->custom1= BSET(node->custom1, NODE_DYNAMIC_LOADED); node->custom1= BSET(node->custom1, NODE_DYNAMIC_LOADED);
node->typeinfo= NULL;
} }
node->typeinfo= NULL;
link_list(fd, &node->inputs);
link_list(fd, &node->outputs);
node->storage= newdataadr(fd, node->storage); node->storage= newdataadr(fd, node->storage);
if(node->storage) { if(node->storage) {
/* could be handlerized at some point */ /* could be handlerized at some point */
if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB)) if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
direct_link_curvemapping(fd, node->storage); direct_link_curvemapping(fd, node->storage);
@ -2217,8 +2243,6 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
((ImageUser *)node->storage)->ok= 1; ((ImageUser *)node->storage)->ok= 1;
} }
} }
link_list(fd, &node->inputs);
link_list(fd, &node->outputs);
} }
link_list(fd, &ntree->links); link_list(fd, &ntree->links);
@ -2228,15 +2252,19 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
/* and we connect the rest */ /* and we connect the rest */
for(node= ntree->nodes.first; node; node= node->next) { for(node= ntree->nodes.first; node; node= node->next) {
node->parent = newdataadr(fd, node->parent);
node->preview= newimaadr(fd, node->preview); node->preview= newimaadr(fd, node->preview);
node->lasty= 0; node->lasty= 0;
for(sock= node->inputs.first; sock; sock= sock->next) for(sock= node->inputs.first; sock; sock= sock->next)
sock->link= newdataadr(fd, sock->link); direct_link_node_socket(fd, sock);
for(sock= node->outputs.first; sock; sock= sock->next) for(sock= node->outputs.first; sock; sock= sock->next)
sock->ns.data= NULL; direct_link_node_socket(fd, sock);
} }
for(sock= ntree->inputs.first; sock; sock= sock->next)
direct_link_node_socket(fd, sock);
for(sock= ntree->outputs.first; sock; sock= sock->next) for(sock= ntree->outputs.first; sock; sock= sock->next)
sock->link= newdataadr(fd, sock->link); direct_link_node_socket(fd, sock);
for(link= ntree->links.first; link; link= link->next) { for(link= ntree->links.first; link; link= link->next) {
link->fromnode= newdataadr(fd, link->fromnode); link->fromnode= newdataadr(fd, link->fromnode);
@ -3869,6 +3897,11 @@ static void lib_link_object(FileData *fd, Main *main)
arma->target= newlibadr(fd, ob->id.lib, arma->target); arma->target= newlibadr(fd, ob->id.lib, arma->target);
arma->subtarget= newlibadr(fd, ob->id.lib, arma->subtarget); arma->subtarget= newlibadr(fd, ob->id.lib, arma->subtarget);
} }
else if(act->type==ACT_STEERING) {
bSteeringActuator *steeringa = act->data;
steeringa->target = newlibadr(fd, ob->id.lib, steeringa->target);
steeringa->navmesh = newlibadr(fd, ob->id.lib, steeringa->navmesh);
}
act= act->next; act= act->next;
} }
@ -4159,6 +4192,13 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
if(tmd->curfalloff) if(tmd->curfalloff)
direct_link_curvemapping(fd, tmd->curfalloff); direct_link_curvemapping(fd, tmd->curfalloff);
} }
else if (md->type==eModifierType_WeightVGEdit) {
WeightVGEditModifierData *wmd = (WeightVGEditModifierData*) md;
wmd->cmap_curve = newdataadr(fd, wmd->cmap_curve);
if(wmd->cmap_curve)
direct_link_curvemapping(fd, wmd->cmap_curve);
}
} }
} }
@ -4971,15 +5011,22 @@ static void lib_link_screen(FileData *fd, Main *main)
SpaceNode *snode= (SpaceNode *)sl; SpaceNode *snode= (SpaceNode *)sl;
snode->id= newlibadr(fd, sc->id.lib, snode->id); snode->id= newlibadr(fd, sc->id.lib, snode->id);
snode->edittree= NULL;
/* internal data, a bit patchy */ if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) {
if(snode->id) { /* internal data, a bit patchy */
if(GS(snode->id->name)==ID_MA) snode->nodetree= NULL;
snode->nodetree= ((Material *)snode->id)->nodetree; if(snode->id) {
else if(GS(snode->id->name)==ID_SCE) if(GS(snode->id->name)==ID_MA)
snode->nodetree= ((Scene *)snode->id)->nodetree; snode->nodetree= ((Material *)snode->id)->nodetree;
else if(GS(snode->id->name)==ID_TE) else if(GS(snode->id->name)==ID_SCE)
snode->nodetree= ((Tex *)snode->id)->nodetree; snode->nodetree= ((Scene *)snode->id)->nodetree;
else if(GS(snode->id->name)==ID_TE)
snode->nodetree= ((Tex *)snode->id)->nodetree;
}
}
else {
snode->nodetree= newlibadr_us(fd, sc->id.lib, snode->nodetree);
} }
snode->linkdrag.first = snode->linkdrag.last = NULL; snode->linkdrag.first = snode->linkdrag.last = NULL;
@ -5199,15 +5246,19 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
snode->id= restore_pointer_by_name(newmain, snode->id, 1); snode->id= restore_pointer_by_name(newmain, snode->id, 1);
snode->edittree= NULL; snode->edittree= NULL;
if(snode->id==NULL) if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) {
snode->nodetree= NULL; snode->nodetree= NULL;
if(snode->id) {
if(GS(snode->id->name)==ID_MA)
snode->nodetree= ((Material *)snode->id)->nodetree;
else if(GS(snode->id->name)==ID_SCE)
snode->nodetree= ((Scene *)snode->id)->nodetree;
else if(GS(snode->id->name)==ID_TE)
snode->nodetree= ((Tex *)snode->id)->nodetree;
}
}
else { else {
if(GS(snode->id->name)==ID_MA) snode->nodetree= restore_pointer_by_name(newmain, &snode->nodetree->id, 1);
snode->nodetree= ((Material *)snode->id)->nodetree;
else if(GS(snode->id->name)==ID_SCE)
snode->nodetree= ((Scene *)snode->id)->nodetree;
else if(GS(snode->id->name)==ID_TE)
snode->nodetree= ((Tex *)snode->id)->nodetree;
} }
} }
} }
@ -5436,7 +5487,6 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
snode->gpd= newdataadr(fd, snode->gpd); snode->gpd= newdataadr(fd, snode->gpd);
direct_link_gpencil(fd, snode->gpd); direct_link_gpencil(fd, snode->gpd);
} }
snode->nodetree= snode->edittree= NULL;
} }
else if(sl->spacetype==SPACE_TIME) { else if(sl->spacetype==SPACE_TIME) {
SpaceTime *stime= (SpaceTime *)sl; SpaceTime *stime= (SpaceTime *)sl;
@ -7120,6 +7170,62 @@ static void do_version_bone_roll_256(Bone *bone)
do_version_bone_roll_256(child); do_version_bone_roll_256(child);
} }
static void do_versions_socket_default_value(bNodeSocket *sock)
{
bNodeSocketValueFloat *valfloat;
bNodeSocketValueVector *valvector;
bNodeSocketValueRGBA *valrgba;
if (sock->default_value)
return;
switch (sock->type) {
case SOCK_FLOAT:
valfloat = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueFloat), "default socket value");
valfloat->value = sock->ns.vec[0];
valfloat->min = sock->ns.min;
valfloat->max = sock->ns.max;
valfloat->subtype = PROP_NONE;
break;
case SOCK_VECTOR:
valvector = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueVector), "default socket value");
copy_v3_v3(valvector->value, sock->ns.vec);
valvector->min = sock->ns.min;
valvector->max = sock->ns.max;
valvector->subtype = PROP_NONE;
break;
case SOCK_RGBA:
valrgba = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueRGBA), "default socket value");
copy_v4_v4(valrgba->value, sock->ns.vec);
break;
}
}
static void do_versions_nodetree_default_value(bNodeTree *ntree)
{
bNode *node;
bNodeSocket *sock;
for (node=ntree->nodes.first; node; node=node->next) {
for (sock=node->inputs.first; sock; sock=sock->next)
do_versions_socket_default_value(sock);
for (sock=node->outputs.first; sock; sock=sock->next)
do_versions_socket_default_value(sock);
}
for (sock=ntree->inputs.first; sock; sock=sock->next)
do_versions_socket_default_value(sock);
for (sock=ntree->outputs.first; sock; sock=sock->next)
do_versions_socket_default_value(sock);
}
static void do_versions_nodetree_dynamic_sockets(bNodeTree *ntree)
{
bNodeSocket *sock;
for (sock=ntree->inputs.first; sock; sock=sock->next)
sock->flag |= SOCK_DYNAMIC;
for (sock=ntree->outputs.first; sock; sock=sock->next)
sock->flag |= SOCK_DYNAMIC;
}
static void do_versions(FileData *fd, Library *lib, Main *main) static void do_versions(FileData *fd, Library *lib, Main *main)
{ {
/* WATCH IT!!!: pointers from libdata have not been converted */ /* WATCH IT!!!: pointers from libdata have not been converted */
@ -11703,6 +11809,23 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
} }
} }
// init facing axis property of steering actuators
{
Object *ob;
for(ob = main->object.first; ob; ob = ob->id.next) {
bActuator *act;
for(act= ob->actuators.first; act; act= act->next) {
if(act->type==ACT_STEERING) {
bSteeringActuator* stact = act->data;
if (stact->facingaxis==0)
{
stact->facingaxis=1;
}
}
}
}
}
if (main->versionfile < 256) { if (main->versionfile < 256) {
bScreen *sc; bScreen *sc;
ScrArea *sa; ScrArea *sa;
@ -11771,7 +11894,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
* is done in lib_verify_nodetree, because at this point the internal * is done in lib_verify_nodetree, because at this point the internal
* nodes may not be up-to-date! (missing lib-link) * nodes may not be up-to-date! (missing lib-link)
*/ */
ntree->flag |= NTREE_DO_VERSIONS; ntree->flag |= NTREE_DO_VERSIONS_GROUP_EXPOSE;
} }
} }
@ -11896,10 +12019,10 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
if(tex->pd) { if(tex->pd) {
if (tex->pd->falloff_speed_scale == 0.0f) if (tex->pd->falloff_speed_scale == 0.0f)
tex->pd->falloff_speed_scale = 100.0f; tex->pd->falloff_speed_scale = 100.0f;
if (!tex->pd->falloff_curve) { if (!tex->pd->falloff_curve) {
tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1); tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1);
tex->pd->falloff_curve->preset = CURVE_PRESET_LINE; tex->pd->falloff_curve->preset = CURVE_PRESET_LINE;
tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE; tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE); curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
@ -12050,12 +12173,99 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
} }
} }
if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 2)){
{
/* Convert default socket values from bNodeStack */
Scene *sce;
Material *mat;
Tex *tex;
bNodeTree *ntree;
for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
do_versions_nodetree_default_value(ntree);
ntree->update |= NTREE_UPDATE;
}
for (sce=main->scene.first; sce; sce=sce->id.next)
if (sce->nodetree) {
do_versions_nodetree_default_value(sce->nodetree);
sce->nodetree->update |= NTREE_UPDATE;
}
for (mat=main->mat.first; mat; mat=mat->id.next)
if (mat->nodetree) {
do_versions_nodetree_default_value(mat->nodetree);
mat->nodetree->update |= NTREE_UPDATE;
}
for (tex=main->tex.first; tex; tex=tex->id.next)
if (tex->nodetree) {
do_versions_nodetree_default_value(tex->nodetree);
tex->nodetree->update |= NTREE_UPDATE;
}
}
/* add SOCK_DYNAMIC flag to existing group sockets */
{
bNodeTree *ntree;
/* only need to do this for trees in main, local trees are not used as groups */
for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
do_versions_nodetree_dynamic_sockets(ntree);
ntree->update |= NTREE_UPDATE;
}
}
{
/* Initialize group tree nodetypes.
* These are used to distinguish tree types and
* associate them with specific node types for polling.
*/
bNodeTree *ntree;
/* all node trees in main->nodetree are considered groups */
for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
ntree->nodetype = NODE_GROUP;
}
}
/* put compatibility code here until next subversion bump */ /* put compatibility code here until next subversion bump */
{ {
} }
//set defaults for obstacle avoidance, recast data
{
Scene *sce;
for(sce = main->scene.first; sce; sce = sce->id.next)
{
if (sce->gm.levelHeight == 0.f)
sce->gm.levelHeight = 2.f;
if(sce->gm.recastData.cellsize == 0.0f)
sce->gm.recastData.cellsize = 0.3f;
if(sce->gm.recastData.cellheight == 0.0f)
sce->gm.recastData.cellheight = 0.2f;
if(sce->gm.recastData.agentmaxslope == 0.0f)
sce->gm.recastData.agentmaxslope = M_PI/4;
if(sce->gm.recastData.agentmaxclimb == 0.0f)
sce->gm.recastData.agentmaxclimb = 0.9f;
if(sce->gm.recastData.agentheight == 0.0f)
sce->gm.recastData.agentheight = 2.0f;
if(sce->gm.recastData.agentradius == 0.0f)
sce->gm.recastData.agentradius = 0.6f;
if(sce->gm.recastData.edgemaxlen == 0.0f)
sce->gm.recastData.edgemaxlen = 12.0f;
if(sce->gm.recastData.edgemaxerror == 0.0f)
sce->gm.recastData.edgemaxerror = 1.3f;
if(sce->gm.recastData.regionminsize == 0.0f)
sce->gm.recastData.regionminsize = 50.f;
if(sce->gm.recastData.regionmergesize == 0.0f)
sce->gm.recastData.regionmergesize = 20.f;
if(sce->gm.recastData.vertsperpoly<3)
sce->gm.recastData.vertsperpoly = 6;
if(sce->gm.recastData.detailsampledist == 0.0f)
sce->gm.recastData.detailsampledist = 6.0f;
if(sce->gm.recastData.detailsamplemaxerror == 0.0f)
sce->gm.recastData.detailsamplemaxerror = 1.0f;
}
}
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */ /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
/* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */ /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
@ -12961,6 +13171,11 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob)
bArmatureActuator *arma= act->data; bArmatureActuator *arma= act->data;
expand_doit(fd, mainvar, arma->target); expand_doit(fd, mainvar, arma->target);
} }
else if(act->type==ACT_STEERING) {
bSteeringActuator *sta= act->data;
expand_doit(fd, mainvar, sta->target);
expand_doit(fd, mainvar, sta->navmesh);
}
act= act->next; act= act->next;
} }

@ -136,6 +136,7 @@ Any case: direct data is ALWAYS after the lib block
#include "BLI_blenlib.h" #include "BLI_blenlib.h"
#include "BLI_linklist.h" #include "BLI_linklist.h"
#include "BLI_bpath.h" #include "BLI_bpath.h"
#include "BLI_math.h"
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
#include "BKE_action.h" #include "BKE_action.h"
@ -643,6 +644,46 @@ static void write_curvemapping(WriteData *wd, CurveMapping *cumap)
writestruct(wd, DATA, "CurveMapPoint", cumap->cm[a].totpoint, cumap->cm[a].curve); writestruct(wd, DATA, "CurveMapPoint", cumap->cm[a].totpoint, cumap->cm[a].curve);
} }
static void write_node_socket(WriteData *wd, bNodeSocket *sock)
{
bNodeSocketType *stype= ntreeGetSocketType(sock->type);
/* forward compatibility code, so older blenders still open */
sock->stack_type = 1;
if(sock->default_value) {
bNodeSocketValueFloat *valfloat;
bNodeSocketValueVector *valvector;
bNodeSocketValueRGBA *valrgba;
switch (sock->type) {
case SOCK_FLOAT:
valfloat = sock->default_value;
sock->ns.vec[0] = valfloat->value;
sock->ns.min = valfloat->min;
sock->ns.max = valfloat->max;
break;
case SOCK_VECTOR:
valvector = sock->default_value;
copy_v3_v3(sock->ns.vec, valvector->value);
sock->ns.min = valvector->min;
sock->ns.max = valvector->max;
break;
case SOCK_RGBA:
valrgba = sock->default_value;
copy_v4_v4(sock->ns.vec, valrgba->value);
sock->ns.min = 0.0f;
sock->ns.max = 1.0f;
break;
}
}
/* actual socket writing */
writestruct(wd, DATA, "bNodeSocket", 1, sock);
if (sock->default_value)
writestruct(wd, DATA, stype->value_structname, 1, sock->default_value);
}
/* this is only direct data, tree itself should have been written */ /* this is only direct data, tree itself should have been written */
static void write_nodetree(WriteData *wd, bNodeTree *ntree) static void write_nodetree(WriteData *wd, bNodeTree *ntree)
{ {
@ -658,6 +699,12 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree)
writestruct(wd, DATA, "bNode", 1, node); writestruct(wd, DATA, "bNode", 1, node);
for(node= ntree->nodes.first; node; node= node->next) { for(node= ntree->nodes.first; node; node= node->next) {
for(sock= node->inputs.first; sock; sock= sock->next)
write_node_socket(wd, sock);
for(sock= node->outputs.first; sock; sock= sock->next)
write_node_socket(wd, sock);
if(node->storage && node->type!=NODE_DYNAMIC) { if(node->storage && node->type!=NODE_DYNAMIC) {
/* could be handlerized at some point, now only 1 exception still */ /* could be handlerized at some point, now only 1 exception still */
if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB)) if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
@ -666,13 +713,9 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree)
write_curvemapping(wd, node->storage); write_curvemapping(wd, node->storage);
else if(ntree->type==NTREE_TEXTURE && (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) ) else if(ntree->type==NTREE_TEXTURE && (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) )
write_curvemapping(wd, node->storage); write_curvemapping(wd, node->storage);
else else
writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage); writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage);
} }
for(sock= node->inputs.first; sock; sock= sock->next)
writestruct(wd, DATA, "bNodeSocket", 1, sock);
for(sock= node->outputs.first; sock; sock= sock->next)
writestruct(wd, DATA, "bNodeSocket", 1, sock);
} }
for(link= ntree->links.first; link; link= link->next) for(link= ntree->links.first; link; link= link->next)
@ -680,9 +723,9 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree)
/* external sockets */ /* external sockets */
for(sock= ntree->inputs.first; sock; sock= sock->next) for(sock= ntree->inputs.first; sock; sock= sock->next)
writestruct(wd, DATA, "bNodeSocket", 1, sock); write_node_socket(wd, sock);
for(sock= ntree->outputs.first; sock; sock= sock->next) for(sock= ntree->outputs.first; sock; sock= sock->next)
writestruct(wd, DATA, "bNodeSocket", 1, sock); write_node_socket(wd, sock);
} }
static void current_screen_compat(Main *mainvar, bScreen **screen) static void current_screen_compat(Main *mainvar, bScreen **screen)
@ -934,7 +977,7 @@ static void write_particlesystems(WriteData *wd, ListBase *particles)
writestruct(wd, DATA, "ClothSimSettings", 1, psys->clmd->sim_parms); writestruct(wd, DATA, "ClothSimSettings", 1, psys->clmd->sim_parms);
writestruct(wd, DATA, "ClothCollSettings", 1, psys->clmd->coll_parms); writestruct(wd, DATA, "ClothCollSettings", 1, psys->clmd->coll_parms);
} }
write_pointcaches(wd, &psys->ptcaches); write_pointcaches(wd, &psys->ptcaches);
} }
} }
@ -1104,6 +1147,9 @@ static void write_actuators(WriteData *wd, ListBase *lb)
case ACT_ARMATURE: case ACT_ARMATURE:
writestruct(wd, DATA, "bArmatureActuator", 1, act->data); writestruct(wd, DATA, "bArmatureActuator", 1, act->data);
break; break;
case ACT_STEERING:
writestruct(wd, DATA, "bSteeringActuator", 1, act->data);
break;
default: default:
; /* error: don't know how to write this file */ ; /* error: don't know how to write this file */
} }
@ -1310,6 +1356,12 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
write_curvemapping(wd, tmd->curfalloff); write_curvemapping(wd, tmd->curfalloff);
} }
} }
else if (md->type==eModifierType_WeightVGEdit) {
WeightVGEditModifierData *wmd = (WeightVGEditModifierData*) md;
if (wmd->cmap_curve)
write_curvemapping(wd, wmd->cmap_curve);
}
} }
} }

File diff suppressed because it is too large Load Diff

@ -89,17 +89,11 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
{ {
COLLADAFW::FloatOrDoubleArray& input = curve->getInputValues(); COLLADAFW::FloatOrDoubleArray& input = curve->getInputValues();
COLLADAFW::FloatOrDoubleArray& output = curve->getOutputValues(); COLLADAFW::FloatOrDoubleArray& output = curve->getOutputValues();
if( curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER ||
curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_STEP ) {
COLLADAFW::FloatOrDoubleArray& intan = curve->getInTangentValues();
COLLADAFW::FloatOrDoubleArray& outtan = curve->getOutTangentValues();
}
float fps = (float)FPS; float fps = (float)FPS;
size_t dim = curve->getOutDimension(); size_t dim = curve->getOutDimension();
unsigned int i; unsigned int i;
std::vector<FCurve*>& fcurves = curve_map[curve->getUniqueId()]; std::vector<FCurve*>& fcurves = curve_map[curve->getUniqueId()];
switch (dim) { switch (dim) {
@ -110,18 +104,18 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
{ {
for (i = 0; i < dim; i++ ) { for (i = 0; i < dim; i++ ) {
FCurve *fcu = (FCurve*)MEM_callocN(sizeof(FCurve), "FCurve"); FCurve *fcu = (FCurve*)MEM_callocN(sizeof(FCurve), "FCurve");
fcu->flag = (FCURVE_VISIBLE|FCURVE_AUTO_HANDLES|FCURVE_SELECTED); fcu->flag = (FCURVE_VISIBLE|FCURVE_AUTO_HANDLES|FCURVE_SELECTED);
// fcu->rna_path = BLI_strdupn(path, strlen(path)); // fcu->rna_path = BLI_strdupn(path, strlen(path));
fcu->array_index = 0; fcu->array_index = 0;
fcu->totvert = curve->getKeyCount(); fcu->totvert = curve->getKeyCount();
// create beztriple for each key // create beztriple for each key
for (unsigned int j = 0; j < curve->getKeyCount(); j++) { for (unsigned int j = 0; j < curve->getKeyCount(); j++) {
BezTriple bez; BezTriple bez;
memset(&bez, 0, sizeof(BezTriple)); memset(&bez, 0, sizeof(BezTriple));
// input, output // input, output
bez.vec[1][0] = bc_get_float_value(input, j) * fps; bez.vec[1][0] = bc_get_float_value(input, j) * fps;
bez.vec[1][1] = bc_get_float_value(output, j * dim + i); bez.vec[1][1] = bc_get_float_value(output, j * dim + i);
@ -131,20 +125,20 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_STEP) curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_STEP)
{ {
COLLADAFW::FloatOrDoubleArray& intan = curve->getInTangentValues(); COLLADAFW::FloatOrDoubleArray& intan = curve->getInTangentValues();
COLLADAFW::FloatOrDoubleArray& outtan = curve->getOutTangentValues(); COLLADAFW::FloatOrDoubleArray& outtan = curve->getOutTangentValues();
// intangent // intangent
bez.vec[0][0] = bc_get_float_value(intan, (j * 2 * dim ) + (2 * i)) * fps; bez.vec[0][0] = bc_get_float_value(intan, (j * 2 * dim ) + (2 * i)) * fps;
bez.vec[0][1] = bc_get_float_value(intan, (j * 2 * dim )+ (2 * i) + 1); bez.vec[0][1] = bc_get_float_value(intan, (j * 2 * dim )+ (2 * i) + 1);
// outtangent // outtangent
bez.vec[2][0] = bc_get_float_value(outtan, (j * 2 * dim ) + (2 * i)) * fps; bez.vec[2][0] = bc_get_float_value(outtan, (j * 2 * dim ) + (2 * i)) * fps;
bez.vec[2][1] = bc_get_float_value(outtan, (j * 2 * dim )+ (2 * i) + 1); bez.vec[2][1] = bc_get_float_value(outtan, (j * 2 * dim )+ (2 * i) + 1);
if(curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER) if(curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER)
bez.ipo = BEZT_IPO_BEZ; bez.ipo = BEZT_IPO_BEZ;
else else
bez.ipo = BEZT_IPO_CONST; bez.ipo = BEZT_IPO_CONST;
//bez.h1 = bez.h2 = HD_AUTO; //bez.h1 = bez.h2 = HD_AUTO;
} }
else else
{ {
@ -153,7 +147,7 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
} }
// bez.ipo = U.ipo_new; /* use default interpolation mode here... */ // bez.ipo = U.ipo_new; /* use default interpolation mode here... */
bez.f1 = bez.f2 = bez.f3 = SELECT; bez.f1 = bez.f2 = bez.f3 = SELECT;
insert_bezt_fcurve(fcu, &bez, 0); insert_bezt_fcurve(fcu, &bez, 0);
} }
@ -306,9 +300,9 @@ bool AnimationImporter::write_animation(const COLLADAFW::Animation* anim)
bool AnimationImporter::write_animation_list(const COLLADAFW::AnimationList* animlist) bool AnimationImporter::write_animation_list(const COLLADAFW::AnimationList* animlist)
{ {
const COLLADAFW::UniqueId& animlist_id = animlist->getUniqueId(); const COLLADAFW::UniqueId& animlist_id = animlist->getUniqueId();
animlist_map[animlist_id] = animlist; animlist_map[animlist_id] = animlist;
#if 0 #if 0
// should not happen // should not happen
@ -317,10 +311,10 @@ bool AnimationImporter::write_animation_list(const COLLADAFW::AnimationList* ani
} }
// for bones rna_path is like: pose.bones["bone-name"].rotation // for bones rna_path is like: pose.bones["bone-name"].rotation
#endif #endif
return true; return true;
} }
@ -433,7 +427,7 @@ virtual void AnimationImporter::change_eul_to_quat(Object *ob, bAction *act)
//sets the rna_path and array index to curve //sets the rna_path and array index to curve
void AnimationImporter::modify_fcurve(std::vector<FCurve*>* curves , char* rna_path , int array_index ) void AnimationImporter::modify_fcurve(std::vector<FCurve*>* curves , char* rna_path , int array_index )
{ {
std::vector<FCurve*>::iterator it; std::vector<FCurve*>::iterator it;
int i; int i;
for (it = curves->begin(), i = 0; it != curves->end(); it++, i++) { for (it = curves->begin(), i = 0; it != curves->end(); it++, i++) {
@ -450,18 +444,18 @@ void AnimationImporter::modify_fcurve(std::vector<FCurve*>* curves , char* rna_p
void AnimationImporter::find_frames( std::vector<float>* frames , std::vector<FCurve*>* curves) void AnimationImporter::find_frames( std::vector<float>* frames , std::vector<FCurve*>* curves)
{ {
std::vector<FCurve*>::iterator iter; std::vector<FCurve*>::iterator iter;
for (iter = curves->begin(); iter != curves->end(); iter++) { for (iter = curves->begin(); iter != curves->end(); iter++) {
FCurve *fcu = *iter; FCurve *fcu = *iter;
for (unsigned int k = 0; k < fcu->totvert; k++) { for (unsigned int k = 0; k < fcu->totvert; k++) {
//get frame value from bezTriple //get frame value from bezTriple
float fra = fcu->bezt[k].vec[1][0]; float fra = fcu->bezt[k].vec[1][0];
//if frame already not added add frame to frames //if frame already not added add frame to frames
if (std::find(frames->begin(), frames->end(), fra) == frames->end()) if (std::find(frames->begin(), frames->end(), fra) == frames->end())
frames->push_back(fra); frames->push_back(fra);
}
} }
}
} }
//creates the rna_paths and array indices of fcurves from animations using transformation and bound animation class of each animation. //creates the rna_paths and array indices of fcurves from animations using transformation and bound animation class of each animation.
@ -472,18 +466,18 @@ void AnimationImporter:: Assign_transform_animations(COLLADAFW::Transformation *
COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType(); COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType();
bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX; bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE; bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
//to check if the no of curves are valid //to check if the no of curves are valid
bool xyz = ((tm_type == COLLADAFW::Transformation::TRANSLATE ||tm_type == COLLADAFW::Transformation::SCALE) && binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ); bool xyz = ((tm_type == COLLADAFW::Transformation::TRANSLATE ||tm_type == COLLADAFW::Transformation::SCALE) && binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ);
if (!((!xyz && curves->size() == 1) || (xyz && curves->size() == 3) || is_matrix)) { if (!((!xyz && curves->size() == 1) || (xyz && curves->size() == 3) || is_matrix)) {
fprintf(stderr, "expected %d curves, got %d\n", xyz ? 3 : 1, (int)curves->size()); fprintf(stderr, "expected %d curves, got %d\n", xyz ? 3 : 1, (int)curves->size());
return; return;
} }
char rna_path[100]; char rna_path[100];
switch (tm_type) { switch (tm_type) {
case COLLADAFW::Transformation::TRANSLATE: case COLLADAFW::Transformation::TRANSLATE:
case COLLADAFW::Transformation::SCALE: case COLLADAFW::Transformation::SCALE:
@ -495,96 +489,96 @@ void AnimationImporter:: Assign_transform_animations(COLLADAFW::Transformation *
BLI_strncpy(rna_path, loc ? "location" : "scale", sizeof(rna_path)); BLI_strncpy(rna_path, loc ? "location" : "scale", sizeof(rna_path));
switch (binding->animationClass) { switch (binding->animationClass) {
case COLLADAFW::AnimationList::POSITION_X: case COLLADAFW::AnimationList::POSITION_X:
modify_fcurve(curves, rna_path, 0 ); modify_fcurve(curves, rna_path, 0 );
break; break;
case COLLADAFW::AnimationList::POSITION_Y: case COLLADAFW::AnimationList::POSITION_Y:
modify_fcurve(curves, rna_path, 1 ); modify_fcurve(curves, rna_path, 1 );
break; break;
case COLLADAFW::AnimationList::POSITION_Z: case COLLADAFW::AnimationList::POSITION_Z:
modify_fcurve(curves, rna_path, 2 ); modify_fcurve(curves, rna_path, 2 );
break; break;
case COLLADAFW::AnimationList::POSITION_XYZ: case COLLADAFW::AnimationList::POSITION_XYZ:
modify_fcurve(curves, rna_path, -1 ); modify_fcurve(curves, rna_path, -1 );
break; break;
default: default:
fprintf(stderr, "AnimationClass %d is not supported for %s.\n", fprintf(stderr, "AnimationClass %d is not supported for %s.\n",
binding->animationClass, loc ? "TRANSLATE" : "SCALE"); binding->animationClass, loc ? "TRANSLATE" : "SCALE");
} }
break; break;
} }
case COLLADAFW::Transformation::ROTATE: case COLLADAFW::Transformation::ROTATE:
{ {
if (is_joint) if (is_joint)
BLI_snprintf(rna_path, sizeof(rna_path), "%s.rotation_euler", joint_path); BLI_snprintf(rna_path, sizeof(rna_path), "%s.rotation_euler", joint_path);
else else
BLI_strncpy(rna_path, "rotation_euler", sizeof(rna_path)); BLI_strncpy(rna_path, "rotation_euler", sizeof(rna_path));
std::vector<FCurve*>::iterator iter; std::vector<FCurve*>::iterator iter;
for (iter = curves->begin(); iter != curves->end(); iter++) { for (iter = curves->begin(); iter != curves->end(); iter++) {
FCurve* fcu = *iter; FCurve* fcu = *iter;
//if transform is rotation the fcurves values must be turned in to radian. //if transform is rotation the fcurves values must be turned in to radian.
if (is_rotation) if (is_rotation)
fcurve_deg_to_rad(fcu); fcurve_deg_to_rad(fcu);
} }
COLLADAFW::Rotate* rot = (COLLADAFW::Rotate*)transform; COLLADAFW::Rotate* rot = (COLLADAFW::Rotate*)transform;
COLLADABU::Math::Vector3& axis = rot->getRotationAxis(); COLLADABU::Math::Vector3& axis = rot->getRotationAxis();
switch (binding->animationClass) { switch (binding->animationClass) {
case COLLADAFW::AnimationList::ANGLE: case COLLADAFW::AnimationList::ANGLE:
if (COLLADABU::Math::Vector3::UNIT_X == axis) { if (COLLADABU::Math::Vector3::UNIT_X == axis) {
modify_fcurve(curves, rna_path, 0 ); modify_fcurve(curves, rna_path, 0 );
}
else if (COLLADABU::Math::Vector3::UNIT_Y == axis) {
modify_fcurve(curves, rna_path, 1 );
}
else if (COLLADABU::Math::Vector3::UNIT_Z == axis) {
modify_fcurve(curves, rna_path, 2 );
}
break;
case COLLADAFW::AnimationList::AXISANGLE:
// TODO convert axis-angle to quat? or XYZ?
default:
fprintf(stderr, "AnimationClass %d is not supported for ROTATE transformation.\n",
binding->animationClass);
}
break;
} }
else if (COLLADABU::Math::Vector3::UNIT_Y == axis) {
modify_fcurve(curves, rna_path, 1 );
}
else if (COLLADABU::Math::Vector3::UNIT_Z == axis) {
modify_fcurve(curves, rna_path, 2 );
}
break;
case COLLADAFW::AnimationList::AXISANGLE:
// TODO convert axis-angle to quat? or XYZ?
default:
fprintf(stderr, "AnimationClass %d is not supported for ROTATE transformation.\n",
binding->animationClass);
}
break;
}
case COLLADAFW::Transformation::MATRIX: case COLLADAFW::Transformation::MATRIX:
/*{ /*{
COLLADAFW::Matrix* mat = (COLLADAFW::Matrix*)transform; COLLADAFW::Matrix* mat = (COLLADAFW::Matrix*)transform;
COLLADABU::Math::Matrix4 mat4 = mat->getMatrix(); COLLADABU::Math::Matrix4 mat4 = mat->getMatrix();
switch (binding->animationClass) { switch (binding->animationClass) {
case COLLADAFW::AnimationList::TRANSFORM: case COLLADAFW::AnimationList::TRANSFORM:
} }
}*/ }*/
break; break;
case COLLADAFW::Transformation::SKEW: case COLLADAFW::Transformation::SKEW:
case COLLADAFW::Transformation::LOOKAT: case COLLADAFW::Transformation::LOOKAT:
fprintf(stderr, "Animation of SKEW and LOOKAT transformations is not supported yet.\n"); fprintf(stderr, "Animation of SKEW and LOOKAT transformations is not supported yet.\n");
break; break;
} }
} }
//creates the rna_paths and array indices of fcurves from animations using color and bound animation class of each animation. //creates the rna_paths and array indices of fcurves from animations using color and bound animation class of each animation.
void AnimationImporter:: Assign_color_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves ,char * anim_type) void AnimationImporter:: Assign_color_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves ,const char * anim_type)
{ {
char rna_path[100]; char rna_path[100];
BLI_strncpy(rna_path,anim_type, sizeof(rna_path)); BLI_strncpy(rna_path,anim_type, sizeof(rna_path));
const COLLADAFW::AnimationList *animlist = animlist_map[listid]; const COLLADAFW::AnimationList *animlist = animlist_map[listid];
const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings(); const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings();
//all the curves belonging to the current binding //all the curves belonging to the current binding
std::vector<FCurve*> animcurves; std::vector<FCurve*> animcurves;
for (unsigned int j = 0; j < bindings.getCount(); j++) { for (unsigned int j = 0; j < bindings.getCount(); j++) {
animcurves = curve_map[bindings[j].animation]; animcurves = curve_map[bindings[j].animation];
switch (bindings[j].animationClass) { switch (bindings[j].animationClass) {
case COLLADAFW::AnimationList::COLOR_R: case COLLADAFW::AnimationList::COLOR_R:
modify_fcurve(&animcurves, rna_path, 0 ); modify_fcurve(&animcurves, rna_path, 0 );
break; break;
@ -598,13 +592,13 @@ void AnimationImporter:: Assign_color_animations(const COLLADAFW::UniqueId& list
case COLLADAFW::AnimationList::COLOR_RGBA: // to do-> set intensity case COLLADAFW::AnimationList::COLOR_RGBA: // to do-> set intensity
modify_fcurve(&animcurves, rna_path, -1 ); modify_fcurve(&animcurves, rna_path, -1 );
break; break;
default: default:
fprintf(stderr, "AnimationClass %d is not supported for %s.\n", fprintf(stderr, "AnimationClass %d is not supported for %s.\n",
bindings[j].animationClass, "COLOR" ); bindings[j].animationClass, "COLOR" );
} }
std::vector<FCurve*>::iterator iter; std::vector<FCurve*>::iterator iter;
//Add the curves of the current animation to the object //Add the curves of the current animation to the object
for (iter = animcurves.begin(); iter != animcurves.end(); iter++) { for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
FCurve * fcu = *iter; FCurve * fcu = *iter;
@ -612,10 +606,10 @@ void AnimationImporter:: Assign_color_animations(const COLLADAFW::UniqueId& list
} }
} }
} }
void AnimationImporter:: Assign_float_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, char * anim_type) void AnimationImporter:: Assign_float_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const char * anim_type)
{ {
char rna_path[100]; char rna_path[100];
if (animlist_map.find(listid) == animlist_map.end()) return ; if (animlist_map.find(listid) == animlist_map.end()) return ;
@ -625,7 +619,7 @@ void AnimationImporter:: Assign_float_animations(const COLLADAFW::UniqueId& list
const COLLADAFW::AnimationList *animlist = animlist_map[listid]; const COLLADAFW::AnimationList *animlist = animlist_map[listid];
const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings(); const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings();
//all the curves belonging to the current binding //all the curves belonging to the current binding
std::vector<FCurve*> animcurves; std::vector<FCurve*> animcurves;
for (unsigned int j = 0; j < bindings.getCount(); j++) { for (unsigned int j = 0; j < bindings.getCount(); j++) {
animcurves = curve_map[bindings[j].animation]; animcurves = curve_map[bindings[j].animation];
@ -671,28 +665,28 @@ void AnimationImporter::apply_matrix_curves( Object * ob, std::vector<FCurve*>&
copy_m4_m4(rest, bone->arm_mat); copy_m4_m4(rest, bone->arm_mat);
invert_m4_m4(irest, rest); invert_m4_m4(irest, rest);
} }
// new curves to assign matrix transform animation // new curves to assign matrix transform animation
FCurve *newcu[10]; // if tm_type is matrix, then create 10 curves: 4 rot, 3 loc, 3 scale FCurve *newcu[10]; // if tm_type is matrix, then create 10 curves: 4 rot, 3 loc, 3 scale
unsigned int totcu = 10 ; unsigned int totcu = 10 ;
const char *tm_str = NULL; const char *tm_str = NULL;
char rna_path[200]; char rna_path[200];
for (int i = 0; i < totcu; i++) { for (int i = 0; i < totcu; i++) {
int axis = i; int axis = i;
if (i < 4) { if (i < 4) {
tm_str = "rotation_quaternion"; tm_str = "rotation_quaternion";
axis = i; axis = i;
} }
else if (i < 7) { else if (i < 7) {
tm_str = "location"; tm_str = "location";
axis = i - 4; axis = i - 4;
} }
else { else {
tm_str = "scale"; tm_str = "scale";
axis = i - 7; axis = i - 7;
} }
if (is_joint) if (is_joint)
BLI_snprintf(rna_path, sizeof(rna_path), "%s.%s", joint_path, tm_str); BLI_snprintf(rna_path, sizeof(rna_path), "%s.%s", joint_path, tm_str);
@ -702,11 +696,11 @@ void AnimationImporter::apply_matrix_curves( Object * ob, std::vector<FCurve*>&
newcu[i]->totvert = frames.size(); newcu[i]->totvert = frames.size();
} }
if (frames.size() == 0) if (frames.size() == 0)
return; return;
std::sort(frames.begin(), frames.end()); std::sort(frames.begin(), frames.end());
std::vector<float>::iterator it; std::vector<float>::iterator it;
// sample values at each frame // sample values at each frame
@ -717,7 +711,7 @@ std::sort(frames.begin(), frames.end());
float matfra[4][4]; float matfra[4][4];
unit_m4(matfra); unit_m4(matfra);
// calc object-space mat // calc object-space mat
evaluate_transform_at_frame(matfra, node, fra); evaluate_transform_at_frame(matfra, node, fra);
@ -743,23 +737,23 @@ std::sort(frames.begin(), frames.end());
} }
float rot[4], loc[3], scale[3]; float rot[4], loc[3], scale[3];
mat4_to_quat(rot, mat); mat4_to_quat(rot, mat);
/*for ( int i = 0 ; i < 4 ; i ++ ) /*for ( int i = 0 ; i < 4 ; i ++ )
{ {
rot[i] = rot[i] * (180 / M_PI); rot[i] = rot[i] * (180 / M_PI);
}*/ }*/
copy_v3_v3(loc, mat[3]); copy_v3_v3(loc, mat[3]);
mat4_to_size(scale, mat); mat4_to_size(scale, mat);
// add keys // add keys
for (int i = 0; i < totcu; i++) { for (int i = 0; i < totcu; i++) {
if (i < 4) if (i < 4)
add_bezt(newcu[i], fra, rot[i]); add_bezt(newcu[i], fra, rot[i]);
else if (i < 7) else if (i < 7)
add_bezt(newcu[i], fra, loc[i - 4]); add_bezt(newcu[i], fra, loc[i - 4]);
else else
add_bezt(newcu[i], fra, scale[i - 7]); add_bezt(newcu[i], fra, scale[i - 7]);
} }
} }
verify_adt_action((ID*)&ob->id, 1); verify_adt_action((ID*)&ob->id, 1);
@ -774,13 +768,13 @@ std::sort(frames.begin(), frames.end());
BLI_addtail(curves, newcu[i]); BLI_addtail(curves, newcu[i]);
} }
if (is_joint) { if (is_joint) {
bPoseChannel *chan = get_pose_channel(ob->pose, bone_name); bPoseChannel *chan = get_pose_channel(ob->pose, bone_name);
chan->rotmode = ROT_MODE_QUAT; chan->rotmode = ROT_MODE_QUAT;
} }
else { else {
ob->rotmode = ROT_MODE_QUAT; ob->rotmode = ROT_MODE_QUAT;
} }
return; return;
@ -803,25 +797,24 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
} }
bAction * act; bAction * act;
bActionGroup *grp = NULL;
if ( (animType->transform) != 0 ) if ( (animType->transform) != 0 )
{ {
const char *bone_name = is_joint ? bc_get_joint_name(node) : NULL; const char *bone_name = is_joint ? bc_get_joint_name(node) : NULL;
char joint_path[200]; char joint_path[200];
if ( is_joint ) if ( is_joint )
armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path)); armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path));
if (!ob->adt || !ob->adt->action) act = verify_adt_action((ID*)&ob->id, 1); if (!ob->adt || !ob->adt->action) act = verify_adt_action((ID*)&ob->id, 1);
else act = ob->adt->action; else act = ob->adt->action;
//Get the list of animation curves of the object //Get the list of animation curves of the object
ListBase *AnimCurves = &(act->curves); ListBase *AnimCurves = &(act->curves);
const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations(); const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations();
//for each transformation in node //for each transformation in node
for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) { for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
COLLADAFW::Transformation *transform = nodeTransforms[i]; COLLADAFW::Transformation *transform = nodeTransforms[i];
@ -829,10 +822,10 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE; bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX; bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
const COLLADAFW::UniqueId& listid = transform->getAnimationList(); const COLLADAFW::UniqueId& listid = transform->getAnimationList();
//check if transformation has animations //check if transformation has animations
if (animlist_map.find(listid) == animlist_map.end()) continue ; if (animlist_map.find(listid) == animlist_map.end()) continue ;
else else
{ {
@ -840,25 +833,25 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
const COLLADAFW::AnimationList *animlist = animlist_map[listid]; const COLLADAFW::AnimationList *animlist = animlist_map[listid];
const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings(); const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings();
//all the curves belonging to the current binding //all the curves belonging to the current binding
std::vector<FCurve*> animcurves; std::vector<FCurve*> animcurves;
for (unsigned int j = 0; j < bindings.getCount(); j++) { for (unsigned int j = 0; j < bindings.getCount(); j++) {
animcurves = curve_map[bindings[j].animation]; animcurves = curve_map[bindings[j].animation];
if ( is_matrix ) if ( is_matrix )
apply_matrix_curves(ob, animcurves, root , node, transform ); apply_matrix_curves(ob, animcurves, root , node, transform );
else { else {
//calculate rnapaths and array index of fcurves according to transformation and animation class //calculate rnapaths and array index of fcurves according to transformation and animation class
Assign_transform_animations(transform, &bindings[j], &animcurves, is_joint, joint_path ); Assign_transform_animations(transform, &bindings[j], &animcurves, is_joint, joint_path );
std::vector<FCurve*>::iterator iter; std::vector<FCurve*>::iterator iter;
//Add the curves of the current animation to the object //Add the curves of the current animation to the object
for (iter = animcurves.begin(); iter != animcurves.end(); iter++) { for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
FCurve * fcu = *iter; FCurve * fcu = *iter;
if ((ob->type == OB_ARMATURE)) if ((ob->type == OB_ARMATURE))
add_bone_fcurve( ob, node , fcu ); add_bone_fcurve( ob, node , fcu );
else else
BLI_addtail(AnimCurves, fcu); BLI_addtail(AnimCurves, fcu);
}
} }
}
} }
} }
if (is_rotation) { if (is_rotation) {
@ -880,7 +873,7 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
Lamp * lamp = (Lamp*) ob->data; Lamp * lamp = (Lamp*) ob->data;
if (!lamp->adt || !lamp->adt->action) act = verify_adt_action((ID*)&lamp->id, 1); if (!lamp->adt || !lamp->adt->action) act = verify_adt_action((ID*)&lamp->id, 1);
else act = lamp->adt->action; else act = lamp->adt->action;
ListBase *AnimCurves = &(act->curves); ListBase *AnimCurves = &(act->curves);
const COLLADAFW::InstanceLightPointerArray& nodeLights = node->getInstanceLights(); const COLLADAFW::InstanceLightPointerArray& nodeLights = node->getInstanceLights();
@ -892,23 +885,23 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
{ {
const COLLADAFW::Color *col = &(light->getColor()); const COLLADAFW::Color *col = &(light->getColor());
const COLLADAFW::UniqueId& listid = col->getAnimationList(); const COLLADAFW::UniqueId& listid = col->getAnimationList();
Assign_color_animations(listid, AnimCurves, "color"); Assign_color_animations(listid, AnimCurves, "color");
} }
if ((animType->light & LIGHT_FOA) != 0 ) if ((animType->light & LIGHT_FOA) != 0 )
{ {
const COLLADAFW::AnimatableFloat *foa = &(light->getFallOffAngle()); const COLLADAFW::AnimatableFloat *foa = &(light->getFallOffAngle());
const COLLADAFW::UniqueId& listid = foa->getAnimationList(); const COLLADAFW::UniqueId& listid = foa->getAnimationList();
Assign_float_animations( listid ,AnimCurves, "spot_size"); Assign_float_animations( listid ,AnimCurves, "spot_size");
} }
if ( (animType->light & LIGHT_FOE) != 0 ) if ( (animType->light & LIGHT_FOE) != 0 )
{ {
const COLLADAFW::AnimatableFloat *foe = &(light->getFallOffExponent()); const COLLADAFW::AnimatableFloat *foe = &(light->getFallOffExponent());
const COLLADAFW::UniqueId& listid = foe->getAnimationList(); const COLLADAFW::UniqueId& listid = foe->getAnimationList();
Assign_float_animations( listid ,AnimCurves, "spot_blend"); Assign_float_animations( listid ,AnimCurves, "spot_blend");
} }
} }
} }
@ -918,7 +911,7 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
Camera * camera = (Camera*) ob->data; Camera * camera = (Camera*) ob->data;
if (!camera->adt || !camera->adt->action) act = verify_adt_action((ID*)&camera->id, 1); if (!camera->adt || !camera->adt->action) act = verify_adt_action((ID*)&camera->id, 1);
else act = camera->adt->action; else act = camera->adt->action;
ListBase *AnimCurves = &(act->curves); ListBase *AnimCurves = &(act->curves);
const COLLADAFW::InstanceCameraPointerArray& nodeCameras= node->getInstanceCameras(); const COLLADAFW::InstanceCameraPointerArray& nodeCameras= node->getInstanceCameras();
@ -957,12 +950,12 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
} }
} }
if ( animType->material != 0){ if ( animType->material != 0){
Material *ma = give_current_material(ob, 1); Material *ma = give_current_material(ob, 1);
if (!ma->adt || !ma->adt->action) act = verify_adt_action((ID*)&ma->id, 1); if (!ma->adt || !ma->adt->action) act = verify_adt_action((ID*)&ma->id, 1);
else act = ma->adt->action; else act = ma->adt->action;
ListBase *AnimCurves = &(act->curves); ListBase *AnimCurves = &(act->curves);
const COLLADAFW::InstanceGeometryPointerArray& nodeGeoms = node->getInstanceGeometries(); const COLLADAFW::InstanceGeometryPointerArray& nodeGeoms = node->getInstanceGeometries();
for (unsigned int i = 0; i < nodeGeoms.getCount(); i++) { for (unsigned int i = 0; i < nodeGeoms.getCount(); i++) {
const COLLADAFW::MaterialBindingArray& matBinds = nodeGeoms[i]->getMaterialBindings(); const COLLADAFW::MaterialBindingArray& matBinds = nodeGeoms[i]->getMaterialBindings();
@ -988,7 +981,7 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
const COLLADAFW::UniqueId& listid = cot->getColor().getAnimationList(); const COLLADAFW::UniqueId& listid = cot->getColor().getAnimationList();
Assign_color_animations( listid, AnimCurves , "specular_color" ); Assign_color_animations( listid, AnimCurves , "specular_color" );
} }
if((animType->material & MATERIAL_DIFF_COLOR) != 0){ if((animType->material & MATERIAL_DIFF_COLOR) != 0){
const COLLADAFW::ColorOrTexture *cot = &(efc->getDiffuse()); const COLLADAFW::ColorOrTexture *cot = &(efc->getDiffuse());
const COLLADAFW::UniqueId& listid = cot->getColor().getAnimationList(); const COLLADAFW::UniqueId& listid = cot->getColor().getAnimationList();
@ -1005,15 +998,15 @@ AnimationImporter::AnimMix* AnimationImporter::get_animation_type ( const COLLAD
std::map<COLLADAFW::UniqueId, const COLLADAFW::Object*> FW_object_map) std::map<COLLADAFW::UniqueId, const COLLADAFW::Object*> FW_object_map)
{ {
AnimMix *types = new AnimMix(); AnimMix *types = new AnimMix();
const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations(); const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations();
//for each transformation in node //for each transformation in node
for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) { for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
COLLADAFW::Transformation *transform = nodeTransforms[i]; COLLADAFW::Transformation *transform = nodeTransforms[i];
const COLLADAFW::UniqueId& listid = transform->getAnimationList(); const COLLADAFW::UniqueId& listid = transform->getAnimationList();
//check if transformation has animations //check if transformation has animations
if (animlist_map.find(listid) == animlist_map.end()) continue ; if (animlist_map.find(listid) == animlist_map.end()) continue ;
else else
{ {
@ -1028,9 +1021,9 @@ AnimationImporter::AnimMix* AnimationImporter::get_animation_type ( const COLLAD
types->light = setAnimType(&(light->getColor()),(types->light), LIGHT_COLOR); types->light = setAnimType(&(light->getColor()),(types->light), LIGHT_COLOR);
types->light = setAnimType(&(light->getFallOffAngle()),(types->light), LIGHT_FOA); types->light = setAnimType(&(light->getFallOffAngle()),(types->light), LIGHT_FOA);
types->light = setAnimType(&(light->getFallOffExponent()),(types->light), LIGHT_FOE); types->light = setAnimType(&(light->getFallOffExponent()),(types->light), LIGHT_FOE);
if ( types->light != 0) break; if ( types->light != 0) break;
} }
const COLLADAFW::InstanceCameraPointerArray& nodeCameras = node->getInstanceCameras(); const COLLADAFW::InstanceCameraPointerArray& nodeCameras = node->getInstanceCameras();
@ -1039,9 +1032,9 @@ AnimationImporter::AnimMix* AnimationImporter::get_animation_type ( const COLLAD
if ( camera->getCameraType() == COLLADAFW::Camera::PERSPECTIVE ) if ( camera->getCameraType() == COLLADAFW::Camera::PERSPECTIVE )
{ {
types->camera = setAnimType(&(camera->getXMag()),(types->camera), CAMERA_XFOV); types->camera = setAnimType(&(camera->getXMag()),(types->camera), CAMERA_XFOV);
} }
else else
{ {
types->camera = setAnimType(&(camera->getXMag()),(types->camera), CAMERA_XMAG); types->camera = setAnimType(&(camera->getXMag()),(types->camera), CAMERA_XMAG);
} }
@ -1059,12 +1052,14 @@ AnimationImporter::AnimMix* AnimationImporter::get_animation_type ( const COLLAD
const COLLADAFW::UniqueId & matuid = matBinds[j].getReferencedMaterial(); const COLLADAFW::UniqueId & matuid = matBinds[j].getReferencedMaterial();
const COLLADAFW::Effect *ef = (COLLADAFW::Effect *) (FW_object_map[matuid]); const COLLADAFW::Effect *ef = (COLLADAFW::Effect *) (FW_object_map[matuid]);
const COLLADAFW::CommonEffectPointerArray& commonEffects = ef->getCommonEffects(); const COLLADAFW::CommonEffectPointerArray& commonEffects = ef->getCommonEffects();
COLLADAFW::EffectCommon *efc = commonEffects[0]; if(!commonEffects.empty()) {
types->material = setAnimType(&(efc->getShininess()),(types->material), MATERIAL_SHININESS); COLLADAFW::EffectCommon *efc = commonEffects[0];
types->material = setAnimType(&(efc->getSpecular().getColor()),(types->material), MATERIAL_SPEC_COLOR); types->material = setAnimType(&(efc->getShininess()),(types->material), MATERIAL_SHININESS);
types->material = setAnimType(&(efc->getDiffuse().getColor()),(types->material), MATERIAL_DIFF_COLOR); types->material = setAnimType(&(efc->getSpecular().getColor()),(types->material), MATERIAL_SPEC_COLOR);
// types->material = setAnimType(&(efc->get()),(types->material), MATERIAL_TRANSPARENCY); types->material = setAnimType(&(efc->getDiffuse().getColor()),(types->material), MATERIAL_DIFF_COLOR);
types->material = setAnimType(&(efc->getIndexOfRefraction()),(types->material), MATERIAL_IOR); // types->material = setAnimType(&(efc->get()),(types->material), MATERIAL_TRANSPARENCY);
types->material = setAnimType(&(efc->getIndexOfRefraction()),(types->material), MATERIAL_IOR);
}
} }
} }
return types; return types;
@ -1101,7 +1096,7 @@ void AnimationImporter::find_frames_old(std::vector<float> * frames, COLLADAFW::
const COLLADAFW::AnimationList *animlist = animlist_map[listid]; const COLLADAFW::AnimationList *animlist = animlist_map[listid];
const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings(); const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings();
if (bindings.getCount()) { if (bindings.getCount()) {
//for each AnimationBinding get the fcurves which animate the transform //for each AnimationBinding get the fcurves which animate the transform
for (unsigned int j = 0; j < bindings.getCount(); j++) { for (unsigned int j = 0; j < bindings.getCount(); j++) {
@ -1113,7 +1108,7 @@ void AnimationImporter::find_frames_old(std::vector<float> * frames, COLLADAFW::
for (iter = curves.begin(); iter != curves.end(); iter++) { for (iter = curves.begin(); iter != curves.end(); iter++) {
FCurve *fcu = *iter; FCurve *fcu = *iter;
//if transform is rotation the fcurves values must be turned in to radian. //if transform is rotation the fcurves values must be turned in to radian.
if (is_rotation) if (is_rotation)
fcurve_deg_to_rad(fcu); fcurve_deg_to_rad(fcu);
@ -1448,9 +1443,9 @@ bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm, float
COLLADAFW::Transformation::TransformationType type = tm->getTransformationType(); COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();
if (type != COLLADAFW::Transformation::ROTATE && if (type != COLLADAFW::Transformation::ROTATE &&
type != COLLADAFW::Transformation::SCALE && type != COLLADAFW::Transformation::SCALE &&
type != COLLADAFW::Transformation::TRANSLATE && type != COLLADAFW::Transformation::TRANSLATE &&
type != COLLADAFW::Transformation::MATRIX) { type != COLLADAFW::Transformation::MATRIX) {
fprintf(stderr, "animation of transformation %d is not supported yet\n", type); fprintf(stderr, "animation of transformation %d is not supported yet\n", type);
return false; return false;
} }
@ -1572,7 +1567,7 @@ bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm, float
COLLADAFW::Matrix tm(matrix); COLLADAFW::Matrix tm(matrix);
dae_matrix_to_mat4(&tm, mat); dae_matrix_to_mat4(&tm, mat);
std::vector<FCurve*>::iterator it; std::vector<FCurve*>::iterator it;
return true; return true;

@ -88,7 +88,7 @@ private:
void add_fcurves_to_object(Object *ob, std::vector<FCurve*>& curves, char *rna_path, int array_index, Animation *animated); void add_fcurves_to_object(Object *ob, std::vector<FCurve*>& curves, char *rna_path, int array_index, Animation *animated);
int typeFlag; int typeFlag;
enum lightAnim enum lightAnim
{ {
// INANIMATE = 0, // INANIMATE = 0,
@ -144,7 +144,7 @@ public:
#if 0 #if 0
virtual void change_eul_to_quat(Object *ob, bAction *act); virtual void change_eul_to_quat(Object *ob, bAction *act);
#endif #endif
void translate_Animations( COLLADAFW::Node * Node , void translate_Animations( COLLADAFW::Node * Node ,
std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& root_map, std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& root_map,
std::map<COLLADAFW::UniqueId, Object*>& object_map , std::map<COLLADAFW::UniqueId, Object*>& object_map ,
@ -159,9 +159,9 @@ public:
const COLLADAFW::AnimationList::AnimationBinding * binding, const COLLADAFW::AnimationList::AnimationBinding * binding,
std::vector<FCurve*>* curves, bool is_joint, char * joint_path); std::vector<FCurve*>* curves, bool is_joint, char * joint_path);
void Assign_color_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves ,char * anim_type); void Assign_color_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const char * anim_type);
void Assign_float_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, char * anim_type); void Assign_float_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const char * anim_type);
int setAnimType ( const COLLADAFW::Animatable * prop , int type, int addition); int setAnimType ( const COLLADAFW::Animatable * prop , int type, int addition);
void modify_fcurve(std::vector<FCurve*>* curves , char* rna_path , int array_index ); void modify_fcurve(std::vector<FCurve*>* curves , char* rna_path , int array_index );
@ -206,5 +206,5 @@ public:
void extra_data_importer(std::string elementName); void extra_data_importer(std::string elementName);
}; };
#endif #endif

@ -49,7 +49,7 @@
// XXX exporter writes wrong data for shared armatures. A separate // XXX exporter writes wrong data for shared armatures. A separate
// controller should be written for each armature-mesh binding how do // controller should be written for each armature-mesh binding how do
// we make controller ids then? // we make controller ids then?
ArmatureExporter::ArmatureExporter(COLLADASW::StreamWriter *sw) : COLLADASW::LibraryControllers(sw) {} ArmatureExporter::ArmatureExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryControllers(sw), export_settings(export_settings) {}
// write bone nodes // write bone nodes
void ArmatureExporter::add_armature_bones(Object *ob_arm, Scene *sce) void ArmatureExporter::add_armature_bones(Object *ob_arm, Scene *sce)
@ -90,14 +90,14 @@ void ArmatureExporter::add_instance_controller(Object *ob)
ins.add(); ins.add();
} }
void ArmatureExporter::export_controllers(Scene *sce, bool export_selected) void ArmatureExporter::export_controllers(Scene *sce)
{ {
scene = sce; scene = sce;
openLibrary(); openLibrary();
GeometryFunctor gf; GeometryFunctor gf;
gf.forEachMeshObjectInScene<ArmatureExporter>(sce, *this, export_selected); gf.forEachMeshObjectInScene<ArmatureExporter>(sce, *this, this->export_settings->selected);
closeLibrary(); closeLibrary();
} }
@ -188,7 +188,7 @@ void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm)
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) { for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) {
add_bone_node(child, ob_arm); add_bone_node(child, ob_arm);
} }
node.end(); node.end();
//} //}
} }

@ -47,16 +47,15 @@
#include "TransformWriter.h" #include "TransformWriter.h"
#include "InstanceWriter.h" #include "InstanceWriter.h"
#include "ExportSettings.h"
// XXX exporter writes wrong data for shared armatures. A separate // XXX exporter writes wrong data for shared armatures. A separate
// controller should be written for each armature-mesh binding how do // controller should be written for each armature-mesh binding how do
// we make controller ids then? // we make controller ids then?
class ArmatureExporter: public COLLADASW::LibraryControllers, protected TransformWriter, protected InstanceWriter class ArmatureExporter: public COLLADASW::LibraryControllers, protected TransformWriter, protected InstanceWriter
{ {
private:
Scene *scene;
public: public:
ArmatureExporter(COLLADASW::StreamWriter *sw); ArmatureExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings);
// write bone nodes // write bone nodes
void add_armature_bones(Object *ob_arm, Scene *sce); void add_armature_bones(Object *ob_arm, Scene *sce);
@ -65,13 +64,14 @@ public:
void add_instance_controller(Object *ob); void add_instance_controller(Object *ob);
void export_controllers(Scene *sce, bool export_selected); void export_controllers(Scene *sce);
void operator()(Object *ob); void operator()(Object *ob);
private: private:
Scene *scene;
UnitConverter converter; UnitConverter converter;
const ExportSettings *export_settings;
#if 0 #if 0
std::vector<Object*> written_armatures; std::vector<Object*> written_armatures;
@ -119,25 +119,4 @@ private:
Object *ob_arm, ListBase *defbase); Object *ob_arm, ListBase *defbase);
}; };
/*
struct GeometryFunctor {
// f should have
// void operator()(Object* ob)
template<class Functor>
void forEachMeshObjectInScene(Scene *sce, Functor &f)
{
Base *base= (Base*) sce->base.first;
while(base) {
Object *ob = base->object;
if (ob->type == OB_MESH && ob->data) {
f(ob);
}
base= base->next;
}
}
};*/
#endif #endif

@ -87,7 +87,7 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
if ( it != finished_joints.end()) return; if ( it != finished_joints.end()) return;
float mat[4][4]; float mat[4][4];
float obmat[4][4]; float obmat[4][4];
// object-space // object-space
get_node_mat(obmat, node, NULL, NULL); get_node_mat(obmat, node, NULL, NULL);
@ -95,8 +95,6 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
EditBone *bone = ED_armature_edit_bone_add((bArmature*)ob_arm->data, (char*)bc_get_joint_name(node)); EditBone *bone = ED_armature_edit_bone_add((bArmature*)ob_arm->data, (char*)bc_get_joint_name(node));
totbone++; totbone++;
bPoseChannel *pchan = get_pose_channel(ob_arm->pose, (char*)bc_get_joint_name(node));
if (parent) bone->parent = parent; if (parent) bone->parent = parent;
float angle = 0; float angle = 0;
@ -280,8 +278,6 @@ void ArmatureImporter::add_leaf_bone(float mat[][4], EditBone *bone, COLLADAFW:
copy_m4_m4(leaf.mat, mat); copy_m4_m4(leaf.mat, mat);
BLI_strncpy(leaf.name, bone->name, sizeof(leaf.name)); BLI_strncpy(leaf.name, bone->name, sizeof(leaf.name));
float vec[3];
TagsMap::iterator etit; TagsMap::iterator etit;
ExtraTags *et = 0; ExtraTags *et = 0;
etit = uid_tags_map.find(node->getUniqueId().toAscii()); etit = uid_tags_map.find(node->getUniqueId().toAscii());
@ -296,7 +292,7 @@ void ArmatureImporter::add_leaf_bone(float mat[][4], EditBone *bone, COLLADAFW:
et->setData("tip_z",&z); et->setData("tip_z",&z);
float vec[3] = {x,y,z}; float vec[3] = {x,y,z};
copy_v3_v3(leaf.bone->tail, leaf.bone->head); copy_v3_v3(leaf.bone->tail, leaf.bone->head);
add_v3_v3v3(leaf.bone->tail, leaf.bone->head, vec); add_v3_v3v3(leaf.bone->tail, leaf.bone->head, vec);
}else }else
leaf_bones.push_back(leaf); leaf_bones.push_back(leaf);
} }
@ -579,9 +575,8 @@ void ArmatureImporter::set_pose ( Object * ob_arm , COLLADAFW::Node * root_node
float mat[4][4]; float mat[4][4];
float obmat[4][4]; float obmat[4][4];
bArmature * arm = (bArmature * ) ob_arm-> data ;
float ax[3]; float ax[3];
float angle = NULL; float angle = 0.0f;
// object-space // object-space
get_node_mat(obmat, root_node, NULL, NULL); get_node_mat(obmat, root_node, NULL, NULL);

@ -115,7 +115,7 @@ private:
void fix_leaf_bones(); void fix_leaf_bones();
void set_pose ( Object * ob_arm , COLLADAFW::Node * root_node ,char * parentname, float parent_mat[][4]); void set_pose ( Object * ob_arm , COLLADAFW::Node * root_node ,char * parentname, float parent_mat[][4]);
#if 0 #if 0
@ -171,7 +171,7 @@ public:
// gives a world-space mat // gives a world-space mat
bool get_joint_bind_mat(float m[][4], COLLADAFW::Node *joint); bool get_joint_bind_mat(float m[][4], COLLADAFW::Node *joint);
void set_tags_map( TagsMap& tags_map); void set_tags_map( TagsMap& tags_map);
}; };

@ -51,6 +51,8 @@ set(SRC
DocumentExporter.cpp DocumentExporter.cpp
DocumentImporter.cpp DocumentImporter.cpp
EffectExporter.cpp EffectExporter.cpp
ErrorHandler.cpp
ExportSettings.cpp
ExtraHandler.cpp ExtraHandler.cpp
ExtraTags.cpp ExtraTags.cpp
GeometryExporter.cpp GeometryExporter.cpp
@ -60,6 +62,7 @@ set(SRC
MaterialExporter.cpp MaterialExporter.cpp
MeshImporter.cpp MeshImporter.cpp
SkinInfo.cpp SkinInfo.cpp
SceneExporter.cpp
TransformReader.cpp TransformReader.cpp
TransformWriter.cpp TransformWriter.cpp
collada.cpp collada.cpp
@ -74,6 +77,8 @@ set(SRC
DocumentExporter.h DocumentExporter.h
DocumentImporter.h DocumentImporter.h
EffectExporter.h EffectExporter.h
ErrorHandler.h
ExportSettings.h
ExtraHandler.h ExtraHandler.h
ExtraTags.h ExtraTags.h
GeometryExporter.h GeometryExporter.h
@ -83,6 +88,7 @@ set(SRC
MaterialExporter.h MaterialExporter.h
MeshImporter.h MeshImporter.h
SkinInfo.h SkinInfo.h
SceneExporter.h
TransformReader.h TransformReader.h
TransformWriter.h TransformWriter.h
collada.h collada.h

@ -39,7 +39,7 @@
#include "collada_internal.h" #include "collada_internal.h"
CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryCameras(sw){} CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): COLLADASW::LibraryCameras(sw), export_settings(export_settings) {}
template<class Functor> template<class Functor>
void forEachCameraObjectInScene(Scene *sce, Functor &f, bool export_selected) void forEachCameraObjectInScene(Scene *sce, Functor &f, bool export_selected)
@ -56,11 +56,11 @@ void forEachCameraObjectInScene(Scene *sce, Functor &f, bool export_selected)
} }
} }
void CamerasExporter::exportCameras(Scene *sce, bool export_selected) void CamerasExporter::exportCameras(Scene *sce)
{ {
openLibrary(); openLibrary();
forEachCameraObjectInScene(sce, *this, export_selected); forEachCameraObjectInScene(sce, *this, this->export_settings->selected);
closeLibrary(); closeLibrary();
} }

Some files were not shown because too many files have changed in this diff Show More