1
1

Compare commits

..

92 Commits

Author SHA1 Message Date
bcf1626934 cleanup: GPUBufferCopyFunc defined twice 2015-05-14 13:17:12 -04:00
8e08b34061 clean up GPUx vertex buffer API (part 1)
Removed unprimed version of GPUx_vertex_buffer_use function. The new
pattern is create, fill, prime, use {draw} done_using, use {draw}
done_using ...

Renamed GPUx_vertex_buffer_use_primed to GPUx_vertex_buffer_use since
there's only one version now.

Also removed the _primed suffix from GPUx_element_list_use.

TODO: make a wiki page about how to use this API
2015-05-14 02:57:40 -04:00
d58765ccb3 fix mismatched memory free
This string is copied with strdup during GPUx_specify_attrib, needs a
plain free.
2015-05-14 00:38:10 -04:00
25e492edaa new function: bind all attrib locations
Was binding these by hand in wireframe shader tests, but retyping the
name strings is a potential source of errors. Call this function instead
after creating VertexBuffer but before linking the GLSL program.
2015-05-13 23:57:03 -04:00
eb42cbf273 Revert "Add missing stubs for buffer generation."
This reverts commit 4040f0af00.
2015-05-12 17:16:50 -04:00
247a1659fa Merge branch 'master' into GPU_data_request 2015-05-11 11:09:04 +02:00
4040f0af00 Add missing stubs for buffer generation. 2015-05-11 11:08:40 +02:00
95ca1ed75d Compilation fixes for C90 - still getting link errors related to buffer
generation routines.
2015-05-11 11:04:19 +02:00
b733d44f04 WIP: fancy wireframe display
Exploring some possibilities with wireframe rendering beyond solid
color.

New effect: color edges based on angle between the faces joined. Loose
edges, perimeter edges, and edges joining 3+ faces are colored
differently.

Some of this code will move to Workflow Shaders. Other parts will move
to DerivedMesh data requests — AdjacentFaces (struct) and/or angle made
by adjacent faces (float).

The (incomplete) shader version uses VertexBuffer’s generic attribute
API, which we want to switch everything to eventually. There is a GLSL
vertex shader *not* included in this commit because I don’t know where
to put it…

The CPU version is temporary — it’s equivalent to the shader setup +
matching GLSL shader.

This particular effect is view independent, so can be done CPU-side
once and drawn many times. Other effects I’m working on are view
dependent, so really need the setup + shader split.
2015-04-28 19:45:58 -04:00
09076e4f99 check extensions before use in GPUx
Using VAOs and integer vertex attributes.

VBO support is *not* checked because it’s guaranteed to be there in a
GL 2.1 context.

VAOs are not part of GL 2.1, but enjoy nearly universal support.

gpu_shader4 is widely supported on recent hardware, not always on older
HW.
2015-04-27 14:55:26 -04:00
9e8f939769 add runtime check for gpu_shader4 support
This extension includes a number of GLSL enhancements:
- full integer support
- interpolation qualifiers (flat, smooth, noperspective)
- gl_VertexID, gl_PrimitiveID
- custom fragment shader outputs, for MRT
2015-04-27 14:40:46 -04:00
b9ac83ce9d single alloc per VertexBuffer, down from 2
Using flexible array member from C99.

Tested on LLVM/clang, also supported in GCC and MSVC according to docs:

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
https://msdn.microsoft.com/en-us/library/b6fae073.aspx
2015-04-23 05:36:59 -04:00
1178265b0d minor cleanup
Mostly moving stuff to where it belongs.

UNUSED_VARS macro explains intent better than (void)var, so use it.

Considered replacing calloc with malloc for ElementList.indices, but
it’s safer to zero this in case not all primitives are set. So calloc
it stays!
2015-04-23 05:00:22 -04:00
4d972a5606 keep vertex data in main mem or VRAM (not both)
If we’re using VBOs, free our own copy once GL has the data.

Data always lives in main memory while being constructed, so that we
don’t need to call any OpenGL functions until it’s time to draw.
2015-04-23 03:06:30 -04:00
6f51182755 minor cleanup 2015-04-23 01:29:54 -04:00
316b953e34 reset shading to SMOOTH or FLAT
missed this as part of GPUx interpolation commit
2015-04-23 00:38:26 -04:00
7cb24b52d7 cleanup my own recent stuff 2015-04-22 03:30:00 -04:00
1653bbc778 reduce VRAM usage for flat normals
Reduce number of GL verts from (3 * tess_tri_ct) to (1 * loop_ct).
Attribute data formats unchanged.

stock Suzanne mesh
507 verts, 1005 edges, 500 polys, 500 faces, 1968 loops

mode = NORMAL_DRAW_FLAT

(3 * tri_ct) verts, vec3s normals (+padding)
GPUx batch size: 63886 bytes

(3 * tri_ct) verts, vec3s normals (no padding)
GPUx batch size: 58080 bytes

loop_ct verts, vec3s normals (+padding)
GPUx batch size: 45166 bytes

loop_ct verts, vec3s normals (no padding)
GPUx batch size: 41232 bytes
2015-04-22 02:59:55 -04:00
27fe1353ad reduce VRAM usage for loop normals
Use GL_SHORT instead of GL_FLOAT for normal attribute. Savings scale
proportional to loop count.

stock Suzanne mesh
507 verts, 1005 edges, 500 polys, 500 faces, 1968 loops

mode = NORMAL_DRAW_LOOP

vec3f normals
GPUx batch size: 53040 bytes

vec3s normals (+padding)
GPUx batch size: 45166 bytes

vec3s normals (no padding)
GPUx batch size: 41232 bytes
2015-04-22 02:13:42 -04:00
6ccc770a95 determine normal draw mode better
based on auto smooth, how many faces are flat vs. smooth, and viewport
overrides.
2015-04-22 01:23:36 -04:00
562d6ee7c4 fix compiler warnings (gcc 4.9) 2015-04-21 22:01:44 -04:00
249a1e7f18 Mesh drawing: loop normals
Looks good, matches existing viewport.

Still room for size optimization here and with flat shading.
2015-04-21 17:17:20 -04:00
8e069c4f8d fix compile on MSVC
BLI_threads uses bool, so depends on include order. Proper fix would be
to #include <stdbool.h> in BLI_threads.h but I don't want to modify in
this branch.
2015-04-21 03:15:51 -04:00
59593af2a7 disable logging of orphaned GL buffer IDs 2015-04-21 03:02:30 -04:00
f0caa0bbad Merge remote-tracking branch 'origin/GPU_data_request' into GPU_data_request
Conflicts (resolved):
	source/blender/gpu/intern/gpux_draw.c
	source/blender/gpu/intern/gpux_element.c
	source/blender/gpu/intern/gpux_vbo.c
2015-04-21 02:27:52 -04:00
0ea4747752 Mesh drawing: variety of surface normal treatments
Can be NONE, SMOOTH, FLAT or LOOP.
LOOP is unfinished at the moment.
NONE might be pulled into its own drawing override mode.

Note: this commit includes some debug/tracing that is still useful to
me but will be removed in the future.
2015-04-21 01:41:26 -04:00
1cc677a037 const-ify BKE_mesh_calc_poly_normal
Some of my new mesh drawing code needs to call this with const data.

TODO: swing the “const hammer” at more BKE_mesh functions
2015-04-21 00:35:52 -04:00
1543c3f706 very minor cleanup 2015-04-21 00:31:29 -04:00
10f095463c manage GL buffer IDs in a thread-safe way
Old way was causing crash in GL when DerivedMesh discarded its
GPUxBatch from another thread.

New way deletes ID when safe to do so, otherwise “orphans” the ID to be
deleted later.
2015-04-21 00:30:30 -04:00
61978bbf32 add GPUxBatch size query
How much VRAM does our draw data use? Or process memory for client-side
data.

Note: right now data is stored in *both* places, but the code will be
smarter about storage in the future.
2015-04-19 03:06:52 -04:00
bcddec8a45 Use BLI_assert instead of assert 2015-04-17 17:31:45 +02:00
b138fbe4a1 Use our own allocation routines for GPUx module 2015-04-17 16:36:04 +02:00
805ddc7790 Merge branch 'master' into GPU_data_request
Conflicts:
	source/blender/makesdna/DNA_view3d_types.h
2015-04-17 11:37:34 +02:00
b91ebca68e add to GPUx state: interpolation (smooth shading)
and remove manual calls to glShadeModel.

TODO: interpolation qualifier per attrib (flat/smooth/noperspective)
instead of here.

This requires GLSL 1.3 (OpenGL 3.0) or EXT_gpu_shader4 so we can’t go
down that path yet.
2015-04-17 01:16:21 -04:00
4b88dbb06e remove short int -> float conversion for vertex normals
Performance experiment — thought this might be slowing down large
shaded meshes on Mac + nVidia but it was not. Index buffers in VRAM
fixed the perf issue :)

Keeping normals as GL_SHORT uses less memory. Would be 1/2 but
padding/alignment makes it 2/3. These stay GL_SHORT in VRAM also, and
are converted to floats when loaded by the vertex shader.
2015-04-16 23:23:46 -04:00
3541f234a2 fix compiler warnings (gcc 4.9) 2015-04-16 17:10:06 -04:00
6695dd5eea store index buffers in VRAM
With this change, smooth solid meshes draw faster in the new viewport
than old with VBOs.

Wireframe was already faster, now it's CRAZY fast.
2015-04-16 16:11:55 -04:00
33f85d0fe2 cache GPUx batches for performance++
WIP — developed on Mac, want to test on Linux & Windows so pushing
unfinished.

Everything needed for drawing is collected into a GPUxBatch. These are
generated per-object the first time drawn, then reused for subsequent
draws. Regenerated when DerivedMesh or draw mode changes.

TODO:
- actively reclaim memory (like gpu_buffers.c’s pool)
- store a list of batches per DM, for complex drawing
- find cause of low perf on high poly OB_SOLID rendering
2015-04-16 13:56:34 -04:00
26e5c28d39 init GL state tracking *after* clearing viewport
Clear function doesn’t use state tracking, sets GL directly.
2015-04-13 16:11:57 -04:00
86b9bcbfb4 workaround for VBOs on Mesa 2015-04-13 04:34:35 -04:00
d77ec2153b Fix crashes on undo when workflow has a nodetree.
Still getting memory leaks on exit, they likely occur because main is
owner of nodetree but we should give it to workflow instead.
2015-04-11 01:16:42 +02:00
404c9e1b7a Workflow shader fixes:
* ID type for GPUWorkflow shaders gets refined correctly
* GPUWorkflow correctly linked to spaceview3d when loading file
* Correct Icons in Node editor
* Creating a node tree works (but it's empty)
2015-04-10 23:34:13 +02:00
0b2abe145a WIP new node type for workflow shaders 2015-04-10 17:50:14 +02:00
418041628a Workflow shader data
Hook the struct to more places. Now there is a button
to choose a workflow instead of a draw type in the new viewport
(still needs to be somehow sorted according to object mode)
2015-04-10 16:38:42 +02:00
62ee03467a Add workflow shader ID to the system
Only struct definitions here. Workflow is also
set per 3d region. (We should be able to get a
workflow per region just like current textured,
solid etc modes can be set per 3D region)
2015-04-10 15:00:10 +02:00
dea27f08eb Add compositing and proper back drawing back to new viewport. 2015-04-10 14:26:12 +02:00
d3bd16b208 draw grid floor with GPUx API
Single draw call for the default case (grid floor with X and Y axes).

Z axis needs a second draw call because it uses 3D coordinates.
2015-04-09 22:24:02 -04:00
028adae2b5 add vec2f convenience function to GPUx 2015-04-09 22:13:40 -04:00
f2ef00f80e improve grid floor drawing function
Maintain visual hierarchy of the grid:
- emphasized lines draw atop normal lines
- axes draw atop all lines (same as before)

Draw axes only once, not twice.

Return early if nothing to draw.
2015-04-09 21:33:07 -04:00
cd454ab5b7 state tracking API - reorder function args
in order of importance.

Doing this early, before it’s used in more places.
2015-04-09 03:54:01 -04:00
e12432ac71 state tracking API - pass NULL to use defaults
reduces typing needed
2015-04-09 03:30:43 -04:00
165dab3551 new grid floor drawing function
changes:
- use vec2 instead of vec3 for grid
- single glBegin/End for axis lines
- draw axes regardless of grid-line count
- use depth buffer
2015-04-09 02:44:05 -04:00
699d7fd732 tweak GL state tracking
New defaults to match common 3D view usage:
- draw both sides (backface culling off)
- depth buffer test & write enabled

Also made default state more readable.
Fixed copy-paste error, GL_POLYGON_STIPPLE.

Mesh objects now draw fine in wireframe and (smooth) solid modes. Now
compatible with UI widgets drawn later!
2015-04-09 02:35:11 -04:00
12820473b2 add runtime check for VAO support 2015-04-07 19:13:30 -04:00
0aebd1b039 smooth lit meshes
WIP… still having some depth buffer issues
2015-04-07 04:56:18 -04:00
8599cfde8e draw derived mesh with GPUx API 2015-04-07 02:07:33 -04:00
3eaf30d216 draw base mesh with GPUx API
Vertex and Edge work great, Face not so much yet — totface = 0 so
nothing is drawn. Will work on derived mesh next.

draw_mesh_object_new_new is simplified to draw mesh geometry and
nothing else. Use draw_mesh_object or draw_mesh_object_new for full
functionality.
2015-04-06 16:04:16 -04:00
dc7a82e5e5 tweak GPUx draw to use actual max index
instead of max allowed index.

This is a looser restriction than before.
2015-04-06 15:43:59 -04:00
d664818c96 fix compilation when TRUST_NO_ONE is disabled 2015-04-04 03:53:40 -04:00
91cd1d98f6 More changes to defines, add GPUx prefix to public API 2015-04-03 12:32:45 +02:00
f40ffb79d4 More compilation fixes - add new files for cmake, make files conform to
old C (no declarations, use #ifdef instead or #if).
2015-04-03 12:13:28 +02:00
4d506c6303 Compile fixes for strict C - no declarations allowed in for loops and in
middle of blocks.
2015-04-03 11:41:23 +02:00
77aafef4b7 start using batched geometry API
Made “new new” version of drawcamera() to test out new drawing code.

Kept “old new” version for comparison.

Uses GL state tracking, partly disabled because it *almost* works —
need to find defaults that agree with UI drawing code.
2015-04-02 21:14:39 -04:00
995c613404 fixed issues in batched geometry API
- made default state available to all
- fixed vertex index tracking
- fixed attrib stride calculation
- fixed VBO binding
- fixed VAO attrib enables
2015-04-02 20:59:43 -04:00
9e7c8641e7 fix errors & warnings
toggling all #defines
2015-04-01 21:29:55 -04:00
c8d50ba9e6 fix VAOs on Mac legacy context
GLEW gives us glBindVertexArray and friends but sets them to NULL,
since Apple uses GL_APPLE_vertex_array_object instead of
GL_ARB_vertex_array_object. The ARB version evolved from the APPLE
version and they’re used in exactly the same way, so I aliased them to
keep our VAO code simple.
2015-04-01 20:37:17 -04:00
24dba1cbe9 tweak GL state tracking functions
Needed a way to force all currently tracked state to GL, for interop
with code that doesn’t use this API.
2015-03-31 14:42:07 -04:00
4ab3f9fb1f refactor vertex attrib handling
Found lots of commonality between generic and legacy attributes.

Also fixed an error found by flipping all the defines on & off.
2015-03-31 03:47:08 -04:00
20ce77c93c delete temp file
from merge conflict resolution, didn’t mean to commit
2015-03-31 03:30:24 -04:00
510af625bd remove unused attrib print routines 2015-03-31 01:32:25 -04:00
bc4b72eabd add support for non-generic vertex attribs
for easier integration into legacy GL usage.

Instead of specifying generic arrays with a name string, choose any or
all of these:

GL_VERTEX_ARRAY
GL_NORMAL_ARRAY
GL_COLOR_ARRAY
GL_TEXTURE_COORD_ARRAY

Generic attribs are still there for when we move to shader-based
drawing / a newer GL.
2015-03-31 01:25:43 -04:00
2398f8713a change function prefix to cdDM to match 2015-03-30 17:01:05 -04:00
84f4c305f9 Merge branch 'master' into GPU_data_request
Resolved conflict:
	source/blender/gpu/intern/gpu_buffers.c
2015-03-30 16:54:30 -04:00
2250834b40 use glDrawRangeElements for camera
glDrawElements has no way to say how much data from the vertex array is
needed, so use the Range variant instead.

glDrawArrays already has this range info.
2015-03-29 02:04:35 -04:00
d119166464 draw camera in 1 GL call (2 for active cam) 2015-03-29 01:51:13 -04:00
fcb2b87932 draw camera using vertex array 2015-03-29 01:26:00 -04:00
cfc05b0e99 put all OB_CAMERA verts in single array
also disable camera border hack (used for viewing THROUGH camera) to
focus on whole-camera drawing.
2015-03-29 01:03:58 -04:00
38ed5b82b3 remove unused test pattern
Helped for orientation before objects were drawn, no longer needed.
2015-03-29 00:22:44 -04:00
9965160c58 new draw path for Mesh & Camera objects
Used only when “new viewport” pref is checked, so we can switch back &
forth for comparison.

Camera because it’s simple — scoped some vars, removed an extra line
segment, touch back face cull state only when needed.

Mesh because it’s interesting — very little difference, just factored
out edit mesh drawing & touch back face cull state only when needed.

Also added (temporary) call graph tracing, to help me make sense of the
object drawing logic.

More to come for these object types, will run with these and add more
object types later. Not using our new APIs yet but that is the goal.
2015-03-28 04:33:47 -04:00
7bcb4fbf73 shell of a GLSL material node
This will hold a single GLSL function, which can be mixed & matched
with other nodes.

Goal: similar workflow to OSL shader node but for real-time rendering,
not Cycles.
2015-03-27 04:12:36 -04:00
6fc928599b cleanup: redundant include & defines
GLEW takes care of this.

VAOs are not part of OpenGL 2.1 but are very widely supported. Even so
we should check before using. Current code does not check.

Also minor style things I missed in the previous commit.
2015-03-21 04:23:29 -04:00
5b10412103 cleanup: code style
C-style comments, braces & pointer placement.
2015-03-21 02:06:54 -04:00
50a511b76e compile fixes for MSVC 2015-03-20 23:55:39 -04:00
49b2228c0e draw grid floor & objects in new viewport
Yanked verbatim from view3d_draw_objects, so there’s nothing “new”
about drawing method. But it does let us see objects positioned in
space which shows us transforms are working properly.
2015-03-20 18:34:13 -04:00
358732c463 OpenGL batched geometry API (experimental)
Clean slate design, with some overlap with existing Blender APIs. Using
GPUx_ prefix to avoid confusion with current GPU_ files.

- specify vertex attribs
- buffer in main memory & VRAM
- build element lists of points, lines, triangles
- draw these --^
- state tracking (fairly basic)
- lots of error & bounds checking!!! can turn this off

The idea is to handle things like VBOs, VAOs, other useful extensions
automatically so users of this API don't have to work hard to get it
right every time. This also lets us turn things on/off in one place for
debugging & perf measurements.

- - - -
Checking this code in now to give it a home & test on multiple systems.
It’s not being used yet and will probably evolve quite a bit as our
needs become clearer.
2015-03-20 18:16:56 -04:00
ded1d86b82 Just clear the buffers in new viewport 2015-02-23 11:18:17 +01:00
022d91bcf6 Flag for new viewport 2015-02-23 11:00:07 +01:00
49385d8b1b Also move new gpu object to derived mesh - we can probably do a few
abstractions here, but gpuObject creation is a bit derivedmesh type
specific (each DM has its own way to calculate vertices needed etc).
2015-02-18 15:35:08 +01:00
0703ba898e Move data copying function from gpu_buffers.c to cdderivedmesh.c (as it
should be, since it's specialized to this derivedmesh type)
2015-02-18 15:19:31 +01:00
9efc674800 Merge branch 'master' into GPU_data_request 2015-02-17 19:02:53 +01:00
d67d29035a Fix some ordering issues, remove leftover glBegin/glEnd 2015-02-09 14:23:58 +01:00
f07ca03185 Initial VBO code for GPU subsurf.
This commit adds a few generalizations to the VBO
code so that modifiers can create and populate their own GPU objects.

The VBO code originally supported CDDerivedMesh only. The design moves slightly
towards the viewport refactor where the rendering system requests data from the
modifiers.

In this commit only basic support for vertices and normals is provided and
some features from blender's VBO system, suchs as mapping to original faces,
unique element indices for vertices and loose vertex/edge support are missing.
Also, the quick navigation feature of the subsurf modifier won't be supported
for now.

What we do have is full support for solid shading with multiple materials,
flat/smooth shading and a big performance boost.
2015-02-09 14:19:03 +01:00
2301 changed files with 53539 additions and 113137 deletions

View File

@@ -53,9 +53,7 @@ if(NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
endif()
if(NOT EXECUTABLE_OUTPUT_PATH)
set(FIRST_RUN TRUE)
else()
set(FIRST_RUN FALSE)
set(FIRST_RUN "TRUE")
endif()
# this starts out unset
@@ -73,6 +71,7 @@ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE NDEBU
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL NDEBUG)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO NDEBUG)
#-----------------------------------------------------------------------------
# Set policy
@@ -130,7 +129,7 @@ macro(option_defaults_init)
set(${_var} ON)
list(APPEND _init_vars "${_var}")
endforeach()
unset(_var)
unset(_INC)
endmacro()
# remove from namespace
@@ -158,30 +157,25 @@ option_defaults_init(
_init_SDL
_init_FFTW3
_init_GAMEENGINE
_init_OPENSUBDIV
)
# customize...
if (UNIX AND NOT APPLE)
if(UNIX AND NOT APPLE)
# some of these libraries are problematic on Linux
# disable less important dependencies by default
set(_init_BUILDINFO OFF)
set(_init_CODEC_FFMPEG OFF)
set(_init_CYCLES_OSL OFF)
set(_init_IMAGE_OPENEXR OFF)
set(_init_IMAGE_REDCODE OFF)
set(_init_INPUT_NDOF OFF)
set(_init_JACK OFF)
set(_init_LIBMV_SCHUR_SPECIALIZATION OFF)
set(_init_OPENCOLLADA OFF)
set(_init_OPENCOLORIO OFF)
set(_init_SDL OFF)
set(_init_FFTW3 OFF)
set(_init_OPENSUBDIV OFF)
elseif(WIN32)
set(_init_JACK OFF)
elseif(APPLE)
set(_init_INPUT_NDOF OFF)
set(_init_JACK OFF)
set(_init_OPENSUBDIV OFF)
set(_init_GAMEENGINE OFF)
endif()
@@ -203,6 +197,7 @@ option(WITH_PYTHON "Enable Embedded Python API (only disable for develop
option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON)
mark_as_advanced(WITH_PYTHON) # dont want people disabling this unless they really know what they are doing.
mark_as_advanced(WITH_PYTHON_SECURITY) # some distributions see this as a security issue, rather than have them patch it, make a build option.
set(WITH_PYTHON_SECURITY ON CACHE BOOL "ON" FORCE) # temp force on.
option(WITH_PYTHON_SAFETY "Enable internal API error checking to track invalid data to prevent crash on access (at the expense of some effeciency, only enable for development)." OFF)
mark_as_advanced(WITH_PYTHON_SAFETY)
@@ -226,15 +221,7 @@ mark_as_advanced(WITH_SYSTEM_BULLET)
option(WITH_GAMEENGINE "Enable Game Engine" ${_init_GAMEENGINE})
option(WITH_PLAYER "Build Player" OFF)
option(WITH_OPENCOLORIO "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
# Compositor
option(WITH_COMPOSITOR "Enable the tile based nodal compositor" ON)
option(WITH_COMPOSITOR_WERROR "Treat warnings as errors in compositor code" OFF)
mark_as_advanced(WITH_COMPOSITOR_WERROR)
option(WITH_OPENSUBDIV "Enable OpenSubdiv for surface subdivision" _init_OPENSUBDIV)
option(WITH_SUBSURF_WERROR "Treat warnings as errors in subsurf code" OFF)
mark_as_advanced(WITH_COMPOSITOR_WERROR)
option(WITH_COMPOSITOR "Enable the tile based nodal compositor" ON)
# GHOST Windowing Library Options
option(WITH_GHOST_DEBUG "Enable debugging output for the GHOST library" OFF)
@@ -252,13 +239,7 @@ option(WITH_HEADLESS "Build without graphical support (renderfarm, server m
mark_as_advanced(WITH_HEADLESS)
option(WITH_AUDASPACE "Build with blenders audio library (only disable if you know what you're doing!)" ON)
option(WITH_SYSTEM_AUDASPACE "Build with external audaspace library installed on the system (only enable if you know what you're doing!)" OFF)
mark_as_advanced(WITH_AUDASPACE)
mark_as_advanced(WITH_SYSTEM_AUDASPACE)
if(NOT WITH_AUDASPACE)
set(WITH_SYSTEM_AUDASPACE OFF)
endif()
option(WITH_OPENMP "Enable OpenMP (has to be supported by the compiler)" ON)
@@ -337,11 +318,9 @@ if(UNIX AND NOT APPLE)
endif()
# Camera/motion tracking
option(WITH_LIBMV "Enable Libmv structure from motion library" ON)
option(WITH_LIBMV "Enable libmv structure from motion library" ON)
option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ${_init_LIBMV_SCHUR_SPECIALIZATION})
option(WITH_LIBMV_WERROR "Treat warnings as errors in Libmv (and Blender's motion tracking) code")
mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
mark_as_advanced(WITH_LIBMV_WERROR)
# Freestyle
option(WITH_FREESTYLE "Enable Freestyle (advanced edges rendering)" ON)
@@ -375,20 +354,18 @@ if(UNIX AND NOT APPLE)
endif()
# Cycles
option(WITH_CYCLES "Enable Cycles Render Engine" ON)
option(WITH_CYCLES_STANDALONE "Build Cycles standalone application" OFF)
option(WITH_CYCLES_STANDALONE_GUI "Build Cycles standalone with GUI" OFF)
option(WITH_CYCLES "Enable cycles Render Engine" ON)
option(WITH_CYCLES_STANDALONE "Build cycles standalone application" OFF)
option(WITH_CYCLES_STANDALONE_GUI "Build cycles standalone with GUI" OFF)
option(WITH_CYCLES_OSL "Build Cycles with OSL support" ${_init_CYCLES_OSL})
option(WITH_CYCLES_CUDA_BINARIES "Build Cycles CUDA binaries" OFF)
option(WITH_CYCLES_CUDA_BINARIES "Build cycles CUDA binaries" OFF)
set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_50 sm_52 CACHE STRING "CUDA architectures to build binaries for")
mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
unset(PLATFORM_DEFAULT)
option(WITH_CYCLES_LOGGING "Build Cycles with logging support" ON)
option(WITH_CYCLES_DEBUG "Build Cycles with extra debug capabilities" OFF)
option(WITH_CYCLES_WERROR "Treat warnings as errors in Cycles code" OFF)
option(WITH_CYCLES_LOGGING "Build cycles with logging support" ON)
option(WITH_CYCLES_DEBUG "Build cycles with extra debug capabilities" OFF)
mark_as_advanced(WITH_CYCLES_LOGGING)
mark_as_advanced(WITH_CYCLES_DEBUG)
mark_as_advanced(WITH_CYCLES_WERROR)
# LLVM
option(WITH_LLVM "Use LLVM" OFF)
@@ -418,6 +395,7 @@ option(WITH_BOOST "Enable features depending on boost" ON)
# Unit testsing
option(WITH_GTESTS "Enable GTest unit testing" OFF)
option(WITH_TESTS_PERFORMANCE "Enable performance tests" OFF)
# Documentation
@@ -434,6 +412,7 @@ option(WITH_GL_EGL "Use the EGL OpenGL system library instead of th
option(WITH_GL_PROFILE_COMPAT "Support using the OpenGL 'compatibility' profile. (deprecated)" ON )
option(WITH_GL_PROFILE_CORE "Support using the OpenGL 3.2+ 'core' profile." OFF)
option(WITH_GL_PROFILE_ES20 "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)" OFF)
option(WITH_GPU_DEBUG "Create a debug OpenGL context (allows inserting custom messages and getting notifications for bad GL use)" OFF)
mark_as_advanced(
WITH_GLEW_MX
@@ -442,6 +421,7 @@ mark_as_advanced(
WITH_GL_PROFILE_COMPAT
WITH_GL_PROFILE_CORE
WITH_GL_PROFILE_ES20
WITH_GPU_DEBUG
)
if(WITH_GL_PROFILE_COMPAT)
@@ -469,10 +449,6 @@ endif()
option(WITH_CPP11 "Build with C++11 standard enabled, for development use only!" OFF)
mark_as_advanced(WITH_CPP11)
# Dependency graph
option(WITH_LEGACY_DEPSGRAPH "Build Blender with legacy dependency graph" ON)
mark_as_advanced(WITH_LEGACY_DEPSGRAPH)
# avoid using again
option_defaults_clear()
@@ -511,11 +487,7 @@ if(APPLE)
endif()
execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
if(${MAC_SYS} MATCHES 15)
set(OSX_SYSTEM 10.11)
# throw an error here, older cmake cannot handle 2 digit subversion!
cmake_minimum_required(VERSION 3.0.0)
elseif(${MAC_SYS} MATCHES 14)
if(${MAC_SYS} MATCHES 14)
set(OSX_SYSTEM 10.10)
# throw an error here, older cmake cannot handle 2 digit subversion!
cmake_minimum_required(VERSION 3.0.0)
@@ -532,11 +504,13 @@ if(APPLE)
else()
set(OSX_SYSTEM unsupported)
endif()
message(STATUS "Detected system-version: " ${OSX_SYSTEM})
# workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not take xcode-select path into accout
# but would always look into /Applications/Xcode.app while dev versions are named Xcode<version>-DP<preview_number>
execute_process(COMMAND xcode-select --print-path OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "/Contents/Developer" "" XCODE_BUNDLE ${XCODE_CHECK}) # truncate to bundlepath in any case
message(STATUS "Xcode-bundle : " ${XCODE_BUNDLE})
if(${CMAKE_GENERATOR} MATCHES "Xcode")
@@ -564,8 +538,8 @@ if(APPLE)
string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
unset(XCODE_VERS_BUILD_NR)
endif()
message(STATUS "Detected OS X ${OSX_SYSTEM} and Xcode ${XCODE_VERSION} at ${XCODE_BUNDLE}")
message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
if(${XCODE_VERSION} VERSION_LESS 4.3)
set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE) # use guaranteed existing sdk
@@ -678,13 +652,6 @@ endif()
# auto enable openimageio for cycles
if(WITH_CYCLES)
set(WITH_OPENIMAGEIO ON)
# auto enable llvm for cycles_osl
if(WITH_CYCLES_OSL)
set(WITH_LLVM ON CACHE BOOL "" FORCE)
endif()
else()
set(WITH_CYCLES_OSL OFF)
endif()
# auto enable openimageio linking dependencies
@@ -693,6 +660,11 @@ if(WITH_OPENIMAGEIO)
set(WITH_IMAGE_TIFF ON)
endif()
# auto enable llvm for cycles_osl
if(WITH_CYCLES_OSL)
set(WITH_LLVM ON CACHE BOOL "" FORCE)
endif()
# don't store paths to libs for portable distribution
if(WITH_INSTALL_PORTABLE)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
@@ -719,34 +691,6 @@ if(HAVE_STDBOOL_H)
add_definitions(-DHAVE_STDBOOL_H)
endif()
if(WITH_AUDASPACE)
if(WITH_SYSTEM_AUDASPACE)
set(AUDASPACE_DEFINITIONS
-DWITH_AUDASPACE
-DWITH_SYSTEM_AUDASPACE
"-DAUD_DEVICE_H=<AUD_Device.h>"
"-DAUD_SPECIAL_H=<AUD_Special.h>"
"-DAUD_SOUND_H=<AUD_Sound.h>"
"-DAUD_HANDLE_H=<AUD_Handle.h>"
"-DAUD_SEQUENCE_H=<AUD_Sequence.h>"
"-DAUD_TYPES_H=<AUD_Types.h>"
"-DAUD_PYTHON_H=<python/PyAPI.h>"
)
else()
set(AUDASPACE_C_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/intern/audaspace/intern")
set(AUDASPACE_PY_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/intern/audaspace/intern")
set(AUDASPACE_DEFINITIONS
-DWITH_AUDASPACE
"-DAUD_DEVICE_H=<AUD_C-API.h>"
"-DAUD_SPECIAL_H=<AUD_C-API.h>"
"-DAUD_SOUND_H=<AUD_C-API.h>"
"-DAUD_HANDLE_H=<AUD_C-API.h>"
"-DAUD_SEQUENCE_H=<AUD_C-API.h>"
"-DAUD_TYPES_H=<AUD_Space.h>"
)
endif()
endif()
#-----------------------------------------------------------------------------
# Check for valid directories
# ... a partial checkout may cause this.
@@ -848,14 +792,6 @@ if(WITH_X11)
endif()
# ----------------------------------------------------------------------------
# Main Platform Checks
#
# - UNIX
# - WIN32
# - APPLE
if(UNIX AND NOT APPLE)
macro(find_package_wrapper)
if(WITH_STATIC_LIBS)
@@ -924,13 +860,6 @@ if(UNIX AND NOT APPLE)
endif()
# Audio IO
if(WITH_SYSTEM_AUDASPACE)
find_package_wrapper(Audaspace)
if(NOT AUDASPACE_FOUND OR NOT AUDASPACE_C_FOUND)
message(FATAL_ERROR "Audaspace external library not found!")
endif()
endif()
if(WITH_OPENAL)
find_package_wrapper(OpenAL)
if(NOT OPENAL_FOUND)
@@ -1131,9 +1060,9 @@ if(UNIX AND NOT APPLE)
endif()
if(WITH_LLVM)
find_package_wrapper(LLVM)
find_package_wrapper(LLVM)
if(NOT LLVM_FOUND)
if(NOT LLVM_FOUND)
set(WITH_LLVM OFF)
message(STATUS "LLVM not found")
endif()
@@ -1144,18 +1073,6 @@ if(UNIX AND NOT APPLE)
set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script='${CMAKE_SOURCE_DIR}/source/creator/blender.map'")
endif()
if(WITH_OPENSUBDIV)
find_package_wrapper(OpenSubdiv)
set(OPENSUBDIV_LIBRARIES ${OPENSUBDIV_LIBRARIES})
set(OPENSUBDIV_LIBPATH) # TODO, remove and reference the absolute path everywhere
if(NOT OPENSUBDIV_FOUND)
set(WITH_OPENSUBDIV OFF)
message(STATUS "OpenSubdiv not found")
endif()
endif()
# OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
list(APPEND PLATFORM_LINKLIBS -lutil -lc -lm)
@@ -1193,12 +1110,12 @@ if(UNIX AND NOT APPLE)
execute_process(
COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version
ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
if("${LD_VERSION}" MATCHES "GNU gold")
if ("${LD_VERSION}" MATCHES "GNU gold")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=gold")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold")
else()
message(STATUS "GNU gold linker isn't available, using the default system linker.")
endif()
else ()
message(INFO "GNU gold linker isn't available, using the default system linker.")
endif ()
unset(LD_VERSION)
# CLang is the same as GCC for now.
@@ -1576,13 +1493,6 @@ elseif(WIN32)
)
endif()
if(WITH_OPENSUBDIV)
set(OPENSUBDIV_INCLUDE_DIR ${LIBDIR}/opensubdiv/include)
set(OPENSUBDIV_LIBPATH ${LIBDIR}/opensubdiv/lib)
set(OPENSUBDIV_LIBRARIES ${OPENSUBDIV_LIBPATH}/osdCPU.lib ${OPENSUBDIV_LIBPATH}/osdGPU.lib)
find_package(OpenSubdiv)
endif()
if(WITH_SDL)
set(SDL ${LIBDIR}/sdl)
set(SDL_INCLUDE_DIR ${SDL}/include)
@@ -1590,16 +1500,6 @@ elseif(WIN32)
set(SDL_LIBPATH ${SDL}/lib)
endif()
# Audio IO
if(WITH_SYSTEM_AUDASPACE)
set(AUDASPACE_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
set(AUDASPACE_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace.lib)
set(AUDASPACE_C_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
set(AUDASPACE_C_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-c.lib)
set(AUDASPACE_PY_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
set(AUDASPACE_PY_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-py.lib)
endif()
# used in many places so include globally, like OpenGL
blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
@@ -1919,17 +1819,6 @@ elseif(APPLE)
endif()
endif()
if(WITH_OPENSUBDIV)
set(OPENSUBDIV ${LIBDIR}/opensubdiv)
set(OPENSUBDIV_LIBPATH ${OPENSUBDIV}/lib)
find_library(OSL_LIB_UTIL NAMES osdutil PATHS ${OPENSUBDIV_LIBPATH})
find_library(OSL_LIB_CPU NAMES osdCPU PATHS ${OPENSUBDIV_LIBPATH})
find_library(OSL_LIB_GPU NAMES osdGPU PATHS ${OPENSUBDIV_LIBPATH})
set(OPENSUBDIV_INCLUDE_DIR ${OPENSUBDIV}/include)
set(OPENSUBDIV_INCLUDE_DIRS ${OPENSUBDIV_INCLUDE_DIR})
list(APPEND OPENSUBDIV_LIBRARIES ${OSL_LIB_UTIL} ${OSL_LIB_CPU} ${OSL_LIB_GPU})
endif()
if(WITH_JACK)
find_library(JACK_FRAMEWORK
NAMES jackmp
@@ -1953,14 +1842,14 @@ elseif(APPLE)
if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
# normally cached but not since we include them with blender
set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
# set(PYTHON_EXECUTABLE "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
# set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
# set(PYTHON_LINKFLAGS "-u _PyMac_Error") # won't build with this enabled
else()
# module must be compiled against Python framework
set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
set(PYTHON_EXECUTABLE "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
#set(PYTHON_LIBRARY python${PYTHON_VERSION})
set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
#set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python") # won't build with this enabled
@@ -2322,21 +2211,9 @@ endif()
if(WITH_IMAGE_OPENJPEG)
if(WITH_SYSTEM_OPENJPEG)
# dealt with above
set(OPENJPEG_DEFINES "")
else()
set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
set(OPENJPEG_DEFINES "-DOPJ_STATIC")
set(OPENJPEG_LIBRARIES "extern_openjpeg")
endif()
# Special handling of Windows platform where openjpeg is always static.
if(WIN32)
set(OPENJPEG_DEFINES "-DOPJ_STATIC")
endif()
endif()
if(WITH_LZO)
if(NOT WITH_SYSTEM_LZO)
set(LZO_LIBRARIES "extern_minilzo")
add_definitions(-DOPJ_STATIC)
endif()
endif()
@@ -2469,6 +2346,10 @@ if(WITH_GL_EGL)
list(APPEND GL_DEFINITIONS -DWITH_EGL)
endif()
if(WITH_GPU_DEBUG)
list(APPEND GL_DEFINITIONS -DWITH_GPU_DEBUG)
endif()
#-----------------------------------------------------------------------------
# Configure OpenMP.
if(WITH_OPENMP)
@@ -2875,29 +2756,25 @@ include(build_files/cmake/packaging.cmake)
# Print Final Configuration
if(FIRST_RUN)
set(_config_msg "\nBlender Configuration\n=====================")
function(info_cfg_option
_setting
)
set(_msg " - ${_setting}")
set(_config_msg "\n* Blender Configuration *")
macro(info_cfg_option
_setting)
set(_msg " * ${_setting}")
string(LENGTH "${_msg}" _len)
while("32" GREATER "${_len}")
set(_msg "${_msg} ")
math(EXPR _len "${_len} + 1")
endwhile()
set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
endfunction()
set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
endmacro()
function(info_cfg_text
_text
)
macro(info_cfg_text
_text)
set(_config_msg "${_config_msg}\n\n ${_text}")
set(_config_msg "${_config_msg}\n\n ${_text}" PARENT_SCOPE)
endfunction()
endmacro()
message(STATUS "C Compiler: \"${CMAKE_C_COMPILER_ID}\"")
message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
@@ -2976,6 +2853,7 @@ if(FIRST_RUN)
info_cfg_option(WITH_GL_PROFILE_COMPAT)
info_cfg_option(WITH_GL_PROFILE_CORE)
info_cfg_option(WITH_GL_PROFILE_ES20)
info_cfg_option(WITH_GPU_DEBUG)
if(WIN32)
info_cfg_option(WITH_GL_ANGLE)
endif()

View File

@@ -43,11 +43,6 @@ ifndef BUILD_DIR
BUILD_DIR:=$(shell dirname "$(BLENDER_DIR)")/build_$(OS_NCASE)
endif
# Allow to use alternative binary (pypy3, etc)
ifndef PYTHON
PYTHON:=python3
endif
# -----------------------------------------------------------------------------
# additional targets for the build configuration
@@ -81,20 +76,18 @@ endif
# -----------------------------------------------------------------------------
# Get the number of cores for threaded build
ifndef NPROCS
NPROCS:=1
ifeq ($(OS), Linux)
NPROCS:=$(shell nproc)
endif
ifeq ($(OS), Darwin)
NPROCS:=$(shell sysctl -a | grep "hw.ncpu" | cut -d" " -f3)
endif
ifeq ($(OS), FreeBSD)
NPROCS:=$(shell sysctl -a | grep "hw.ncpu" | cut -d" " -f2 )
endif
ifeq ($(OS), NetBSD)
NPROCS:=$(shell sysctl -a | grep "hw.ncpu" | cut -d" " -f2 )
endif
NPROCS:=1
ifeq ($(OS), Linux)
NPROCS:=$(shell nproc)
endif
ifeq ($(OS), Darwin)
NPROCS:=$(shell sysctl -a | grep "hw.ncpu" | cut -d" " -f3)
endif
ifeq ($(OS), FreeBSD)
NPROCS:=$(shell sysctl -a | grep "hw.ncpu" | cut -d" " -f2 )
endif
ifeq ($(OS), NetBSD)
NPROCS:=$(shell sysctl -a | grep "hw.ncpu" | cut -d" " -f2 )
endif
@@ -122,14 +115,14 @@ endif
# Build Blender
all: FORCE
@echo
@echo Configuring Blender in \"$(BUILD_DIR)\" ...
@echo Configuring Blender ...
# # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
# # $(CMAKE_CONFIG); \
# # fi
# if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
# $(CMAKE_CONFIG); \
# fi
# # do this always incase of failed initial build, could be smarter here...
@$(CMAKE_CONFIG)
# do this always incase of failed initial build, could be smarter here...
$(CMAKE_CONFIG)
@echo
@echo Building Blender ...
@@ -208,12 +201,6 @@ help: FORCE
@echo " * tgz - create a compressed archive of the source code."
@echo " * update - updates git and all submodules"
@echo ""
@echo "Environment Variables"
@echo " * BUILD_CMAKE_ARGS - arguments passed to CMake."
@echo " * BUILD_DIR - override default build path."
@echo " * PYTHON - use this for the Python command (used for checking tools)."
@echo " * NPROCS - number of processes to use building (auto-detect when omitted)."
@echo ""
@echo "Documentation Targets (not associated with building blender)"
@echo " * doc_py - generate sphinx python api docs"
@echo " * doc_doxy - generate doxygen C/C++ docs"
@@ -223,7 +210,6 @@ help: FORCE
@echo "Information"
@echo " * help - this help message"
@echo " * help_features - show a list of optional features when building"
@echo ""
# -----------------------------------------------------------------------------
# Packages
@@ -247,21 +233,21 @@ test: FORCE
# run pep8 check check on scripts we distribute.
test_pep8: FORCE
$(PYTHON) tests/python/pep8.py > test_pep8.log 2>&1
python3 tests/python/pep8.py > test_pep8.log 2>&1
@echo "written: test_pep8.log"
# run some checks on our cmakefiles.
test_cmake: FORCE
$(PYTHON) build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
python3 build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
@echo "written: test_cmake_consistency.log"
# run deprecation tests, see if we have anything to remove.
test_deprecated: FORCE
$(PYTHON) tests/check_deprecated.py
python3 tests/check_deprecated.py
test_style_c: FORCE
# run our own checks on C/C++ style
PYTHONIOENCODING=utf_8 $(PYTHON) \
PYTHONIOENCODING=utf_8 python3 \
"$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
"$(BLENDER_DIR)/source/blender" \
"$(BLENDER_DIR)/source/creator" \
@@ -270,7 +256,7 @@ test_style_c: FORCE
test_style_c_qtc: FORCE
# run our own checks on C/C++ style
USE_QTC_TASK=1 \
PYTHONIOENCODING=utf_8 $(PYTHON) \
PYTHONIOENCODING=utf_8 python3 \
"$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
"$(BLENDER_DIR)/source/blender" \
"$(BLENDER_DIR)/source/creator" \
@@ -282,7 +268,7 @@ test_style_c_qtc: FORCE
test_style_osl: FORCE
# run our own checks on C/C++ style
PYTHONIOENCODING=utf_8 $(PYTHON) \
PYTHONIOENCODING=utf_8 python3 \
"$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
"$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
"$(BLENDER_DIR)/release/scripts/templates_osl"
@@ -291,7 +277,7 @@ test_style_osl: FORCE
test_style_osl_qtc: FORCE
# run our own checks on C/C++ style
USE_QTC_TASK=1 \
PYTHONIOENCODING=utf_8 $(PYTHON) \
PYTHONIOENCODING=utf_8 python3 \
"$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
"$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
"$(BLENDER_DIR)/release/scripts/templates_osl" \
@@ -304,10 +290,10 @@ test_style_osl_qtc: FORCE
#
project_qtcreator: FORCE
$(PYTHON) build_files/cmake/cmake_qtcreator_project.py "$(BUILD_DIR)"
python3 build_files/cmake/cmake_qtcreator_project.py "$(BUILD_DIR)"
project_netbeans: FORCE
$(PYTHON) build_files/cmake/cmake_netbeans_project.py "$(BUILD_DIR)"
python3 build_files/cmake/cmake_netbeans_project.py "$(BUILD_DIR)"
project_eclipse: FORCE
cmake -G"Eclipse CDT4 - Unix Makefiles" -H"$(BLENDER_DIR)" -B"$(BUILD_DIR)"
@@ -320,39 +306,39 @@ project_eclipse: FORCE
check_cppcheck: FORCE
$(CMAKE_CONFIG)
cd "$(BUILD_DIR)" ; \
$(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py" 2> \
python3 "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py" 2> \
"$(BLENDER_DIR)/check_cppcheck.txt"
@echo "written: check_cppcheck.txt"
check_clang_array: FORCE
$(CMAKE_CONFIG)
cd "$(BUILD_DIR)" ; \
$(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_clang_array.py"
python3 "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_clang_array.py"
check_splint: FORCE
$(CMAKE_CONFIG)
cd "$(BUILD_DIR)" ; \
$(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py"
python3 "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py"
check_sparse: FORCE
$(CMAKE_CONFIG)
cd "$(BUILD_DIR)" ; \
$(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py"
python3 "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py"
check_smatch: FORCE
$(CMAKE_CONFIG)
cd "$(BUILD_DIR)" ; \
$(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py"
python3 "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py"
check_spelling_py: FORCE
cd "$(BUILD_DIR)" ; \
PYTHONIOENCODING=utf_8 $(PYTHON) \
PYTHONIOENCODING=utf_8 python3 \
"$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
"$(BLENDER_DIR)/release/scripts"
check_spelling_c: FORCE
cd "$(BUILD_DIR)" ; \
PYTHONIOENCODING=utf_8 $(PYTHON) \
PYTHONIOENCODING=utf_8 python3 \
"$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
"$(BLENDER_DIR)/source" \
"$(BLENDER_DIR)/intern/cycles" \
@@ -361,7 +347,7 @@ check_spelling_c: FORCE
check_spelling_c_qtc: FORCE
cd "$(BUILD_DIR)" ; USE_QTC_TASK=1 \
PYTHONIOENCODING=utf_8 $(PYTHON) \
PYTHONIOENCODING=utf_8 python3 \
"$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
"$(BLENDER_DIR)/source" \
"$(BLENDER_DIR)/intern/cycles" \
@@ -372,7 +358,7 @@ check_spelling_c_qtc: FORCE
check_spelling_osl: FORCE
cd "$(BUILD_DIR)" ;\
PYTHONIOENCODING=utf_8 $(PYTHON) \
PYTHONIOENCODING=utf_8 python3 \
"$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
"$(BLENDER_DIR)/intern/cycles/kernel/shaders"
@@ -418,10 +404,10 @@ doc_dna: FORCE
@echo "docs written into: '$(BLENDER_DIR)/doc/blender_file_format/dna.html'"
doc_man: FORCE
$(PYTHON) doc/manpage/blender.1.py "$(BUILD_DIR)/bin/blender"
python3 doc/manpage/blender.1.py "$(BUILD_DIR)/bin/blender"
help_features: FORCE
@$(PYTHON) -c \
@python3 -c \
"import re; \
print('\n'.join([ \
w for l in open('"$(BLENDER_DIR)"/CMakeLists.txt', 'r').readlines() \

View File

@@ -331,10 +331,7 @@ if env['OURPLATFORM']=='darwin':
print B.bc.OKGREEN + "Available SDK's: \n" + B.bc.ENDC + MACOSX_SDK_CHECK.replace('\t', '')
if env['MACOSX_SDK'] == '': # no set sdk, choosing best one found
if 'OS X 10.11' in MACOSX_SDK_CHECK:
env['MACOSX_DEPLOYMENT_TARGET'] = '10.6'
env['MACOSX_SDK']='/Developer/SDKs/MacOSX10.11.sdk'
elif 'OS X 10.10' in MACOSX_SDK_CHECK:
if 'OS X 10.10' in MACOSX_SDK_CHECK:
env['MACOSX_DEPLOYMENT_TARGET'] = '10.6'
env['MACOSX_SDK']='/Developer/SDKs/MacOSX10.10.sdk'
elif 'OS X 10.9' in MACOSX_SDK_CHECK:
@@ -473,14 +470,6 @@ if env['OURPLATFORM']=='darwin':
################### End Automatic configuration for OSX ##################
#############################################################################
if env['OURPLATFORM'] == 'linux' and not env['C_COMPILER_ID']:
command = ["%s"%env['CC'], "--version"]
line = btools.get_command_output(command)
if line.startswith('gcc'):
env['C_COMPILER_ID'] = 'gcc'
elif 'clang' in line[0]:
env['C_COMPILER_ID'] = 'clang'
if env['WITH_BF_OPENMP'] == 1:
if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
env['CCFLAGS'].append('/openmp')
@@ -517,10 +506,6 @@ if env['WITH_BF_STATICCXX']:
else:
print '\tcould not remove stdc++ library from LLIBS, WITH_BF_STATICCXX may not work for your platform'
# audaspace is needed for the game engine
if not env['WITH_BF_AUDASPACE']:
env['WITH_BF_GAMEENGINE'] = False
# check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
if 'blenderplayer' in B.targets:
env['WITH_BF_PLAYER'] = True
@@ -547,25 +532,13 @@ else:
env['CPPFLAGS'].append('-D__LITTLE_ENDIAN__')
# TODO, make optional (as with CMake)
env['CPPFLAGS'].append('-DWITH_AUDASPACE')
env['CPPFLAGS'].append('-DWITH_AVI')
env['CPPFLAGS'].append('-DWITH_OPENNL')
if env['OURPLATFORM'] not in ('win32-vc', 'win64-vc'):
env['CPPFLAGS'].append('-DHAVE_STDBOOL_H')
# Audaspace
if env['WITH_BF_AUDASPACE']:
env['BF_AUDASPACE_C_INC'] = '#intern/audaspace/intern'
env['BF_AUDASPACE_PY_INC'] = '#intern/audaspace/intern'
env['BF_AUDASPACE_DEF'] = ['WITH_AUDASPACE']
env['BF_AUDASPACE_DEF'].append('AUD_DEVICE_H="<AUD_C-API.h>"')
env['BF_AUDASPACE_DEF'].append('AUD_SPECIAL_H="<AUD_C-API.h>"')
env['BF_AUDASPACE_DEF'].append('AUD_SOUND_H="<AUD_C-API.h>"')
env['BF_AUDASPACE_DEF'].append('AUD_HANDLE_H="<AUD_C-API.h>"')
env['BF_AUDASPACE_DEF'].append('AUD_SEQUENCE_H="<AUD_C-API.h>"')
env['BF_AUDASPACE_DEF'].append('AUD_TYPES_H="<AUD_Space.h>"')
# OpenGL
if env['WITH_BF_GL_PROFILE_COMPAT']:
@@ -785,8 +758,6 @@ if B.targets != ['cudakernels']:
data_to_c_simple("release/datafiles/preview_cycles.blend")
# --- glsl ---
data_to_c_simple("source/blender/gpu/shaders/gpu_shader_geometry.glsl")
data_to_c_simple("source/blender/gpu/shaders/gpu_program_smoke_frag.glsl")
data_to_c_simple("source/blender/gpu/shaders/gpu_program_smoke_color_frag.glsl")
@@ -810,7 +781,6 @@ if B.targets != ['cudakernels']:
data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fx_depth_resolve.glsl")
data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fx_vert.glsl")
data_to_c_simple("intern/opencolorio/gpu_shader_display_transform.glsl")
data_to_c_simple("intern/opensubdiv/gpu_shader_opensubd_display.glsl")
# --- blender ---
data_to_c_simple("release/datafiles/bfont.pfb")
@@ -1050,16 +1020,14 @@ if env['OURPLATFORM']!='darwin':
dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'kernel')
source=os.listdir('intern/cycles/kernel')
if '__pycache__' in source: source.remove('__pycache__')
source.remove('kernel.cpp')
source.remove('CMakeLists.txt')
source.remove('SConscript')
source.remove('svm')
source.remove('closure')
source.remove('geom')
source.remove('shaders')
source.remove('osl')
source.remove('split')
source=['intern/cycles/kernel/'+s for s in source]
source.append('intern/cycles/util/util_atomic.h')
source.append('intern/cycles/util/util_color.h')
source.append('intern/cycles/util/util_half.h')
source.append('intern/cycles/util/util_math.h')
@@ -1085,12 +1053,6 @@ if env['OURPLATFORM']!='darwin':
if '__pycache__' in source: source.remove('__pycache__')
source=['intern/cycles/kernel/geom/'+s for s in source]
scriptinstall.append(env.Install(dir=dir,source=source))
# split
dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'kernel', 'split')
source=os.listdir('intern/cycles/kernel/split')
if '__pycache__' in source: source.remove('__pycache__')
source=['intern/cycles/kernel/split/'+s for s in source]
scriptinstall.append(env.Install(dir=dir,source=source))
# licenses
dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'license')
@@ -1322,15 +1284,6 @@ if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc', 'linuxcross'):
windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
allinstall += windlls
# TODO(sergey): For unti we've got better way to deal with python binary
if env['WITH_BF_PYTHON']:
py_target = os.path.join(env['BF_INSTALLDIR'], VERSION, 'python', 'bin')
if env['BF_DEBUG']:
allinstall += env.Install(dir=py_target, source = ['${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll'])
else:
allinstall += env.Install(dir=py_target, source = ['${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}.dll'])
if env['OURPLATFORM'] == 'win64-mingw':
dllsources = []

View File

@@ -27,16 +27,13 @@ getopt \
-o s:i:t:h \
--long source:,install:,tmp:,info:,threads:,help,no-sudo,with-all,with-opencollada,\
ver-ocio:,ver-oiio:,ver-llvm:,ver-osl:,\
force-all,force-python,force-numpy,force-boost,force-ocio,force-oiio,force-llvm,force-osl,force-osd,\
force-ffmpeg,force-opencollada,\
skip-python,skip-numpy,skip-boost,skip-ocio,skip-openexr,skip-oiio,skip-llvm,skip-osl,skip-osd,\
skip-ffmpeg,skip-opencollada,\
force-all,force-python,force-numpy,force-boost,force-ocio,force-oiio,force-llvm,force-osl,force-opencollada,\
force-ffmpeg,\
skip-python,skip-numpy,skip-boost,skip-ocio,skip-openexr,skip-oiio,skip-llvm,skip-osl,skip-ffmpeg,skip-opencollada,\
required-numpy: \
-- "$@" \
)
COMMANDLINE=$@
DISTRO=""
RPM=""
SRC="$HOME/src/blender-deps"
@@ -44,7 +41,6 @@ INST="/opt/lib"
TMP="/tmp"
CWD=$PWD
INFO_PATH=$CWD
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# Do not install some optional, potentially conflicting libs by default...
WITH_ALL=false
@@ -142,9 +138,6 @@ ARGUMENTS_INFO="\"COMMAND LINE ARGUMENTS:
--force-osl
Force the rebuild of OpenShadingLanguage.
--force-osd
Force the rebuild of OpenSubdiv.
--force-opencollada
Force the rebuild of OpenCOLLADA.
@@ -181,9 +174,6 @@ ARGUMENTS_INFO="\"COMMAND LINE ARGUMENTS:
--skip-osl
Unconditionally skip OpenShadingLanguage installation/building.
--skip-osd
Unconditionally skip OpenSubdiv installation/building.
--skip-opencollada
Unconditionally skip OpenCOLLADA installation/building.
@@ -243,12 +233,6 @@ OSL_VERSION_MIN=$OSL_VERSION
OSL_FORCE_REBUILD=false
OSL_SKIP=false
# OpenSubdiv needs to be compiled for now
OSD_VERSION="3.0.2"
OSD_VERSION_MIN=$OSD_VERSION
OSD_FORCE_REBUILD=false
OSD_SKIP=false
# Version??
OPENCOLLADA_VERSION="1.3"
OPENCOLLADA_FORCE_REBUILD=false
@@ -391,11 +375,6 @@ while true; do
OSL_VERSION_MIN=$OSL_VERSION
shift; shift; continue
;;
--ver-osd)
OSD_VERSION="$2"
OSD_VERSION_MIN=$OSD_VERSION
shift; shift; continue
;;
--force-all)
PYTHON_FORCE_REBUILD=true
NUMPY_FORCE_REBUILD=true
@@ -405,7 +384,6 @@ while true; do
OIIO_FORCE_REBUILD=true
LLVM_FORCE_REBUILD=true
OSL_FORCE_REBUILD=true
OSD_FORCE_REBUILD=true
OPENCOLLADA_FORCE_REBUILD=true
FFMPEG_FORCE_REBUILD=true
shift; continue
@@ -439,9 +417,6 @@ while true; do
--force-osl)
OSL_FORCE_REBUILD=true; shift; continue
;;
--force-osd)
OSD_FORCE_REBUILD=true; shift; continue
;;
--force-opencollada)
OPENCOLLADA_FORCE_REBUILD=true; shift; continue
;;
@@ -472,9 +447,6 @@ while true; do
--skip-osl)
OSL_SKIP=true; shift; continue
;;
--skip-osd)
OSD_SKIP=true; shift; continue
;;
--skip-opencollada)
OPENCOLLADA_SKIP=true; shift; continue
;;
@@ -537,14 +509,6 @@ OSL_SOURCE_REPO=( "https://github.com/Nazg-Gul/OpenShadingLanguage.git" )
OSL_SOURCE_REPO_UID="22ee5ea298fd215430dfbd160b5aefd507f06db0"
OSL_SOURCE_REPO_BRANCH="blender-fixes"
OSD_USE_REPO=true
# Script foo to make the version string compliant with the archive name:
# ${Varname//SearchForThisChar/ReplaceWithThisChar}
OSD_SOURCE=( "https://github.com/PixarAnimationStudios/OpenSubdiv/archive/v${OSD_VERSION//./_}.tar.gz" )
OSD_SOURCE_REPO=( "https://github.com/PixarAnimationStudios/OpenSubdiv.git" )
OSD_SOURCE_REPO_UID="404659fffa659da075d1c9416e4fc939139a84ee"
OSD_SOURCE_REPO_BRANCH="dev"
OPENCOLLADA_SOURCE=( "https://github.com/KhronosGroup/OpenCOLLADA.git" )
OPENCOLLADA_REPO_UID="3335ac164e68b2512a40914b14c74db260e6ff7d"
FFMPEG_SOURCE=( "http://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.bz2" )
@@ -1379,7 +1343,19 @@ compile_LLVM() {
cd $_src
# XXX Ugly patching hack!
patch -p1 -i "$SCRIPT_DIR/install_deps_patches/llvm.patch"
cat << EOF | patch -p1
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,7 +13,7 @@
set(LLVM_VERSION_MAJOR 3)
set(LLVM_VERSION_MINOR 1)
-set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}svn")
+set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
EOF
cd $CWD
@@ -1398,7 +1374,7 @@ compile_LLVM() {
cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
cmake_d="$cmake_d -D LLVM_ENABLE_FFI=ON"
cmake_d="$cmake_d -D LLVM_TARGETS_TO_BUILD=X86"
cmake_d="$cmake_d -D LLVM_ENABLE_TERMINFO=OFF"
cmake_d="$cmake_d -D -DLLVM_ENABLE_TERMINFO=OFF"
if [ -d $_FFI_INCLUDE_DIR ]; then
cmake_d="$cmake_d -D FFI_INCLUDE_DIR=$_FFI_INCLUDE_DIR"
@@ -1449,10 +1425,10 @@ compile_OSL() {
# Clean install if needed!
magic_compile_check osl-$OSL_VERSION $osl_magic
if [ $? -eq 1 -o $OSL_FORCE_REBUILD == true ]; then
#~ if [ $? -eq 1 -o $OSL_FORCE_REBUILD == true ]; then
#~ rm -Rf $_src # XXX Radical, but not easy to change remote repo fully automatically
clean_OSL
fi
#~ clean_OSL
#~ fi
if [ ! -d $_inst ]; then
INFO "Building OpenShadingLanguage-$OSL_VERSION"
@@ -1481,9 +1457,6 @@ compile_OSL() {
# Stick to same rev as windows' libs...
git checkout $OSL_SOURCE_REPO_UID
git reset --hard
# XXX Ugly patching hack!
patch -p1 -i "$SCRIPT_DIR/install_deps_patches/osl.patch"
fi
# Always refresh the whole build!
@@ -1525,9 +1498,6 @@ compile_OSL() {
fi
fi
#~ cmake_d="$cmake_d -D CMAKE_EXPORT_COMPILE_COMMANDS=ON"
#~ cmake_d="$cmake_d -D CMAKE_VERBOSE_MAKEFILE=ON"
cmake $cmake_d ..
make -j$THREADS && make install
@@ -1552,99 +1522,6 @@ compile_OSL() {
run_ldconfig "osl"
}
#### Build OSD ####
_init_osd() {
_src=$SRC/OpenSubdiv-$OSD_VERSION
_git=true
_inst=$INST/osd-$OSD_VERSION
_inst_shortcut=$INST/osd
}
clean_OSD() {
_init_osd
_clean
}
compile_OSD() {
# To be changed each time we make edits that would modify the compiled result!
osd_magic=0
_init_osd
# Clean install if needed!
magic_compile_check osd-$OSD_VERSION $osd_magic
if [ $? -eq 1 -o $OSD_FORCE_REBUILD == true ]; then
clean_OSD
fi
if [ ! -d $_inst ]; then
INFO "Building OpenSubdiv-$OSD_VERSION"
prepare_opt
if [ ! -d $_src ]; then
mkdir -p $SRC
if [ $OSD_USE_REPO == true ]; then
git clone ${OSD_SOURCE_REPO[0]} $_src
else
download OSD_SOURCE[@] "$_src.tar.gz"
INFO "Unpacking OpenSubdiv-$OSD_VERSION"
tar -C $SRC --transform "s,(.*/?)OpenSubdiv-[^/]*(.*),\1OpenSubdiv-$OSD_VERSION\2,x" \
-xf $_src.tar.gz
fi
fi
cd $_src
if [ $OSD_USE_REPO == true ]; then
git remote set-url origin ${OSD_SOURCE_REPO[0]}
# XXX For now, always update from latest repo...
git pull --no-edit -X theirs origin $OSD_SOURCE_REPO_BRANCH
# Stick to same rev as windows' libs...
git checkout $OSD_SOURCE_REPO_UID
git reset --hard
fi
# Always refresh the whole build!
if [ -d build ]; then
rm -rf build
fi
mkdir build
cd build
cmake_d="-D CMAKE_BUILD_TYPE=Release"
cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
# ptex is only needed when nicholas bishop is ready
cmake_d="$cmake_d -D NO_PTEX=1"
cmake_d="$cmake_d -D NO_CLEW=1"
# maya plugin, docs, tutorials, regression tests and examples are not needed
cmake_d="$cmake_d -D NO_MAYA=1 -D NO_DOC=1 -D NO_TUTORIALS=1 -D NO_REGRESSION=1 -DNO_EXAMPLES=1"
cmake $cmake_d ..
make -j$THREADS && make install
make clean
if [ -d $_inst ]; then
_create_inst_shortcut
else
ERROR "OpenSubdiv-$OSD_VERSION failed to compile, exiting"
exit 1
fi
magic_compile_set osd-$OSD_VERSION $osd_magic
cd $CWD
INFO "Done compiling OpenSubdiv-$OSD_VERSION!"
else
INFO "Own OpenSubdiv-$OSD_VERSION is up to date, nothing to do!"
INFO "If you want to force rebuild of this lib, use the --force-osd option."
fi
run_ldconfig "osd"
}
#### Build OpenCOLLADA ####
_init_opencollada() {
_src=$SRC/OpenCOLLADA-$OPENCOLLADA_VERSION
@@ -1936,9 +1813,8 @@ install_DEB() {
THEORA_DEV="libtheora-dev"
_packages="gawk cmake cmake-curses-gui scons build-essential libjpeg-dev libpng-dev \
libfreetype6-dev libx11-dev \
libxcursor-dev libxi-dev wget libsqlite3-dev libxrandr-dev libxinerama-dev \
libbz2-dev libncurses5-dev libssl-dev liblzma-dev libreadline-dev $OPENJPEG_DEV \
libfreetype6-dev libx11-dev libxi-dev wget libsqlite3-dev libbz2-dev \
libncurses5-dev libssl-dev liblzma-dev libreadline-dev $OPENJPEG_DEV \
libopenal-dev libglew-dev libglewmx-dev yasm $THEORA_DEV $VORBIS_DEV $OGG_DEV \
libsdl1.2-dev libfftw3-dev patch bzip2 libxml2-dev libtinyxml-dev"
@@ -2213,20 +2089,6 @@ install_DEB() {
fi
fi
PRINT ""
if $OSD_SKIP; then
WARNING "Skipping OpenSubdiv installation, as requested..."
else
if $have_llvm; then
install_packages_DEB flex bison libtbb-dev
# No package currently!
PRINT ""
compile_OSD
else
WARNING "No LLVM available, cannot build OSD!"
fi
fi
if $WITH_OPENCOLLADA; then
PRINT ""
if $OPENCOLLADA_SKIP; then
@@ -2425,9 +2287,9 @@ install_RPM() {
OGG_DEV="libogg-devel"
THEORA_DEV="libtheora-devel"
_packages="gcc gcc-c++ git make cmake scons libtiff-devel libjpeg-devel\
libpng-devel libX11-devel libXi-devel libXcursor-devel libXrandr-devel libXinerama-devel \
wget ncurses-devel readline-devel $OPENJPEG_DEV openal-soft-devel \
_packages="gcc gcc-c++ make scons libtiff-devel freetype-devel libjpeg-devel\
libpng-devel libX11-devel libXi-devel wget ncurses-devel \
readline-devel $OPENJPEG_DEV openal-soft-devel \
glew-devel yasm $THEORA_DEV $VORBIS_DEV $OGG_DEV patch \
libxml2-devel yaml-cpp-devel tinyxml-devel"
@@ -2439,7 +2301,7 @@ install_RPM() {
if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
OPENEXR_DEV="openexr-devel"
_packages="$_packages freetype-devel libsqlite3x-devel fftw-devel SDL-devel"
_packages="$_packages libsqlite3x-devel fftw-devel SDL-devel"
if $WITH_ALL; then
_packages="$_packages jack-audio-connection-kit-devel"
@@ -2477,7 +2339,7 @@ install_RPM() {
elif [ $RPM = "SUSE" ]; then
OPENEXR_DEV="libopenexr-devel"
_packages="$_packages cmake freetype2-devel sqlite3-devel fftw3-devel libSDL-devel"
_packages="$_packages cmake sqlite3-devel fftw3-devel libSDL-devel"
PRINT ""
install_packages_RPM $_packages
@@ -2533,7 +2395,7 @@ install_RPM() {
if $NUMPY_SKIP; then
WARNING "Skipping NumPy installation, as requested..."
else
check_package_version_ge_RPM python3-numpy $NUMPY_VERSION_MIN
check_package_version_match_RPM python3-numpy $NUMPY_VERSION_MIN
if [ $? -eq 0 ]; then
install_packages_RPM python3-numpy
elif $NUMPY_REQUIRED; then
@@ -2654,7 +2516,7 @@ install_RPM() {
else
if $have_llvm; then
# No package currently!
install_packages_RPM flex bison
install_packages_RPM flex bison git
if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
install_packages_RPM tbb-devel
fi
@@ -2665,29 +2527,12 @@ install_RPM() {
fi
fi
PRINT ""
if $OSD_SKIP; then
WARNING "Skipping OpenSubdiv installation, as requested..."
else
if $have_llvm; then
# No package currently!
install_packages_RPM flex bison
if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
install_packages_RPM tbb-devel
fi
PRINT ""
compile_OSD
else
WARNING "No LLVM available, cannot build OSD!"
fi
fi
if $WITH_OPENCOLLADA; then
PRINT ""
if $OPENCOLLADA_SKIP; then
WARNING "Skipping OpenCOLLADA installation, as requested..."
else
install_packages_RPM pcre-devel
install_packages_RPM pcre-devel git
# Find path to libxml shared lib...
_XML2_LIB=`rpm -ql libxml2-devel | grep -e ".*/libxml2.so"`
# No package...
@@ -2795,8 +2640,7 @@ install_ARCH() {
OGG_DEV="libogg"
THEORA_DEV="libtheora"
_packages="base-devel git scons cmake \
libxi libxcursor libxrandr libxinerama glew libpng libtiff wget openal \
_packages="base-devel scons cmake libxi glew libpng libtiff wget openal \
$OPENJPEG_DEV $VORBIS_DEV $OGG_DEV $THEORA_DEV yasm sdl fftw \
libxml2 yaml-cpp tinyxml"
@@ -2983,7 +2827,7 @@ install_ARCH() {
clean_OSL
else
#XXX Note: will fail to build with LLVM 3.2!
install_packages_ARCH intel-tbb
install_packages_ARCH git intel-tbb
PRINT ""
compile_OSL
fi
@@ -2992,20 +2836,6 @@ install_ARCH() {
fi
fi
PRINT ""
if $OSD_SKIP; then
WARNING "Skipping OpenSubdiv installation, as requested..."
else
if $have_llvm; then
# No package currently? Just build for now!
install_packages_ARCH intel-tbb
PRINT ""
compile_OSD
else
WARNING "No LLVM available, cannot build OSD!"
fi
fi
if $WITH_OPENCOLLADA; then
PRINT ""
if $OPENCOLLADA_SKIP; then
@@ -3016,7 +2846,7 @@ install_ARCH() {
install_packages_ARCH opencollada
clean_OpenCOLLADA
else
install_packages_ARCH pcre
install_packages_ARCH pcre git
PRINT ""
compile_OpenCOLLADA
fi
@@ -3117,10 +2947,6 @@ print_info() {
PRINT "Often, changes in the libs built by this script, or in your distro package, cannot be handled simply, so..."
PRINT ""
PRINT ""
PRINT "Ran with:"
PRINT " install_deps.sh $COMMANDLINE"
PRINT ""
PRINT ""
PRINT "If you're using CMake add this to your configuration flags:"
_buildargs=""
@@ -3185,14 +3011,6 @@ print_info() {
_buildargs="$_buildargs $_1 $_2"
fi
if [ -d $INST/osd ]; then
_1="-D WITH_OPENSUBDIV=ON"
_2="-D OPENSUBDIV_ROOT_DIR=$INST/osd"
PRINT " $_1"
PRINT " $_2"
_buildargs="$_buildargs $_1 $_2"
fi
if $WITH_OPENCOLLADA; then
_1="-D WITH_OPENCOLLADA=ON"
PRINT " $_1"
@@ -3259,13 +3077,6 @@ print_info() {
PRINT "BF_OSL = '$INST/osl'"
fi
if [ "$OSD_SKIP" = false ]; then
PRINT "WITH_BF_OPENSUBDIV = True"
if [ -d $INST/osd ]; then
PRINT "BF_OPENSUBDIV = '$INST/osd'"
fi
fi
if [ "$BOOST_SKIP" = false ]; then
PRINT "WITH_BF_BOOST = True"
if [ -d $INST/boost ]; then
@@ -3312,27 +3123,7 @@ elif [ -f /etc/redhat-release -o /etc/SuSE-release ]; then
DISTRO="RPM"
install_RPM
else
ERROR "Failed to detect distribution type."
PRINT ""
PRINT "Your distribution is not supported by this script, you'll have to install dependencies and"
PRINT "dev packages yourself (list non-exhaustive, but should cover most needs):"
PRINT " * Basics of dev environment (cmake or scons, gcc, svn , git, ...)."
PRINT " * Python$PYTHON_VERSION_MIN, numpy."
PRINT " * libboost$BOOST_VERSION_MIN (locale, filesystem, regex, system, thread, wave)."
PRINT " * libjpeg, libpng, libtiff, libopenjpeg, libopenal."
PRINT " * ffmpeg (with libvorbis, libogg, libtheora, libx264, libmp3lame, libxvidcore, libvpx, ...)."
PRINT " * libx11, libxcursor, libxi, libxrandr, libxinerama (and other libx... as needed)."
PRINT " * libsqlite3, libbz2, libssl, libfftw3, libxml2, libtinyxml, yasm, libyaml-cpp."
PRINT " * libsdl1.2, libglew, libglewmx."
PRINT " * libopencolorio$OCIO_VERSION_MIN, libopenexr$OPENEXR_VERSION_MIN, libopenimageio$OIIO_VERSION_MIN."
PRINT " * llvm-$LLVM_VERSION (with clang)."
PRINT ""
PRINT "Most of up-listed packages are available in recent distributions. The following are likely not,"
PRINT "you'll have to build them (they are all optional, though):"
PRINT " * OpenShadingLanguage (from https://github.com/Nazg-Gul/OpenShadingLanguage.git, branch blender-fixes, commit 22ee5ea298fd215430dfbd160b5aefd507f06db0)."
PRINT " * OpenSubDiv (from https://github.com/PixarAnimationStudios/OpenSubdiv.git, branch dev, commit 404659fffa659da075d1c9416e4fc939139a84ee)."
PRINT " * OpenCollada (from https://github.com/KhronosGroup/OpenCOLLADA.git, branch master, commit 3335ac164e68b2512a40914b14c74db260e6ff7d)."
PRINT ""
ERROR "Failed to detect distribution type"
exit 1
fi

View File

@@ -1,12 +0,0 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,7 +13,7 @@
set(LLVM_VERSION_MAJOR 3)
set(LLVM_VERSION_MINOR 1)
-set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}svn")
+set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

View File

@@ -1,12 +0,0 @@
--- a/src/shaders/CMakeLists.txt
+++ b/src/shaders/CMakeLists.txt
@@ -27,7 +27,7 @@ macro (osl_compile oslsrc objlist headers)
message (STATUS "cmd: ${CMAKE_CURRENT_BINARY_DIR}/../oslc/oslc ${oslsrc}")
endif ()
add_custom_command (OUTPUT ${osofile}
- COMMAND "${CMAKE_CURRENT_BINARY_DIR}/../oslc/oslc" ${oslsrc}
+ COMMAND "${CMAKE_CURRENT_BINARY_DIR}/../oslc/oslc" "-o" ${osofile} ${oslsrc}
MAIN_DEPENDENCY ${oslsrc}
DEPENDS ${${headers}} ${oslsrc} "${CMAKE_CURRENT_BINARY_DIR}/stdosl.h" "${CMAKE_CURRENT_BINARY_DIR}/../oslc/oslc"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

View File

@@ -2,5 +2,4 @@ BF_BUILDDIR = '../blender-build/linux-glibc211-i686'
BF_INSTALLDIR = '../blender-install/linux-glibc211-i686'
BF_NUMJOBS = 1
#BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_20', 'sm_21', 'sm_30', 'sm_35', 'sm_50', 'sm_52']
BF_CYCLES_CUDA_BINARIES_ARCH = []
BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_20', 'sm_21', 'sm_30', 'sm_35', 'sm_50', 'sm_52']

View File

@@ -166,15 +166,6 @@ BF_BOOST_LIBPATH = '${BF_BOOST}/lib'
# Ocean Simulation
WITH_BF_OCEANSIM = True
# OpenSubdiv
WITH_BF_OPENSUBDIV = True
WITH_BF_STATICOPENSUBDIV = True
BF_OPENSUBDIV = '/opt/lib/opensubdiv'
BF_OPENSUBDIV_INC = '${BF_OPENSUBDIV}/include'
BF_OPENSUBDIV_LIB = 'osdCPU osdGPU'
BF_OPENSUBDIV_LIBPATH = '${BF_OPENSUBDIV}/lib'
BF_OPENSUBDIV_LIB_STATIC = '${BF_OPENSUBDIV}/lib/libosdCPU.a ${BF_OPENSUBDIV}/lib/libosdGPU.a'
# Compilation and optimization
BF_DEBUG = False
REL_CCFLAGS = ['-DNDEBUG', '-O2', '-msse', '-msse2'] # C & C++

View File

@@ -166,15 +166,6 @@ BF_BOOST_LIBPATH = '${BF_BOOST}/lib'
# Ocean Simulation
WITH_BF_OCEANSIM = True
# OpenSubdiv
WITH_BF_OPENSUBDIV = True
WITH_BF_STATICOPENSUBDIV = True
BF_OPENSUBDIV = '/opt/lib/opensubdiv'
BF_OPENSUBDIV_INC = '${BF_OPENSUBDIV}/include'
BF_OPENSUBDIV_LIB = 'osdCPU osdGPU'
BF_OPENSUBDIV_LIBPATH = '${BF_OPENSUBDIV}/lib'
BF_OPENSUBDIV_LIB_STATIC = '${BF_OPENSUBDIV}/lib/libosdCPU.a ${BF_OPENSUBDIV}/lib/libosdGPU.a'
# Compilation and optimization
BF_DEBUG = False
REL_CCFLAGS = ['-DNDEBUG', '-O2', '-msse', '-msse2'] # C & C++

View File

@@ -1,5 +1,5 @@
#CC = "../lib/darwin-9.x.universal/clang-omp-3.5/bin/clang"
#CXX = "../lib/darwin-9.x.universal/clang-omp-3.5/bin/clang++"
CC = "../lib/darwin-9.x.universal/clang-omp-3.5/bin/clang"
CXX = "../lib/darwin-9.x.universal/clang-omp-3.5/bin/clang++"
MACOSX_ARCHITECTURE = 'x86_64' # valid archs: ppc, i386, ppc64, x86_64

View File

@@ -4,7 +4,7 @@
# <pep8 compliant>
# List of the branches being built automatically overnight
NIGHT_SCHEDULE_BRANCHES = [None]
NIGHT_SCHEDULE_BRANCHES = [None, "gooseberry"]
# List of the branches available for force build
FORCE_SCHEDULE_BRANCHES = ["master", "gooseberry", "experimental-build"]
@@ -305,12 +305,12 @@ add_builder(c, 'mac_x86_64_10_6_scons', 'darwin-9.x.universal', generic_builder,
add_builder(c, 'mac_i386_10_6_scons', 'darwin-9.x.universal', generic_builder, hour=11)
add_builder(c, 'linux_glibc211_i386_scons', '', generic_builder, hour=1)
add_builder(c, 'linux_glibc211_x86_64_scons', '', generic_builder, hour=2)
#add_builder(c, 'win32_scons_vc2013', 'windows_vc12', generic_builder, hour=1)
#add_builder(c, 'win64_scons_vc2013', 'win64_vc12', generic_builder, hour=2)
add_builder(c, 'win32_scons_vc2013', 'windows_vc12', generic_builder, hour=1)
add_builder(c, 'win64_scons_vc2013', 'win64_vc12', generic_builder, hour=2)
add_builder(c, 'win32_cmake_vc2013', 'windows_vc12', generic_builder, hour=3)
add_builder(c, 'win64_cmake_vc2013', 'win64_vc12', generic_builder, hour=4)
#add_builder(c, 'mingw_win32_scons', 'mingw32', generic_builder, hour=4)
#add_builder(c, 'mingw_win64_scons', 'mingw64', generic_builder, hour=3)
add_builder(c, 'mingw_win64_scons', 'mingw64', generic_builder, hour=3)
#add_builder(c, 'freebsd_i386_cmake', '', generic_builder, hour=1)
#add_builder(c, 'freebsd_x86_64_cmake', '', generic_builder, hour=2)

View File

@@ -124,12 +124,10 @@ else:
directory = 'public_html/download'
try:
filename = os.path.join(directory, packagename)
zf = z.open(package)
f = file(filename, "wb")
f = file(os.path.join(directory, packagename), "wb")
shutil.copyfileobj(zf, f)
os.chmod(filename, 0644)
zf.close()
z.close()

View File

@@ -52,18 +52,12 @@ if 'cmake' in builder:
cmake_options.append(['-G', '"Visual Studio 12 2013"'])
cmake_options.append("-C../blender.git/build_files/cmake/config/blender_full.cmake")
if 'win32' not in builder:
cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=1")
else:
cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=0")
cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=1")
# configure and make
retcode = subprocess.call(['cmake', blender_dir] + cmake_options)
if retcode != 0:
sys.exit(retcode)
if 'win32' in builder:
retcode = subprocess.call(['msbuild', 'INSTALL.vcxproj', '/Property:PlatformToolset=v120_xp', '/p:Configuration=Release'])
elif 'win64' in builder:
if 'win' in builder:
retcode = subprocess.call(['msbuild', 'INSTALL.vcxproj', '/p:Configuration=Release'])
else:
retcode = subprocess.call(['make', '-s', '-j4', 'install'])

View File

@@ -123,26 +123,14 @@ else:
os.remove(f)
retcode = subprocess.call(['cpack', '-G', 'ZIP'])
result_file = [f for f in os.listdir('.') if os.path.isfile(f) and f.endswith('.zip')][0]
# TODO(sergey): Such magic usually happens in SCon's packaging bu we don't have it
# in the CMake yet. For until then we do some magic here.
tokens = result_file.split('-')
blender_version = tokens[1].split('.')
blender_full_version = '.'.join(blender_version[0:2])
git_hash = tokens[2].split('.')[1]
platform = builder.split('_')[0]
builderified_name = 'blender-{}-{}-{}'.format(blender_full_version, git_hash, platform)
if branch != '':
builderified_name = branch + "-" + builderified_name
os.rename(result_file, "{}.zip".format(builderified_name))
os.rename(result_file, "{}.zip".format(builder))
# create zip file
try:
upload_zip = "buildbot_upload.zip"
if os.path.exists(upload_zip):
os.remove(upload_zip)
z = zipfile.ZipFile(upload_zip, "w", compression=zipfile.ZIP_STORED)
z.write("{}.zip".format(builderified_name))
z.write("{}.zip".format(builder))
z.close()
sys.exit(retcode)
except Exception as ex:

View File

@@ -1,113 +0,0 @@
# - Try to find audaspace
# Once done, this will define
#
# AUDASPACE_FOUND - system has audaspace
# AUDASPACE_INCLUDE_DIRS - the audaspace include directories
# AUDASPACE_LIBRARIES - link these to use audaspace
# AUDASPACE_C_FOUND - system has audaspace's C binding
# AUDASPACE_C_INCLUDE_DIRS - the audaspace's C binding include directories
# AUDASPACE_C_LIBRARIES - link these to use audaspace's C binding
# AUDASPACE_PY_FOUND - system has audaspace's python binding
# AUDASPACE_PY_INCLUDE_DIRS - the audaspace's python binding include directories
# AUDASPACE_PY_LIBRARIES - link these to use audaspace's python binding
IF(NOT AUDASPACE_ROOT_DIR AND NOT $ENV{AUDASPACE_ROOT_DIR} STREQUAL "")
SET(AUDASPACE_ROOT_DIR $ENV{AUDASPACE_ROOT_DIR})
ENDIF()
SET(_audaspace_SEARCH_DIRS
${AUDASPACE_ROOT_DIR}
/usr/local
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
)
# Use pkg-config to get hints about paths
FIND_PACKAGE(PkgConfig)
IF(PKG_CONFIG_FOUND)
PKG_CHECK_MODULES(AUDASPACE_PKGCONF audaspace)
ENDIF(PKG_CONFIG_FOUND)
# Include dir
FIND_PATH(AUDASPACE_INCLUDE_DIR
NAMES ISound.h
HINTS ${_audaspace_SEARCH_DIRS}
PATHS ${AUDASPACE_PKGCONF_INCLUDE_DIRS}
PATH_SUFFIXES include/audaspace
)
# Library
FIND_LIBRARY(AUDASPACE_LIBRARY
NAMES audaspace
HINTS ${_audaspace_SEARCH_DIRS}
PATHS ${AUDASPACE_PKGCONF_LIBRARY_DIRS}
PATH_SUFFIXES lib lib64
)
# Include dir
FIND_PATH(AUDASPACE_C_INCLUDE_DIR
NAMES AUD_Sound.h
HINTS ${_audaspace_SEARCH_DIRS}
PATHS ${AUDASPACE_PKGCONF_INCLUDE_DIRS}
PATH_SUFFIXES include/audaspace
)
# Library
FIND_LIBRARY(AUDASPACE_C_LIBRARY
NAMES audaspace-c
HINTS ${_audaspace_SEARCH_DIRS}
PATHS ${AUDASPACE_PKGCONF_LIBRARY_DIRS}
PATH_SUFFIXES lib lib64
)
# Include dir
FIND_PATH(AUDASPACE_PY_INCLUDE_DIR
NAMES python/PyAPI.h
HINTS ${_audaspace_SEARCH_DIRS}
PATHS ${AUDASPACE_PKGCONF_INCLUDE_DIRS}
PATH_SUFFIXES include/audaspace
)
# Library
FIND_LIBRARY(AUDASPACE_PY_LIBRARY
NAMES audaspace-py
HINTS ${_audaspace_SEARCH_DIRS}
PATHS ${AUDASPACE_PKGCONF_LIBRARY_DIRS}
PATH_SUFFIXES lib lib64
)
FIND_PACKAGE(PackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Audaspace DEFAULT_MSG AUDASPACE_LIBRARY AUDASPACE_INCLUDE_DIR)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Audaspace_C DEFAULT_MSG AUDASPACE_C_LIBRARY AUDASPACE_C_INCLUDE_DIR)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Audaspace_Py DEFAULT_MSG AUDASPACE_PY_LIBRARY AUDASPACE_PY_INCLUDE_DIR)
IF(AUDASPACE_FOUND)
SET(AUDASPACE_LIBRARIES ${AUDASPACE_LIBRARY})
SET(AUDASPACE_INCLUDE_DIRS ${AUDASPACE_INCLUDE_DIR})
ENDIF(AUDASPACE_FOUND)
IF(AUDASPACE_C_FOUND)
SET(AUDASPACE_C_LIBRARIES ${AUDASPACE_C_LIBRARY})
SET(AUDASPACE_C_INCLUDE_DIRS ${AUDASPACE_C_INCLUDE_DIR})
ENDIF(AUDASPACE_C_FOUND)
IF(AUDASPACE_PY_FOUND)
SET(AUDASPACE_PY_LIBRARIES ${AUDASPACE_PY_LIBRARY})
SET(AUDASPACE_PY_INCLUDE_DIRS ${AUDASPACE_PY_INCLUDE_DIR})
ENDIF(AUDASPACE_PY_FOUND)
MARK_AS_ADVANCED(
AUDASPACE_LIBRARY
AUDASPACE_LIBRARIES
AUDASPACE_INCLUDE_DIR
AUDASPACE_INCLUDE_DIRS
AUDASPACE_C_LIBRARY
AUDASPACE_C_LIBRARIES
AUDASPACE_C_INCLUDE_DIR
AUDASPACE_C_INCLUDE_DIRS
AUDASPACE_PY_LIBRARY
AUDASPACE_PY_LIBRARIES
AUDASPACE_PY_INCLUDE_DIR
AUDASPACE_PY_INCLUDE_DIRS
)

View File

@@ -59,8 +59,7 @@ FIND_LIBRARY(OPENIMAGEIO_LIBRARY
FIND_FILE(OPENIMAGEIO_IDIFF
NAMES
idiff
HINTS
${OPENIMAGEIO_ROOT_DIR}
${OPENIMAGEIO_ROOT_DIR}
PATH_SUFFIXES
bin
)

View File

@@ -1,111 +0,0 @@
# - Find OpenSubdiv library
# Find the native OpenSubdiv includes and library
# This module defines
# OPENSUBDIV_INCLUDE_DIRS, where to find OpenSubdiv headers, Set when
# OPENSUBDIV_INCLUDE_DIR is found.
# OPENSUBDIV_LIBRARIES, libraries to link against to use OpenSubdiv.
# OPENSUBDIV_ROOT_DIR, the base directory to search for OpenSubdiv.
# This can also be an environment variable.
# OPENSUBDIV_FOUND, if false, do not try to use OpenSubdiv.
#
# also defined, but not for general use are
# OPENSUBDIV_LIBRARY, where to find the OpenSubdiv library.
#=============================================================================
# Copyright 2013 Blender Foundation.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# If OPENSUBDIV_ROOT_DIR was defined in the environment, use it.
IF(NOT OPENSUBDIV_ROOT_DIR AND NOT $ENV{OPENSUBDIV_ROOT_DIR} STREQUAL "")
SET(OPENSUBDIV_ROOT_DIR $ENV{OPENSUBDIV_ROOT_DIR})
ENDIF()
SET(_opensubdiv_FIND_COMPONENTS
osdGPU
osdCPU
)
SET(_opensubdiv_SEARCH_DIRS
${OPENSUBDIV_ROOT_DIR}
/usr/local
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt/lib/opensubdiv
)
FIND_PATH(OPENSUBDIV_INCLUDE_DIR
NAMES
opensubdiv/osd/mesh.h
HINTS
${_opensubdiv_SEARCH_DIRS}
PATH_SUFFIXES
include
)
SET(_opensubdiv_LIBRARIES)
FOREACH(COMPONENT ${_opensubdiv_FIND_COMPONENTS})
STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
FIND_LIBRARY(OPENSUBDIV_${UPPERCOMPONENT}_LIBRARY
NAMES
${COMPONENT}
HINTS
${_opensubdiv_SEARCH_DIRS}
PATH_SUFFIXES
lib64 lib
)
LIST(APPEND _opensubdiv_LIBRARIES "${OPENSUBDIV_${UPPERCOMPONENT}_LIBRARY}")
ENDFOREACH()
MACRO(OPENSUBDIV_CHECK_CONTROLLER
controller_include_file
variable_name)
IF(EXISTS "${OPENSUBDIV_INCLUDE_DIR}/opensubdiv/osd/${controller_include_file}")
SET(${variable_name} TRUE)
ELSE()
SET(${variable_name} FALSE)
ENDIF()
ENDMACRO()
# handle the QUIETLY and REQUIRED arguments and set OPENSUBDIV_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSubdiv DEFAULT_MSG
_opensubdiv_LIBRARIES OPENSUBDIV_INCLUDE_DIR)
IF(OPENSUBDIV_FOUND)
SET(OPENSUBDIV_LIBRARIES ${_opensubdiv_LIBRARIES})
SET(OPENSUBDIV_INCLUDE_DIRS ${OPENSUBDIV_INCLUDE_DIR})
# Find available compute controllers.
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET(OPENSUBDIV_HAS_OPENMP TRUE)
ELSE()
SET(OPENSUBDIV_HAS_OPENMP FALSE)
ENDIF()
OPENSUBDIV_CHECK_CONTROLLER("tbbEvaluator.h" OPENSUBDIV_HAS_TBB)
OPENSUBDIV_CHECK_CONTROLLER("clEvaluator.h" OPENSUBDIV_HAS_OPENCL)
OPENSUBDIV_CHECK_CONTROLLER("cudaEvaluator.h" OPENSUBDIV_HAS_CUDA)
OPENSUBDIV_CHECK_CONTROLLER("glXFBEvaluator.h" OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK)
OPENSUBDIV_CHECK_CONTROLLER("glComputeEvaluator.h" OPENSUBDIV_HAS_GLSL_COMPUTE)
ENDIF(OPENSUBDIV_FOUND)
MARK_AS_ADVANCED(
OPENSUBDIV_INCLUDE_DIR
)
FOREACH(COMPONENT ${_opensubdiv_FIND_COMPONENTS})
STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
MARK_AS_ADVANCED(OPENSUBDIV_${UPPERCOMPONENT}_LIBRARY)
ENDFOREACH()

View File

@@ -66,14 +66,6 @@ IF(DEFINED PYTHON_LIBPATH)
SET(_IS_LIB_PATH_DEF ON)
ENDIF()
STRING(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
SET(_python_SEARCH_DIRS
${PYTHON_ROOT_DIR}
"$ENV{HOME}/py${_PYTHON_VERSION_NO_DOTS}"
"/opt/py${_PYTHON_VERSION_NO_DOTS}"
"/opt/lib/python-${PYTHON_VERSION}"
)
# only search for the dirs if we havn't already
IF((NOT _IS_INC_DEF) OR (NOT _IS_INC_CONF_DEF) OR (NOT _IS_LIB_DEF) OR (NOT _IS_LIB_PATH_DEF))
@@ -83,7 +75,14 @@ IF((NOT _IS_INC_DEF) OR (NOT _IS_INC_CONF_DEF) OR (NOT _IS_LIB_DEF) OR (NOT _IS_
"dm;dmu;du;d" # debug
)
STRING(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
SET(_python_SEARCH_DIRS
${PYTHON_ROOT_DIR}
"$ENV{HOME}/py${_PYTHON_VERSION_NO_DOTS}"
"/opt/py${_PYTHON_VERSION_NO_DOTS}"
"/opt/lib/python-${PYTHON_VERSION}"
)
FOREACH(_CURRENT_ABI_FLAGS ${_python_ABI_FLAGS})
#IF(CMAKE_BUILD_TYPE STREQUAL Debug)
@@ -148,7 +147,6 @@ IF((NOT _IS_INC_DEF) OR (NOT _IS_INC_CONF_DEF) OR (NOT _IS_LIB_DEF) OR (NOT _IS_
ENDIF()
IF(PYTHON_LIBRARY AND PYTHON_LIBPATH AND PYTHON_INCLUDE_DIR AND PYTHON_INCLUDE_CONFIG_DIR)
SET(_PYTHON_ABI_FLAGS "${_CURRENT_ABI_FLAGS}")
break()
ELSE()
# ensure we dont find values from 2 different ABI versions
@@ -171,6 +169,7 @@ IF((NOT _IS_INC_DEF) OR (NOT _IS_INC_CONF_DEF) OR (NOT _IS_LIB_DEF) OR (NOT _IS_
UNSET(_CURRENT_PATH)
UNSET(_python_ABI_FLAGS)
UNSET(_python_SEARCH_DIRS)
ENDIF()
UNSET(_IS_INC_DEF)
@@ -202,28 +201,14 @@ IF(PYTHONLIBSUNIX_FOUND)
# XXX No more valid with debian-like py3.4 packages...
# GET_FILENAME_COMPONENT(PYTHON_LIBPATH ${PYTHON_LIBRARY} PATH)
# not required for build, just used when bundling Python.
FIND_PROGRAM(
PYTHON_EXECUTABLE
NAMES
"python${PYTHON_VERSION}${_PYTHON_ABI_FLAGS}"
"python${PYTHON_VERSION}"
"python"
HINTS
${_python_SEARCH_DIRS}
PATH_SUFFIXES bin
)
# not used
# SET(PYTHON_BINARY ${PYTHON_EXECUTABLE} CACHE STRING "")
ENDIF()
UNSET(_PYTHON_VERSION_NO_DOTS)
UNSET(_PYTHON_ABI_FLAGS)
UNSET(_python_SEARCH_DIRS)
MARK_AS_ADVANCED(
PYTHON_INCLUDE_DIR
PYTHON_INCLUDE_CONFIG_DIR
PYTHON_LIBRARY
PYTHON_LIBPATH
PYTHON_SITE_PACKAGES
PYTHON_EXECUTABLE
)

View File

@@ -12,7 +12,7 @@
#
#=============================================================================
macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST)
macro(BLENDER_SRC_GTEST NAME SRC EXTRA_LIBS)
if(WITH_GTESTS)
get_property(_current_include_directories
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
@@ -40,20 +40,10 @@ macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST)
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${TESTS_OUTPUT_DIR}"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${TESTS_OUTPUT_DIR}"
INCLUDE_DIRECTORIES "${TEST_INC}")
if(${DO_ADD_TEST})
add_test(${NAME}_test ${TESTS_OUTPUT_DIR}/${NAME}_test)
endif()
add_test(${NAME}_test ${TESTS_OUTPUT_DIR}/${NAME}_test)
endif()
endmacro()
macro(BLENDER_SRC_GTEST NAME SRC EXTRA_LIBS)
BLENDER_SRC_GTEST_EX("${NAME}" "${SRC}" "${EXTRA_LIBS}" "TRUE")
endmacro()
macro(BLENDER_TEST NAME EXTRA_LIBS)
BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "TRUE")
endmacro()
macro(BLENDER_TEST_PERFORMANCE NAME EXTRA_LIBS)
BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "FALSE")
BLENDER_SRC_GTEST("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}")
endmacro()

View File

@@ -10,9 +10,9 @@ set(MY_WC_COMMIT_TIMESTAMP 0)
# Guess if this is a git working copy and then look up the revision
if(EXISTS ${SOURCE_DIR}/.git)
# The FindGit.cmake module is part of the standard distribution
find_package(Git)
include(FindGit)
if(GIT_FOUND)
message(STATUS "Found Git: ${GIT_EXECUTABLE}")
message(STATUS "-- Found Git: ${GIT_EXECUTABLE}")
execute_process(COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${SOURCE_DIR}
@@ -97,10 +97,6 @@ if(EXISTS ${SOURCE_DIR}/.git)
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE MY_WC_COMMIT_TIMESTAMP
OUTPUT_STRIP_TRAILING_WHITESPACE)
# May fail in rare cases
if(MY_WC_COMMIT_TIMESTAMP STREQUAL "")
set(MY_WC_COMMIT_TIMESTAMP 0)
endif()
# Update GIT index before getting dirty files
execute_process(COMMAND git update-index -q --refresh

View File

@@ -28,17 +28,13 @@ if not sys.version.startswith("3"):
sys.version.partition(" ")[0])
sys.exit(1)
from cmake_consistency_check_config import (
IGNORE,
UTF8_CHECK,
SOURCE_DIR,
BUILD_DIR,
)
from cmake_consistency_check_config import IGNORE, UTF8_CHECK, SOURCE_DIR
import os
from os.path import join, dirname, normpath, splitext
print("Scanning:", SOURCE_DIR)
global_h = set()
global_c = set()
global_refs = {}
@@ -138,7 +134,6 @@ def cmake_get_src(f):
if found:
cmake_base = dirname(f)
cmake_base_bin = os.path.join(BUILD_DIR, os.path.relpath(cmake_base, SOURCE_DIR))
while it is not None:
i += 1
@@ -159,8 +154,6 @@ def cmake_get_src(f):
# replace dirs
l = l.replace("${CMAKE_CURRENT_SOURCE_DIR}", cmake_base)
l = l.replace("${CMAKE_CURRENT_BINARY_DIR}", cmake_base_bin)
l = l.strip('"')
if not l:
pass
@@ -200,16 +193,13 @@ def cmake_get_src(f):
raise Exception("unknown file type - not c or h %s -> %s" % (f, new_file))
elif context_name == "INC":
if new_file.startswith(BUILD_DIR):
# assume generated path
pass
elif os.path.isdir(new_file):
if os.path.isdir(new_file):
new_path_rel = os.path.relpath(new_file, cmake_base)
if new_path_rel != l:
print("overly relative path:\n %s:%d\n %s\n %s" % (f, i, l, new_path_rel))
# # Save time. just replace the line
## Save time. just replace the line
# replace_line(f, i - 1, new_path_rel)
else:
@@ -240,6 +230,10 @@ def cmake_get_src(f):
filen.close()
for cmake in source_list(SOURCE_DIR, is_cmake):
cmake_get_src(cmake)
def is_ignore(f):
for ig in IGNORE:
if ig in f:
@@ -247,83 +241,73 @@ def is_ignore(f):
return False
def main():
# First do stupid check, do these files exist?
print("\nChecking for missing references:")
is_err = False
errs = []
for f in (global_h | global_c):
if f.endswith("dna.c"):
continue
print("Scanning:", SOURCE_DIR)
if not os.path.exists(f):
refs = global_refs[f]
if refs:
for cf, i in refs:
errs.append((cf, i))
else:
raise Exception("CMake referenecs missing, internal error, aborting!")
is_err = True
for cmake in source_list(SOURCE_DIR, is_cmake):
cmake_get_src(cmake)
# First do stupid check, do these files exist?
print("\nChecking for missing references:")
is_err = False
errs = []
for f in (global_h | global_c):
if f.startswith(BUILD_DIR):
continue
if not os.path.exists(f):
refs = global_refs[f]
if refs:
for cf, i in refs:
errs.append((cf, i))
else:
raise Exception("CMake referenecs missing, internal error, aborting!")
is_err = True
errs.sort()
errs.reverse()
for cf, i in errs:
print("%s:%d" % (cf, i))
# Write a 'sed' script, useful if we get a lot of these
# print("sed '%dd' '%s' > '%s.tmp' ; mv '%s.tmp' '%s'" % (i, cf, cf, cf, cf))
errs.sort()
errs.reverse()
for cf, i in errs:
print("%s:%d" % (cf, i))
# Write a 'sed' script, useful if we get a lot of these
# print("sed '%dd' '%s' > '%s.tmp' ; mv '%s.tmp' '%s'" % (i, cf, cf, cf, cf))
if is_err:
raise Exception("CMake referenecs missing files, aborting!")
del is_err
del errs
if is_err:
raise Exception("CMake referenecs missing files, aborting!")
del is_err
del errs
# now check on files not accounted for.
print("\nC/C++ Files CMake doesnt know about...")
for cf in sorted(source_list(SOURCE_DIR, is_c)):
if not is_ignore(cf):
if cf not in global_c:
print("missing_c: ", cf)
# now check on files not accounted for.
print("\nC/C++ Files CMake doesnt know about...")
for cf in sorted(source_list(SOURCE_DIR, is_c)):
if not is_ignore(cf):
if cf not in global_c:
print("missing_c: ", cf)
# check if automake builds a corrasponding .o file.
'''
if cf in global_c:
out1 = os.path.splitext(cf)[0] + ".o"
out2 = os.path.splitext(cf)[0] + ".Po"
out2_dir, out2_file = out2 = os.path.split(out2)
out2 = os.path.join(out2_dir, ".deps", out2_file)
if not os.path.exists(out1) and not os.path.exists(out2):
print("bad_c: ", cf)
'''
# check if automake builds a corrasponding .o file.
'''
if cf in global_c:
out1 = os.path.splitext(cf)[0] + ".o"
out2 = os.path.splitext(cf)[0] + ".Po"
out2_dir, out2_file = out2 = os.path.split(out2)
out2 = os.path.join(out2_dir, ".deps", out2_file)
if not os.path.exists(out1) and not os.path.exists(out2):
print("bad_c: ", cf)
'''
print("\nC/C++ Headers CMake doesnt know about...")
for hf in sorted(source_list(SOURCE_DIR, is_c_header)):
if not is_ignore(hf):
if hf not in global_h:
print("missing_h: ", hf)
print("\nC/C++ Headers CMake doesnt know about...")
for hf in sorted(source_list(SOURCE_DIR, is_c_header)):
if not is_ignore(hf):
if hf not in global_h:
print("missing_h: ", hf)
if UTF8_CHECK:
# test encoding
import traceback
for files in (global_c, global_h):
for f in sorted(files):
if os.path.exists(f):
# ignore outside of our source tree
if "extern" not in f:
i = 1
try:
for l in open(f, "r", encoding="utf8"):
i += 1
except UnicodeDecodeError:
print("Non utf8: %s:%d" % (f, i))
if i > 1:
traceback.print_exc()
if __name__ == "__main__":
main()
if UTF8_CHECK:
# test encoding
import traceback
for files in (global_c, global_h):
for f in sorted(files):
if os.path.exists(f):
# ignore outside of our source tree
if "extern" not in f:
i = 1
try:
for l in open(f, "r", encoding="utf8"):
i += 1
except UnicodeDecodeError:
print("Non utf8: %s:%d" % (f, i))
if i > 1:
traceback.print_exc()

View File

@@ -74,6 +74,3 @@ IGNORE = (
UTF8_CHECK = True
SOURCE_DIR = os.path.normpath(os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(__file__), "..", ".."))))
# doesn't have to exist, just use as reference
BUILD_DIR = os.path.normpath(os.path.abspath(os.path.normpath(os.path.join(SOURCE_DIR, "..", "build"))))

View File

@@ -40,7 +40,6 @@ from project_info import (
# is_py,
cmake_advanced_info,
cmake_compiler_defines,
cmake_cache_var,
project_name_get,
)
@@ -50,8 +49,6 @@ from os.path import join, dirname, normpath, relpath, exists
def create_nb_project_main():
from xml.sax.saxutils import escape
files = list(source_list(SOURCE_DIR, filename_check=is_project_file))
files_rel = [relpath(f, start=PROJECT_DIR) for f in files]
files_rel.sort()
@@ -74,10 +71,6 @@ def create_nb_project_main():
# be tricky, get the project name from git if we can!
PROJECT_NAME = project_name_get()
make_exe = cmake_cache_var("CMAKE_MAKE_PROGRAM")
make_exe_basename = os.path.basename(make_exe)
# --------------- NB spesific
defines = [("%s=%s" % cdef) if cdef[1] else cdef[0] for cdef in defines]
defines += [cdef.replace("#define", "").strip() for cdef in cmake_compiler_defines()]
@@ -138,9 +131,9 @@ def create_nb_project_main():
f = open(join(PROJECT_DIR_NB, "configurations.xml"), 'w')
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
f.write('<configurationDescriptor version="95">\n')
f.write('<configurationDescriptor version="94">\n')
f.write(' <logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT">\n')
f.write(' <df root="%s" name="0">\n' % SOURCE_DIR) # base_root_rel
f.write(' <df name="0" root="%s">\n' % SOURCE_DIR) # base_root_rel
# write files!
files_rel_local = [normpath(relpath(join(CMAKE_DIR, path), SOURCE_DIR)) for path in files_rel]
@@ -192,27 +185,16 @@ def create_nb_project_main():
f.write(' <toolsSet>\n')
f.write(' <compilerSet>default</compilerSet>\n')
f.write(' <dependencyChecking>false</dependencyChecking>\n')
f.write(' <rebuildPropChanged>false</rebuildPropChanged>\n')
f.write(' </toolsSet>\n')
f.write(' <codeAssistance>\n')
f.write(' </codeAssistance>\n')
f.write(' <dependencyChecking>false</dependencyChecking>\n')
f.write(' <rebuildPropChanged>false</rebuildPropChanged>\n')
f.write(' <makefileType>\n')
f.write(' <makeTool>\n')
f.write(' <buildCommandWorkingDir>.</buildCommandWorkingDir>\n')
if make_exe_basename == "ninja":
build_cmd = "ninja"
clean_cmd = "ninja -t clean"
else:
build_cmd = "${MAKE} -f Makefile"
clean_cmd = "${MAKE} -f Makefile clean"
f.write(' <buildCommand>%s</buildCommand>\n' % escape(build_cmd))
f.write(' <cleanCommand>%s</cleanCommand>\n' % escape(clean_cmd))
f.write(' <buildCommand>${MAKE} -f Makefile</buildCommand>\n')
f.write(' <cleanCommand>${MAKE} -f Makefile clean</cleanCommand>\n')
f.write(' <executablePath>./bin/blender</executablePath>\n')
del build_cmd, clean_cmd
def write_toolinfo():
f.write(' <incDir>\n')
@@ -221,7 +203,7 @@ def create_nb_project_main():
f.write(' </incDir>\n')
f.write(' <preprocessorList>\n')
for cdef in defines:
f.write(' <Elem>%s</Elem>\n' % escape(cdef))
f.write(' <Elem>%s</Elem>\n' % cdef)
f.write(' </preprocessorList>\n')
f.write(' <cTool>\n')
@@ -239,11 +221,10 @@ def create_nb_project_main():
f.write(' \n')
for path in files_rel_local:
is_c = path.endswith(".c")
f.write(' <item path="%s"\n' % path)
f.write(' ex="false"\n')
f.write(' tool="%d"\n' % (0 if is_c else 1))
f.write(' flavor2="%d">\n' % (3 if is_c else 0))
f.write(' tool="1"\n')
f.write(' flavor2="0">\n')
f.write(' </item>\n')
f.write(' <runprofile version="9">\n')

View File

@@ -1,4 +1,5 @@
# Turn everything ON thats expected for an official release builds.
# turn everything OFF except for python which defaults to ON
# and is needed for the UI
#
# Example usage:
# cmake -C../blender/build_files/cmake/config/blender_full.cmake ../blender
@@ -12,7 +13,6 @@ set(WITH_CODEC_SNDFILE ON CACHE BOOL "" FORCE)
set(WITH_CYCLES ON CACHE BOOL "" FORCE)
set(WITH_FFTW3 ON CACHE BOOL "" FORCE)
set(WITH_LIBMV ON CACHE BOOL "" FORCE)
set(WITH_LIBMV_SCHUR_SPECIALIZATIONS ON CACHE BOOL "" FORCE)
set(WITH_GAMEENGINE ON CACHE BOOL "" FORCE)
set(WITH_COMPOSITOR ON CACHE BOOL "" FORCE)
set(WITH_FREESTYLE ON CACHE BOOL "" FORCE)
@@ -52,18 +52,11 @@ set(WITH_X11_XF86VMODE ON CACHE BOOL "" FORCE)
set(WITH_PLAYER ON CACHE BOOL "" FORCE)
set(WITH_MEM_JEMALLOC ON CACHE BOOL "" FORCE)
# platform dependant options
if(UNIX AND NOT APPLE)
set(WITH_JACK ON CACHE BOOL "" FORCE)
set(WITH_DOC_MANPAGE ON CACHE BOOL "" FORCE)
set(WITH_OPENSUBDIV ON CACHE BOOL "" FORCE)
elseif(WIN32)
set(WITH_JACK OFF CACHE BOOL "" FORCE)
set(WITH_OPENSUBDIV ON CACHE BOOL "" FORCE)
elseif (APPLE)
set(WITH_JACK ON CACHE BOOL "" FORCE)
set(WITH_CODEC_QUICKTIME ON CACHE BOOL "" FORCE)
set(WITH_OPENSUBDIV OFF CACHE BOOL "" FORCE)
endif()
if(APPLE)
set(WITH_CODEC_QUICKTIME ON CACHE BOOL "" FORCE)
endif()

View File

@@ -16,7 +16,6 @@ set(WITH_CODEC_SNDFILE OFF CACHE BOOL "" FORCE)
set(WITH_CYCLES OFF CACHE BOOL "" FORCE)
set(WITH_FFTW3 OFF CACHE BOOL "" FORCE)
set(WITH_LIBMV OFF CACHE BOOL "" FORCE)
set(WITH_LLVM OFF CACHE BOOL "" FORCE)
set(WITH_GAMEENGINE OFF CACHE BOOL "" FORCE)
set(WITH_COMPOSITOR OFF CACHE BOOL "" FORCE)
set(WITH_FREESTYLE OFF CACHE BOOL "" FORCE)
@@ -48,6 +47,7 @@ set(WITH_OPENCOLORIO OFF CACHE BOOL "" FORCE)
set(WITH_OPENIMAGEIO OFF CACHE BOOL "" FORCE)
set(WITH_OPENMP OFF CACHE BOOL "" FORCE)
set(WITH_OPENNL OFF CACHE BOOL "" FORCE)
set(WITH_PYTHON_INSTALL OFF CACHE BOOL "" FORCE)
set(WITH_RAYOPTIMIZATION OFF CACHE BOOL "" FORCE)
set(WITH_SDL OFF CACHE BOOL "" FORCE)
set(WITH_X11_XINPUT OFF CACHE BOOL "" FORCE)

View File

@@ -48,7 +48,7 @@ macro(list_insert_before
unset(_index)
endmacro()
function(list_assert_duplicates
function (list_assert_duplicates
list_id
)
@@ -104,31 +104,21 @@ macro(file_list_suffix
endmacro()
function(target_link_libraries_optimized
TARGET
LIBS
)
macro(target_link_libraries_optimized TARGET LIBS)
foreach(_LIB ${LIBS})
target_link_libraries(${TARGET} optimized "${_LIB}")
endforeach()
endfunction()
function(target_link_libraries_debug
TARGET
LIBS
)
unset(_LIB)
endmacro()
macro(target_link_libraries_debug TARGET LIBS)
foreach(_LIB ${LIBS})
target_link_libraries(${TARGET} debug "${_LIB}")
endforeach()
endfunction()
function(target_link_libraries_decoupled
target
libraries_var
)
unset(_LIB)
endmacro()
macro(target_link_libraries_decoupled target libraries_var)
if(NOT MSVC)
target_link_libraries(${target} ${${libraries_var}})
else()
@@ -137,15 +127,14 @@ function(target_link_libraries_decoupled
file_list_suffix(_libraries_debug "${${libraries_var}}" "_d")
target_link_libraries_debug(${target} "${_libraries_debug}")
target_link_libraries_optimized(${target} "${${libraries_var}}")
unset(_libraries_debug)
endif()
endfunction()
endmacro()
# Nicer makefiles with -I/1/foo/ instead of -I/1/2/3/../../foo/
# use it instead of include_directories()
function(blender_include_dirs
includes
)
macro(blender_include_dirs
includes)
set(_ALL_INCS "")
foreach(_INC ${ARGV})
get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
@@ -156,12 +145,13 @@ function(blender_include_dirs
##endif()
endforeach()
include_directories(${_ALL_INCS})
endfunction()
function(blender_include_dirs_sys
includes
)
unset(_INC)
unset(_ABS_INC)
unset(_ALL_INCS)
endmacro()
macro(blender_include_dirs_sys
includes)
set(_ALL_INCS "")
foreach(_INC ${ARGV})
get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
@@ -171,11 +161,13 @@ function(blender_include_dirs_sys
##endif()
endforeach()
include_directories(SYSTEM ${_ALL_INCS})
endfunction()
unset(_INC)
unset(_ABS_INC)
unset(_ALL_INCS)
endmacro()
function(blender_source_group
sources
)
macro(blender_source_group
sources)
# Group by location on disk
source_group("Source Files" FILES CMakeLists.txt)
@@ -185,23 +177,23 @@ function(blender_source_group
if((${_SRC_EXT} MATCHES ".h") OR
(${_SRC_EXT} MATCHES ".hpp") OR
(${_SRC_EXT} MATCHES ".hh"))
set(GROUP_ID "Header Files")
source_group("Header Files" FILES ${_SRC})
else()
set(GROUP_ID "Source Files")
source_group("Source Files" FILES ${_SRC})
endif()
source_group("${GROUP_ID}" FILES ${_SRC})
endforeach()
endfunction()
unset(_SRC)
unset(_SRC_EXT)
endmacro()
# only MSVC uses SOURCE_GROUP
function(blender_add_lib_nolist
macro(blender_add_lib_nolist
name
sources
includes
includes_sys
)
includes_sys)
# message(STATUS "Configuring library ${name}")
@@ -212,8 +204,6 @@ function(blender_add_lib_nolist
add_library(${name} ${sources})
target_link_libraries(${name} ${lib_depends})
# works fine without having the includes
# listed is helpful for IDE's (QtCreator/MSVC)
blender_source_group("${sources}")
@@ -223,27 +213,22 @@ function(blender_add_lib_nolist
# Not for system includes because they can resolve to the same path
# list_assert_duplicates("${includes_sys}")
endfunction()
endmacro()
function(blender_add_lib
macro(blender_add_lib
name
sources
includes
includes_sys
libs
)
includes_sys)
blender_add_lib_nolist(${name} "${sources}" "${includes}" "${includes_sys}")
target_link_libraries(${name} "${libs}")
set_property(GLOBAL APPEND PROPERTY BLENDER_LINK_LIBS ${name})
endfunction()
endmacro()
function(SETUP_LIBDIRS)
macro(SETUP_LIBDIRS)
link_directories(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH})
if(WITH_PYTHON) # AND NOT WITH_PYTHON_MODULE # WIN32 needs
@@ -303,27 +288,24 @@ function(SETUP_LIBDIRS)
if(WIN32 AND NOT UNIX)
link_directories(${PTHREADS_LIBPATH})
endif()
endfunction()
endmacro()
function(setup_liblinks
target
)
macro(setup_liblinks
target)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}")
target_link_libraries(
${target}
${PNG_LIBRARIES}
${ZLIB_LIBRARIES}
${FREETYPE_LIBRARY}
)
target_link_libraries(${target}
${PNG_LIBRARIES}
${ZLIB_LIBRARIES}
${FREETYPE_LIBRARY})
# since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
if(WITH_PYTHON) # AND NOT WITH_PYTHON_MODULE # WIN32 needs
@@ -348,9 +330,6 @@ function(setup_liblinks
if(WITH_BULLET AND WITH_SYSTEM_BULLET)
target_link_libraries(${target} ${BULLET_LIBRARIES})
endif()
if(WITH_AUDASPACE AND WITH_SYSTEM_AUDASPACE)
target_link_libraries(${target} ${AUDASPACE_C_LIBRARIES} ${AUDASPACE_PY_LIBRARIES})
endif()
if(WITH_OPENAL)
target_link_libraries(${target} ${OPENAL_LIBRARY})
endif()
@@ -378,16 +357,6 @@ function(setup_liblinks
if(WITH_OPENCOLORIO)
target_link_libraries(${target} ${OPENCOLORIO_LIBRARIES})
endif()
if(WITH_OPENSUBDIV)
if(WIN32 AND NOT UNIX)
file_list_suffix(OPENSUBDIV_LIBRARIES_DEBUG "${OPENSUBDIV_LIBRARIES}" "_d")
target_link_libraries_debug(${target} "${OPENSUBDIV_LIBRARIES_DEBUG}")
target_link_libraries_optimized(${target} "${OPENSUBDIV_LIBRARIES}")
unset(OPENSUBDIV_LIBRARIES_DEBUG)
else()
target_link_libraries(${target} ${OPENSUBDIV_LIBRARIES})
endif()
endif()
if(WITH_CYCLES_OSL)
target_link_libraries(${target} ${OSL_LIBRARIES})
endif()
@@ -433,13 +402,11 @@ function(setup_liblinks
unset(EXPAT_LIB_DEBUG)
endif()
else()
target_link_libraries(
${target}
${OPENCOLLADA_LIBRARIES}
${PCRE_LIBRARIES}
${XML2_LIBRARIES}
${EXPAT_LIB}
)
target_link_libraries(${target}
${OPENCOLLADA_LIBRARIES}
${PCRE_LIBRARIES}
${XML2_LIBRARIES}
${EXPAT_LIB})
endif()
endif()
if(WITH_MEM_JEMALLOC)
@@ -469,13 +436,10 @@ function(setup_liblinks
${BLENDER_GL_LIBRARIES})
target_link_libraries(${target} ${PLATFORM_LINKLIBS} ${CMAKE_DL_LIBS})
endfunction()
endmacro()
function(SETUP_BLENDER_SORTED_LIBS)
# get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
set(BLENDER_LINK_LIBS)
macro(SETUP_BLENDER_SORTED_LIBS)
get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
list(APPEND BLENDER_LINK_LIBS
bf_windowmanager
@@ -560,7 +524,6 @@ function(SETUP_BLENDER_SORTED_LIBS)
bf_blenloader
bf_imbuf
bf_blenlib
bf_depsgraph
bf_intern_ghost
bf_intern_string
bf_avi
@@ -597,7 +560,6 @@ function(SETUP_BLENDER_SORTED_LIBS)
ge_videotex
bf_dna
bf_blenfont
bf_blentranslation
bf_intern_audaspace
bf_intern_mikktspace
bf_intern_dualcon
@@ -615,7 +577,6 @@ function(SETUP_BLENDER_SORTED_LIBS)
extern_libmv
extern_glog
extern_sdlew
extern_eigen3
bf_intern_glew_mx
)
@@ -694,10 +655,6 @@ function(SETUP_BLENDER_SORTED_LIBS)
list_insert_after(BLENDER_SORTED_LIBS "ge_logic_ngnetwork" "extern_bullet")
endif()
if(WITH_OPENSUBDIV)
list(APPEND BLENDER_SORTED_LIBS bf_intern_opensubdiv)
endif()
foreach(SORTLIB ${BLENDER_SORTED_LIBS})
set(REMLIB ${SORTLIB})
foreach(SEARCHLIB ${BLENDER_LINK_LIBS})
@@ -716,12 +673,14 @@ function(SETUP_BLENDER_SORTED_LIBS)
message(STATUS "Blender Skipping: (${REM_MSG})")
endif()
set(BLENDER_SORTED_LIBS ${BLENDER_SORTED_LIBS} PARENT_SCOPE)
unset(SEARCHLIB)
unset(SORTLIB)
unset(REMLIB)
unset(REM_MSG)
# for top-level tests
set_property(GLOBAL PROPERTY BLENDER_SORTED_LIBS_PROP ${BLENDER_SORTED_LIBS})
endfunction()
endmacro()
macro(TEST_SSE_SUPPORT
_sse_flags
@@ -943,22 +902,19 @@ endmacro()
# utility macro
macro(remove_cc_flag
_flag)
flag)
foreach(flag ${ARGV})
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endforeach()
unset(flag)
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endmacro()
@@ -972,34 +928,28 @@ endmacro()
macro(remove_strict_flags)
if(CMAKE_COMPILER_IS_GNUCC)
remove_cc_flag(
"-Wstrict-prototypes"
"-Wmissing-prototypes"
"-Wmissing-format-attribute"
"-Wunused-local-typedefs"
"-Wunused-macros"
"-Wunused-parameter"
"-Wwrite-strings"
"-Wredundant-decls"
"-Wundef"
"-Wshadow"
"-Wdouble-promotion"
"-Wold-style-definition"
"-Werror=[^ ]+"
"-Werror"
)
remove_cc_flag("-Wstrict-prototypes")
remove_cc_flag("-Wmissing-prototypes")
remove_cc_flag("-Wunused-parameter")
remove_cc_flag("-Wunused-macros")
remove_cc_flag("-Wwrite-strings")
remove_cc_flag("-Wredundant-decls")
remove_cc_flag("-Wundef")
remove_cc_flag("-Wshadow")
remove_cc_flag("-Wdouble-promotion")
remove_cc_flag("-Wold-style-definition")
remove_cc_flag("-Werror=[^ ]+")
remove_cc_flag("-Werror")
# negate flags implied by '-Wall'
add_cc_flag("${CC_REMOVE_STRICT_FLAGS}")
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
remove_cc_flag(
"-Wunused-parameter"
"-Wunused-variable"
"-Werror=[^ ]+"
"-Werror"
)
remove_cc_flag("-Wunused-parameter")
remove_cc_flag("-Wunused-variable")
remove_cc_flag("-Werror=[^ ]+")
remove_cc_flag("-Werror")
# negate flags implied by '-Wall'
add_cc_flag("${CC_REMOVE_STRICT_FLAGS}")
@@ -1013,15 +963,11 @@ endmacro()
macro(remove_extra_strict_flags)
if(CMAKE_COMPILER_IS_GNUCC)
remove_cc_flag(
"-Wunused-parameter"
)
remove_cc_flag("-Wunused-parameter")
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
remove_cc_flag(
"-Wunused-parameter"
)
remove_cc_flag("-Wunused-parameter")
endif()
if(MSVC)
@@ -1057,39 +1003,37 @@ macro(remove_strict_flags_file
endmacro()
function(ADD_CHECK_C_COMPILER_FLAG
macro(ADD_CHECK_C_COMPILER_FLAG
_CFLAGS
_CACHE_VAR
_FLAG
)
_FLAG)
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
if(${_CACHE_VAR})
# message(STATUS "Using CFLAG: ${_FLAG}")
set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}" PARENT_SCOPE)
set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}")
else()
message(STATUS "Unsupported CFLAG: ${_FLAG}")
endif()
endfunction()
endmacro()
function(ADD_CHECK_CXX_COMPILER_FLAG
macro(ADD_CHECK_CXX_COMPILER_FLAG
_CXXFLAGS
_CACHE_VAR
_FLAG
)
_FLAG)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
if(${_CACHE_VAR})
# message(STATUS "Using CXXFLAG: ${_FLAG}")
set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}" PARENT_SCOPE)
set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}")
else()
message(STATUS "Unsupported CXXFLAG: ${_FLAG}")
endif()
endfunction()
endmacro()
function(get_blender_version)
# extracts header vars and defines them in the parent scope:
@@ -1239,7 +1183,7 @@ endmacro()
# pair of macros to allow libraries to be specify files to install, but to
# only install them at the end so the directories don't get cleared with
# the files in them. used by cycles to install addon.
function(delayed_install
macro(delayed_install
base
files
destination)
@@ -1252,7 +1196,8 @@ function(delayed_install
endif()
set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_DESTINATIONS ${destination})
endforeach()
endfunction()
unset(f)
endmacro()
# note this is a function instead of a macro so that ${BUILD_TYPE} in targetdir
# does not get expanded in calling but is preserved
@@ -1271,59 +1216,62 @@ function(delayed_do_install
list(GET destinations ${i} d)
install(FILES ${f} DESTINATION ${targetdir}/${d})
endforeach()
unset(f)
endif()
endfunction()
function(data_to_c
file_from file_to
list_to_add
)
macro(data_to_c
file_from file_to
list_to_add)
list(APPEND ${list_to_add} ${file_to})
set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
get_filename_component(_file_to_path ${file_to} PATH)
add_custom_command(
OUTPUT ${file_to}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
COMMAND "$<TARGET_FILE:datatoc>" ${file_from} ${file_to}
COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/datatoc ${file_from} ${file_to}
DEPENDS ${file_from} datatoc)
set_source_files_properties(${file_to} PROPERTIES GENERATED TRUE)
endfunction()
unset(_file_to_path)
endmacro()
# same as above but generates the var name and output automatic.
function(data_to_c_simple
file_from
list_to_add
)
macro(data_to_c_simple
file_from
list_to_add)
# remove ../'s
get_filename_component(_file_from ${CMAKE_CURRENT_SOURCE_DIR}/${file_from} REALPATH)
get_filename_component(_file_to ${CMAKE_CURRENT_BINARY_DIR}/${file_from}.c REALPATH)
list(APPEND ${list_to_add} ${_file_to})
set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
get_filename_component(_file_to_path ${_file_to} PATH)
add_custom_command(
OUTPUT ${_file_to}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
COMMAND "$<TARGET_FILE:datatoc>" ${_file_from} ${_file_to}
COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/datatoc ${_file_from} ${_file_to}
DEPENDS ${_file_from} datatoc)
set_source_files_properties(${_file_to} PROPERTIES GENERATED TRUE)
endfunction()
unset(_file_from)
unset(_file_to)
unset(_file_to_path)
endmacro()
# macro for converting pixmap directory to a png and then a c file
function(data_to_c_simple_icons
path_from
list_to_add
)
macro(data_to_c_simple_icons
path_from
list_to_add
)
# Conversion steps
# path_from -> _file_from -> _file_to
@@ -1335,7 +1283,6 @@ function(data_to_c_simple_icons
get_filename_component(_file_to ${CMAKE_CURRENT_BINARY_DIR}/${path_from}.png.c REALPATH)
list(APPEND ${list_to_add} ${_file_to})
set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
get_filename_component(_file_to_path ${_file_to} PATH)
@@ -1346,8 +1293,8 @@ function(data_to_c_simple_icons
OUTPUT ${_file_from} ${_file_to}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
#COMMAND python3 ${CMAKE_SOURCE_DIR}/source/blender/datatoc/datatoc_icon.py ${_path_from_abs} ${_file_from}
COMMAND "$<TARGET_FILE:datatoc_icon>" ${_path_from_abs} ${_file_from}
COMMAND "$<TARGET_FILE:datatoc>" ${_file_from} ${_file_to}
COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/datatoc_icon ${_path_from_abs} ${_file_from}
COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/datatoc ${_file_from} ${_file_to}
DEPENDS
${_icon_files}
datatoc_icon
@@ -1357,22 +1304,27 @@ function(data_to_c_simple_icons
)
set_source_files_properties(${_file_from} ${_file_to} PROPERTIES GENERATED TRUE)
endfunction()
unset(_path_from_abs)
unset(_file_from)
unset(_file_to)
unset(_file_to_path)
unset(_icon_files)
endmacro()
# XXX Not used for now...
function(svg_to_png
file_from
file_to
dpi
list_to_add
)
macro(svg_to_png
file_from
file_to
dpi
list_to_add)
# remove ../'s
get_filename_component(_file_from ${CMAKE_CURRENT_SOURCE_DIR}/${file_from} REALPATH)
get_filename_component(_file_to ${CMAKE_CURRENT_SOURCE_DIR}/${file_to} REALPATH)
list(APPEND ${list_to_add} ${_file_to})
set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
find_program(INKSCAPE_EXE inkscape)
mark_as_advanced(INKSCAPE_EXE)
@@ -1395,12 +1347,15 @@ function(svg_to_png
else()
message(WARNING "Inkscape not found, could not re-generate ${_file_to} from ${_file_from}!")
endif()
endfunction()
function(msgfmt_simple
file_from
list_to_add
)
unset(_file_from)
unset(_file_to)
endmacro()
macro(msgfmt_simple
file_from
list_to_add)
# remove ../'s
get_filename_component(_file_from_we ${file_from} NAME_WE)
@@ -1409,22 +1364,25 @@ function(msgfmt_simple
get_filename_component(_file_to ${CMAKE_CURRENT_BINARY_DIR}/${_file_from_we}.mo REALPATH)
list(APPEND ${list_to_add} ${_file_to})
set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
get_filename_component(_file_to_path ${_file_to} PATH)
add_custom_command(
OUTPUT ${_file_to}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
COMMAND "$<TARGET_FILE:msgfmt>" ${_file_from} ${_file_to}
COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/msgfmt ${_file_from} ${_file_to}
DEPENDS msgfmt ${_file_from})
set_source_files_properties(${_file_to} PROPERTIES GENERATED TRUE)
endfunction()
function(find_python_package
package
)
unset(_file_from_we)
unset(_file_from)
unset(_file_to)
unset(_file_to_path)
endmacro()
macro(find_python_package
package)
string(TOUPPER ${package} _upper_package)
@@ -1462,17 +1420,25 @@ function(find_python_package
"'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/${package}', "
"'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/${package}', "
"WITH_PYTHON_INSTALL_${_upper_package} option will be ignored when installing python")
set(WITH_PYTHON_INSTALL_${_upper_package} OFF PARENT_SCOPE)
set(WITH_PYTHON_INSTALL_${_upper_package} OFF)
else()
message(STATUS "${package} found at '${PYTHON_${_upper_package}_PATH}'")
endif()
unset(_PY_VER_SPLIT)
unset(_PY_VER_MAJOR)
endif()
endfunction()
unset(_upper_package)
endmacro()
# like Python's 'print(dir())'
function(print_all_vars)
macro(print_all_vars)
get_cmake_property(_vars VARIABLES)
foreach(_var ${_vars})
message("${_var}=${${_var}}")
endforeach()
endfunction()
unset(_vars)
unset(_var)
endmacro()

View File

@@ -21,10 +21,10 @@ SET(CPACK_PACKAGE_VERSION_PATCH "${PATCH_VERSION}")
# Get the build revision, note that this can get out-of-sync, so for packaging run cmake first.
set(MY_WC_HASH "unknown")
if(EXISTS ${CMAKE_SOURCE_DIR}/.git/)
find_package(Git)
include(FindGit)
if(GIT_FOUND)
message(STATUS "Found Git: ${GIT_EXECUTABLE}")
execute_process(COMMAND git rev-parse --short HEAD
message(STATUS "-- Found Git: ${GIT_EXECUTABLE}")
execute_process(COMMAND git rev-parse --short @{u}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE MY_WC_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
@@ -37,8 +37,7 @@ unset(MY_WC_HASH)
# Force Package Name
execute_process(COMMAND date "+%Y%m%d" OUTPUT_VARIABLE CPACK_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME_LOWER}-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}-git${CPACK_DATE}.${BUILD_REV}-${CMAKE_SYSTEM_PROCESSOR})
set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}-git${CPACK_DATE}.${BUILD_REV}-${CMAKE_SYSTEM_PROCESSOR})
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
# RPM packages
@@ -74,7 +73,6 @@ if(WIN32)
set(CPACK_WIX_PRODUCT_ICON ${CMAKE_SOURCE_DIR}/source/icons/winblender.ico)
set(CPACK_WIX_UPGRADE_GUID "B767E4FD-7DE7-4094-B051-3AE62E13A17A")
set(CPACK_WIX_TEMPLATE ${LIBDIR}/package/installer_wix/WIX.template)
set(CPACK_WIX_UI_BANNER ${LIBDIR}/package/installer_wix/WIX_UI_BANNER.bmp)
set(CPACK_WIX_UI_DIALOG ${LIBDIR}/package/installer_wix/WIX_UI_DIALOG.bmp)
@@ -114,9 +112,3 @@ elseif(UNIX)
"tar.bz2")
endif()
unset(MAJOR_VERSION)
unset(MINOR_VERSION)
unset(PATCH_VERSION)
unset(BUILD_REV)

View File

@@ -130,7 +130,7 @@ def is_project_file(filename):
def cmake_advanced_info():
""" Extract includes and defines from cmake.
""" Extracr includes and defines from cmake.
"""
make_exe = cmake_cache_var("CMAKE_MAKE_PROGRAM")

View File

@@ -59,21 +59,14 @@ def is_c_any(filename):
CMAKE_DIR = "."
def cmake_cache_var_iter():
import re
re_cache = re.compile(r'([A-Za-z0-9_\-]+)?:?([A-Za-z0-9_\-]+)?=(.*)$')
with open(join(CMAKE_DIR, "CMakeCache.txt"), 'r', encoding='utf-8') as cache_file:
for l in cache_file:
match = re_cache.match(l.strip())
if match is not None:
var, type_, val = match.groups()
yield (var, type_ or "", val)
def cmake_cache_var(var):
for var_iter, type_iter, value_iter in cmake_cache_var_iter():
if var == var_iter:
return value_iter
cache_file = open(join(CMAKE_DIR, "CMakeCache.txt"))
lines = [l_strip for l in cache_file for l_strip in (l.strip(),) if l_strip if not l_strip.startswith("//") if not l_strip.startswith("#")]
cache_file.close()
for l in lines:
if l.split(":")[0] == var:
return l.split("=", 1)[-1]
return None

View File

@@ -52,8 +52,6 @@ BF_CXX = '/usr'
WITH_BF_STATICCXX = False
BF_CXX_LIB_STATIC = '${BF_CXX}/lib/libstdc++.a'
WITH_BF_AUDASPACE = True
# we use simply jack framework
WITH_BF_JACK = True
BF_JACK = '/Library/Frameworks/Jackmp.framework'
@@ -215,12 +213,6 @@ WITH_BF_FREESTYLE = True
#OpenMP ( will be checked for compiler support and turned off eventually )
WITH_BF_OPENMP = True
WITH_BF_OPENSUBDIV = False
BF_OPENSUBDIV = LIBDIR + '/opensubdiv'
BF_OPENSUBDIV_INC = '${BF_OPENSUBDIV}/include'
BF_OPENSUBDIV_LIB = 'osdCPU osdGPU'
BF_OPENSUBDIV_LIBPATH = '${BF_OPENSUBDIV}/lib'
#Ray trace optimization
WITH_BF_RAYOPTIMIZATION = True
BF_RAYOPTIMIZATION_SSE_FLAGS = []

View File

@@ -26,8 +26,6 @@ BF_CXX = '/usr'
WITH_BF_STATICCXX = False
BF_CXX_LIB_STATIC = '${BF_CXX}/lib/libstdc++.a'
WITH_BF_AUDASPACE = True
WITH_BF_JACK = False
BF_JACK = '/usr'
BF_JACK_INC = '${BF_JACK}/include/jack'
@@ -208,7 +206,7 @@ WITH_BF_CYCLES = WITH_BF_OIIO and WITH_BF_BOOST
WITH_BF_CYCLES_CUDA_BINARIES = False
BF_CYCLES_CUDA_NVCC = '/usr/local/cuda/bin/nvcc'
BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_20', 'sm_21', 'sm_30', 'sm_35', 'sm_50', 'sm_52']
BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_20', 'sm_21', 'sm_30', 'sm_35', 'sm_50']
WITH_BF_OPENMP = True
@@ -228,14 +226,6 @@ BF_3DMOUSE_LIB_STATIC = '${BF_3DMOUSE_LIBPATH}/libspnav.a'
#Freestyle
WITH_BF_FREESTYLE = True
WITH_BF_OPENSUBDIV = False
WITH_BF_STATICOPENSUBDIV = False
BF_OPENSUBDIV = '/usr'
BF_OPENSUBDIV_INC = '${BF_OPENSUBDIV}/include'
BF_OPENSUBDIV_LIB = 'osdCPU osdGPU'
BF_OPENSUBDIV_LIB_STATIC = '${BF_OPENSUBDIV_LIBPATH}/libosdGPU.a ${BF_OPENSUBDIV_LIBPATH}/libosdCPU.a'
BF_OPENSUBDIV_LIBPATH = '${BF_OPENSUBDIV}/lib'
##
CC = 'gcc'
CXX = 'g++'

View File

@@ -23,8 +23,6 @@ BF_FFMPEG_LIBPATH = LIBDIR + '/ffmpeg/lib'
BF_FFMPEG_INC = LIBDIR + '/ffmpeg/include'
BF_FFMPEG_DLL = '${BF_FFMPEG_LIBPATH}/avformat-55.dll ${BF_FFMPEG_LIBPATH}/avcodec-55.dll ${BF_FFMPEG_LIBPATH}/avdevice-55.dll ${BF_FFMPEG_LIBPATH}/avutil-52.dll ${BF_FFMPEG_LIBPATH}/swscale-2.dll'
WITH_BF_AUDASPACE = True
WITH_BF_JACK = False
BF_JACK = LIBDIR + '/jack'
BF_JACK_INC = '${BF_JACK}/include'
@@ -147,7 +145,7 @@ BF_OPENCOLLADA_LIBPATH = '${BF_OPENCOLLADA}/lib/opencollada'
WITH_BF_CYCLES = True
WITH_BF_CYCLES_CUDA_BINARIES = False
BF_CYCLES_CUDA_NVCC = "" # Path to the NVIDIA CUDA compiler
BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_20', 'sm_21', 'sm_30', 'sm_35', 'sm_50', 'sm_52']
BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_20', 'sm_21', 'sm_30', 'sm_35', 'sm_50']
WITH_BF_OIIO = True
BF_OIIO = LIBDIR + '/openimageio'
@@ -168,12 +166,6 @@ BF_BOOST_LIB = 'boost_date_time-mgw46-mt-s-1_49 boost_filesystem-mgw46-mt-s-1_49
BF_BOOST_LIB_INTERNATIONAL = 'boost_locale-mgw46-mt-s-1_49'
BF_BOOST_LIBPATH = '${BF_BOOST}/lib'
WITH_BF_OPENSUBDIV = False
BF_OPENSUBDIV = LIBDIR + '/opensubdiv'
BF_OPENSUBDIV_INC = '${BF_OPENSUBDIV}/include'
BF_OPENSUBDIV_LIB = 'osdCPU osdGPU'
BF_OPENSUBDIV_LIBPATH = '${BF_OPENSUBDIV}/lib'
#Ray trace optimization
WITH_BF_RAYOPTIMIZATION = True
BF_RAYOPTIMIZATION_SSE_FLAGS = ['-msse']

View File

@@ -42,8 +42,6 @@ BF_ICONV_INC = '${BF_ICONV}/include'
BF_ICONV_LIB = 'iconv'
BF_ICONV_LIBPATH = '${BF_ICONV}/lib'
WITH_BF_AUDASPACE = True
WITH_BF_JACK = False
BF_JACK = LIBDIR + '/jack'
BF_JACK_INC = '${BF_JACK}/include ${BF_FFMPEG}/include/msvc'
@@ -210,12 +208,6 @@ BF_RAYOPTIMIZATION_SSE_FLAGS = ['/arch:SSE']
#Freestyle
WITH_BF_FREESTYLE = True
WITH_BF_OPENSUBDIV = True
BF_OPENSUBDIV = LIBDIR + '/opensubdiv'
BF_OPENSUBDIV_INC = '${BF_OPENSUBDIV}/include'
BF_OPENSUBDIV_LIB = 'osdCPU osdGPU'
BF_OPENSUBDIV_LIBPATH = '${BF_OPENSUBDIV}/lib'
WITH_BF_STATICOPENGL = False
BF_OPENGL_INC = '${BF_OPENGL}/include'
BF_OPENGL_LIBINC = '${BF_OPENGL}/lib'

View File

@@ -22,8 +22,6 @@ BF_FFMPEG_LIBPATH = LIBDIR + '/ffmpeg/lib'
BF_FFMPEG_INC = LIBDIR + '/ffmpeg/include'
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_LIBPATH}/swresample-0.dll ${BF_FFMPEG_LIBPATH}/xvidcore.dll'
WITH_BF_AUDASPACE = True
WITH_BF_JACK = False
BF_JACK = LIBDIR + '/jack'
BF_JACK_INC = '${BF_JACK}/include'
@@ -146,7 +144,7 @@ BF_OPENCOLLADA_LIBPATH = '${BF_OPENCOLLADA}/lib/opencollada'
WITH_BF_CYCLES = True
WITH_BF_CYCLES_CUDA_BINARIES = False
BF_CYCLES_CUDA_NVCC = "" # Path to the NVIDIA CUDA compiler
BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_20', 'sm_21', 'sm_30', 'sm_35', 'sm_50', 'sm_52']
BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_20', 'sm_21', 'sm_30', 'sm_35', 'sm_50']
WITH_BF_OIIO = True
BF_OIIO = LIBDIR + '/openimageio'
@@ -167,12 +165,6 @@ BF_BOOST_LIB = 'boost_date_time-mgw47-mt-s-1_49 boost_date_time-mgw47-mt-sd-1_49
BF_BOOST_LIB_INTERNATIONAL = ' boost_locale-mgw47-mt-s-1_49 boost_locale-mgw47-mt-sd-1_49'
BF_BOOST_LIBPATH = '${BF_BOOST}/lib'
WITH_BF_OPENSUBDIV = False
BF_OPENSUBDIV = LIBDIR + '/opensubdiv'
BF_OPENSUBDIV_INC = '${BF_OPENSUBDIV}/include'
BF_OPENSUBDIV_LIB = 'osdCPU osdGPU'
BF_OPENSUBDIV_LIBPATH = '${BF_OPENSUBDIV}/lib'
#Ray trace optimization
WITH_BF_RAYOPTIMIZATION = True
BF_RAYOPTIMIZATION_SSE_FLAGS = ['-mmmx', '-msse', '-msse2']

View File

@@ -55,8 +55,6 @@ BF_SDL_INC = '${BF_SDL}/include'
BF_SDL_LIB = 'SDL2.lib'
BF_SDL_LIBPATH = '${BF_SDL}/lib'
WITH_BF_AUDASPACE = True
WITH_BF_JACK = False
BF_PTHREADS = LIBDIR + '/pthreads'
@@ -214,12 +212,6 @@ BF_RAYOPTIMIZATION_SSE_FLAGS = ['']
#Freestyle
WITH_BF_FREESTYLE = True
WITH_BF_OPENSUBDIV = True
BF_OPENSUBDIV = LIBDIR + '/opensubdiv'
BF_OPENSUBDIV_INC = '${BF_OPENSUBDIV}/include'
BF_OPENSUBDIV_LIB = 'osdCPU osdGPU'
BF_OPENSUBDIV_LIBPATH = '${BF_OPENSUBDIV}/lib'
WITH_BF_STATICOPENGL = False
BF_OPENGL_INC = '${BF_OPENGL}/include'
BF_OPENGL_LIBINC = '${BF_OPENGL}/lib'

View File

@@ -242,11 +242,6 @@ def setup_staticlibs(lenv):
if lenv['WITH_BF_STATIC3DMOUSE']:
statlibs += Split(lenv['BF_3DMOUSE_LIB_STATIC'])
if lenv['WITH_BF_OPENSUBDIV']:
libincs += Split(lenv['BF_OPENSUBDIV_LIBPATH'])
if lenv['WITH_BF_STATICOPENSUBDIV']:
statlibs += Split(lenv['BF_OPENSUBDIV_LIB_STATIC'])
# setting this last so any overriding of manually libs could be handled
if lenv['OURPLATFORM'] not in ('win32-vc', 'win32-mingw', 'win64-vc', 'linuxcross', 'win64-mingw'):
# We must remove any previous items defining this path, for same reason stated above!
@@ -349,13 +344,6 @@ def setup_syslibs(lenv):
if not lenv['WITH_BF_STATICPNG']:
syslibs += Split(lenv['BF_PNG_LIB'])
if lenv['WITH_BF_OPENSUBDIV']:
if not lenv['WITH_BF_STATICOPENSUBDIV']:
if lenv['BF_DEBUG'] and lenv['OURPLATFORM'] in ('win32-vc', 'win64-vc', 'win32-mingw', 'win64-mingw'):
syslibs += [osdlib+'_d' for osdlib in Split(lenv['BF_OPENSUBDIV_LIB'])]
else:
syslibs += Split(lenv['BF_OPENSUBDIV_LIB'])
# Hack to pass OSD libraries to linker before extern_{clew,cuew}
for syslib in create_blender_liblist(lenv, 'system'):
syslibs.append(os.path.basename(syslib))
@@ -384,7 +372,7 @@ def propose_priorities():
def creator(env):
sources = ['creator.c']# + Blender.buildinfo(env, "dynamic") + Blender.resources
incs = ['#/intern/guardedalloc', '#/source/blender/blenlib', '#/source/blender/blenkernel', '#/source/blender/depsgraph', '#/source/blender/editors/include', '#/source/blender/blenloader', '#/source/blender/imbuf', '#/source/blender/renderconverter', '#/source/blender/render/extern/include', '#/source/blender/windowmanager', '#/source/blender/makesdna', '#/source/blender/makesrna', '#/source/gameengine/BlenderRoutines', '#/extern/glew/include', '#/source/blender/gpu', env['BF_OPENGL_INC']]
incs = ['#/intern/guardedalloc', '#/source/blender/blenlib', '#/source/blender/blenkernel', '#/source/blender/editors/include', '#/source/blender/blenloader', '#/source/blender/imbuf', '#/source/blender/renderconverter', '#/source/blender/render/extern/include', '#/source/blender/windowmanager', '#/source/blender/makesdna', '#/source/blender/makesrna', '#/source/gameengine/BlenderRoutines', '#/extern/glew/include', '#/source/blender/gpu', env['BF_OPENGL_INC']]
defs = []
@@ -642,7 +630,7 @@ def WinPyBundle(target=None, source=None, env=None):
py_tar+= '/release/python' + env['BF_PYTHON_VERSION'].replace('.','') + '.tar.gz'
py_target = env.subst(env['BF_INSTALLDIR']).lstrip("#")
py_target = os.path.join(py_target, VERSION, 'python')
py_target = os.path.join(py_target, VERSION, 'python', 'lib')
def printexception(func,path,ex):
if os.path.exists(path): #do not report if path does not exist. eg on a fresh build.
print str(func) + ' failed on ' + str(path)
@@ -776,7 +764,7 @@ def AppIt(target=None, source=None, env=None):
commands.getoutput(cmd)
cmd = 'cp -R %s/kernel/*.h %s/kernel/*.cl %s/kernel/*.cu %s/kernel/' % (croot, croot, croot, cinstalldir)
commands.getoutput(cmd)
cmd = 'cp -R %s/kernel/svm %s/kernel/closure %s/kernel/geom %s/kernel/split %s/kernel/kernels %s/util/util_color.h %s/util/util_half.h %s/util/util_math.h %s/util/util_math_fast.h %s/util/util_transform.h %s/util/util_types.h %s/util/util_atomic.h %s/kernel/' % (croot, croot, croot, croot, croot, croot, croot, croot, croot, croot, croot, croot, cinstalldir)
cmd = 'cp -R %s/kernel/svm %s/kernel/closure %s/kernel/geom %s/util/util_color.h %s/util/util_half.h %s/util/util_math.h %s/util/util_math_fast.h %s/util/util_transform.h %s/util/util_types.h %s/kernel/' % (croot, croot, croot, croot, croot, croot, croot, croot, croot, cinstalldir)
commands.getoutput(cmd)
cmd = 'cp -R %s/../intern/cycles/kernel/*.cubin %s/lib/' % (builddir, cinstalldir)
commands.getoutput(cmd)
@@ -796,8 +784,6 @@ def AppIt(target=None, source=None, env=None):
commands.getoutput(cmd)
cmd = 'cp -R %s/release/site-packages/ %s/%s.app/Contents/Resources/%s/python/lib/python%s/site-packages/'%(libdir,installdir,binary,VERSION,env['BF_PYTHON_VERSION'])
commands.getoutput(cmd)
cmd = 'cp -r %s/python/bin -d %s/%s.app/Contents/Resources/%s/python/'%(libdir,installdir,binary,VERSION)
commands.getoutput(cmd)
cmd = 'chmod +x %s/%s.app/Contents/MacOS/%s'%(installdir,binary, binary)
commands.getoutput(cmd)
@@ -857,7 +843,6 @@ def UnixPyBundle(target=None, source=None, env=None):
py_src = env.subst( env['BF_PYTHON_LIBPATH'] + '/python'+env['BF_PYTHON_VERSION'] )
py_target = env.subst( dir + '/python/' + target_lib + '/python'+env['BF_PYTHON_VERSION'] )
py_target_bin = env.subst(dir + '/python/bin')
# This is a bit weak, but dont install if its been installed before, makes rebuilds quite slow.
if os.path.exists(py_target):
@@ -877,11 +862,6 @@ def UnixPyBundle(target=None, source=None, env=None):
except:
pass
# install the executable
run("rm -rf '%s'" % py_target_bin)
os.makedirs(py_target_bin)
run("cp '%s' '%s'" % (env.subst(env['BF_PYTHON_BINARY']), py_target_bin))
run("cp -R '%s' '%s'" % (py_src, os.path.dirname(py_target)))
run("rm -rf '%s/distutils'" % py_target)
run("rm -rf '%s/lib2to3'" % py_target)

View File

@@ -107,7 +107,6 @@ def print_arguments(args, bc):
def validate_arguments(args, bc):
opts_list = [
'WITH_BF_FREESTYLE', 'WITH_BF_PYTHON', 'WITH_BF_PYTHON_SAFETY', 'WITH_BF_PYTHON_SECURITY', 'BF_PYTHON', 'BF_PYTHON_VERSION', 'BF_PYTHON_INC', 'BF_PYTHON_BINARY', 'BF_PYTHON_LIB', 'BF_PYTHON_LIBPATH', 'BF_PYTHON_LIBPATH_ARCH', 'WITH_BF_STATICPYTHON', 'WITH_OSX_STATICPYTHON', 'BF_PYTHON_LIB_STATIC', 'BF_PYTHON_DLL', 'BF_PYTHON_ABI_FLAGS',
'WITH_BF_AUDASPACE', 'BF_AUDASPACE_C_INC', 'BF_AUDASPACE_PY_INC', 'BF_AUDASPACE_DEF',
'WITH_BF_OPENAL', 'BF_OPENAL', 'BF_OPENAL_INC', 'BF_OPENAL_LIB', 'BF_OPENAL_LIBPATH', 'WITH_BF_STATICOPENAL', 'BF_OPENAL_LIB_STATIC',
'WITH_BF_SDL', 'BF_SDL', 'BF_SDL_INC', 'BF_SDL_LIB', 'BF_SDL_LIBPATH', 'WITH_BF_SDL_DYNLOAD',
'WITH_BF_JACK', 'BF_JACK', 'BF_JACK_INC', 'BF_JACK_LIB', 'BF_JACK_LIBPATH', 'WITH_BF_JACK_DYNLOAD',
@@ -183,8 +182,7 @@ def validate_arguments(args, bc):
'WITH_BF_BOOST', 'WITH_BF_STATICBOOST', 'BF_BOOST', 'BF_BOOST_INC', 'BF_BOOST_LIB', 'BF_BOOST_LIB_INTERNATIONAL', 'BF_BOOST_LIB_STATIC', 'BF_BOOST_LIBPATH',
'WITH_BF_LIBMV', 'WITH_BF_LIBMV_SCHUR_SPECIALIZATIONS',
'WITH_BF_CYCLES_OSL', 'WITH_BF_STATICOSL', 'BF_OSL', 'BF_OSL_INC', 'BF_OSL_LIB', 'BF_OSL_LIBPATH', 'BF_OSL_LIB_STATIC', 'BF_OSL_COMPILER',
'WITH_BF_LLVM', 'WITH_BF_STATICLLVM', 'BF_LLVM', 'BF_LLVM_LIB', 'BF_LLVM_LIBPATH', 'BF_LLVM_LIB_STATIC', 'BF_PROGRAM_LINKFLAGS',
'WITH_BF_OPENSUBDIV', 'WITH_BF_STATICOPENSUBDIV', 'BF_OPENSUBDIV', 'BF_OPENSUBDIV_INC', 'BF_OPENSUBDIV_LIB', 'BF_OPENSUBDIV_LIBPATH', 'BF_OPENSUBDIV_LIB_STATIC'
'WITH_BF_LLVM', 'WITH_BF_STATICLLVM', 'BF_LLVM', 'BF_LLVM_LIB', 'BF_LLVM_LIBPATH', 'BF_LLVM_LIB_STATIC', 'BF_PROGRAM_LINKFLAGS'
]
# Have options here that scons expects to be lists
@@ -201,7 +199,7 @@ def validate_arguments(args, bc):
'LLIBS', 'PLATFORM_LINKFLAGS', 'MACOSX_ARCHITECTURE', 'MACOSX_SDK', 'XCODE_CUR_VER', 'C_COMPILER_ID',
'BF_CYCLES_CUDA_BINARIES_ARCH', 'BF_PROGRAM_LINKFLAGS', 'MACOSX_DEPLOYMENT_TARGET',
'WITH_BF_CYCLES_DEBUG', 'WITH_BF_CYCLES_LOGGING',
'WITH_BF_CPP11', 'WITH_BF_LEGACY_DEPSGRAPH',
'WITH_BF_CPP11'
]
@@ -299,11 +297,6 @@ def read_opts(env, cfg, args):
('BF_OPENAL_LIBPATH', 'Path to OpenAL library', ''),
(BoolVariable('WITH_BF_STATICOPENAL', 'Staticly link to openal', False)),
(BoolVariable('WITH_BF_AUDASPACE', 'Build with audaspace if true', True)),
('BF_AUDASPACE_C_INC', 'audaspace-c include path', ''),
('BF_AUDASPACE_PY_INC', 'audaspace-py include path', ''),
('BF_AUDASPACE_DEF', 'audaspace defines', ''),
(BoolVariable('WITH_BF_SDL', 'Use SDL if true', False)),
('BF_SDL', 'SDL base path', ''),
('BF_SDL_INC', 'SDL include path', ''),
@@ -663,17 +656,7 @@ def read_opts(env, cfg, args):
('BF_PROGRAM_LINKFLAGS', 'Link flags applied only to final binaries (blender and blenderplayer, not makesrna/makesdna)', ''),
(BoolVariable('WITH_BF_OPENSUBDIV', 'Build with OpenSubdiv library', False)),
(BoolVariable('WITH_BF_STATICOPENSUBDIV', 'Staticly link to OpenColorIO', False)),
('BF_OPENSUBDIV', 'OpenSubdiv root path', ''),
('BF_OPENSUBDIV_INC', 'OpenSubdiv include path', ''),
('BF_OPENSUBDIV_LIB', 'OpenSubdiv library', ''),
('BF_OPENSUBDIV_LIBPATH', 'OpenSubdiv library path', ''),
('BF_OPENSUBDIV_LIB_STATIC', 'OpenSubdiv static library', ''),
(BoolVariable('WITH_BF_CPP11', '"Build with C++11 standard enabled, for development use only!', False)),
(BoolVariable('WITH_BF_LEGACY_DEPSGRAPH', 'Build Blender with legacy dependency graph', True)),
) # end of opts.AddOptions()
return localopts

104
doc/build_systems/cmake.txt Normal file
View File

@@ -0,0 +1,104 @@
Blender CMake build system
============================
Contents
---------------
1. Introduction
2. Obtaining CMake
3. Building Blender
4. Generic Setup
5. Configuring the build after SVN updates
1. Introduction
---------------
This document describes general usage of the new CMake scripts. The
inner workings will be described in blender-cmake-dev.txt (TODO).
2. Obtaining CMake
------------------
CMake for can either be downloaded using your favorite package manager
or is also available from the CMake website at http://www.cmake.org
The website also contains some documentation on CMake usage but I found
the man page alone pretty helpful.
3. Building Blender
-------------------
Building Blender requires obtaining a compiler, library dependencies,
and correct setup depending on the system. For details on how to set
up a build on various operating systems, see the wiki documentation:
http://wiki.blender.org/index.php/Dev:Doc/Building_Blender
4. Generic Setup
----------------
CMake allows one to generate the build project files and binary objects
outside the source tree which can be pretty handy in working and experimenting
with different Blender configurations (Audio/NoAudio, GameEngine/NoGameEngine etc.)
while maintaining a clean source tree. It also makes it possible to generate files
for different build systems on the same source tree. This also has benefits for
general SVN management for the developer as patches and submit logs are much cleaner.
Create a directory outside the blender source tree where you would like to build
Blender (from now on called $BLENDERBUILD). On the commandline you can then run
the cmake command to generate your initial build files. First just run 'cmake' which
will inform you what the available generators are. Thn you can run
'cmake -G generator $BLENDERSOURCE' to generate the build files. Here is an example
of all this for Xcode:
% mkdir $BLENDERBUILD
% cd $BLENDERBUILD
% cmake
...
...
--version [file] = Show program name/version banner and exit.
Generators
The following generators are available on this platform:
KDevelop3 = Generates KDevelop 3 project files.
Unix Makefiles = Generates standard UNIX makefiles.
Xcode = Generate XCode project files.
% cmake -G Xcode $BLENDERSOURCE
...
...
-- Configuring blender
-- Configuring blenderplayer
-- Configuring done
-- Generating done
-- Build files have been written to: $BLENDERBUILD
This will generate the build files with default values. Specific features can
be enabled or disabled by running the ccmake "GUI" from $BLENDERBUILD as follows:
% ccmake $BLENDERSOURCE
A number of options appear which can be changed depending on your needs and
available dependencies (e.g. setting WITH_OPENEXR to OFF will disable support
for OpenEXR). It will also allow you to override default and detected paths
(e.g. Python directories) and compile and link flags. When you are satisfied
used ccmake to re-configure the build files and exit.
It is also possible to use the commandline of 'cmake' to override certain
of these settings.
5. Configuring the build after SVN updates
------------------------------------------
The $BLENDERBUILD directory maintains a file called CMakeCache.txt which
remembers the initial run's settings for subsequent generation runs. After
SVN updates that contain changes to the build system, rebuilding Blender will
automatically invoke CMake to regenerate the CMakeCache.txt and other files
as needed.
/Jacques Beaurain (jbinto)

File diff suppressed because it is too large Load Diff

View File

@@ -10,14 +10,26 @@
* \ingroup intern
*/
/** \defgroup boolop boolop
* \ingroup intern
*/
/** \defgroup ctr container
* \ingroup intern
*/
/** \defgroup decimation decimation
* \ingroup intern
*/
/** \defgroup elbeem elbeem
* \ingroup intern
*/
/** \defgroup bsp bsp
* \ingroup intern
*/
/** \defgroup iksolver iksolver
* \ingroup intern
*/

View File

@@ -7,7 +7,7 @@
* These pages document the source code of blender.
*
* \subsection implinks Important Links
* - <a href="http://developer.blender.org">developer.blender.org</a> with bug tracker.
* - <a href="http://developer.blender.org">developer.blender.org</a> with bug tracker
* - <a href="http://wiki.blender.org/index.php/Dev:Contents">Development documents</a> on our wiki.
*
* \subsection blother Other

View File

@@ -11,6 +11,7 @@
/** \defgroup bmesh BMesh
* \ingroup blender
*/
/** \defgroup texture Texturing */
/** \defgroup compositor Compositing */
/** \defgroup python Python
@@ -92,48 +93,36 @@
/* ================================ */
/** \defgroup blender Blender */
/** \defgroup blender blender */
/** \defgroup blt BlenTranslation
/** \defgroup blf blenfont
* \ingroup blender
*/
/** \defgroup blf BlenFont
/** \defgroup bke blenkernel
* \ingroup blender
*/
/** \defgroup bke BlenKernel
/** \defgroup bli blenlib
* \ingroup blender
*/
/** \defgroup bli BlenLib
/** \defgroup nodes nodes
* \ingroup blender
*/
/** \defgroup depsgraph Dependency Graph
* \ingroup blender
*/
/** \defgroup bph Physics
* \ingroup blender
*/
/** \defgroup nodes Nodes
* \ingroup blender
*/
/** \defgroup cmpnodes Nodes (Compositor)
/** \defgroup cmpnodes cmpnodes
* \ingroup nodes
*/
/** \defgroup shdnodes Nodes (Shader)
/** \defgroup shdnodes shdnodes
* \ingroup nodes
*/
/** \defgroup texnodes Nodes (Texture)
/** \defgroup texnodes texnodes
* \ingroup nodes
*/
/** \defgroup modifiers Object Modifiers
/** \defgroup modifiers modifiers
* \ingroup blender
*/
@@ -143,29 +132,29 @@
* \ingroup blender
*/
/** \defgroup ikplugin IK Plugin
/** \defgroup ikplugin ikplugin
* \ingroup blender
*/
/** \defgroup DNA Struct DNA (File Format)
/** \defgroup DNA sDNA
* \ingroup blender data
*/
/** \defgroup RNA RNA (Data API)
/** \defgroup RNA RNA
* \ingroup blender data
*/
/** \defgroup blenloader Blend file IO
/** \defgroup blenloader .blend read and write functions
* \ingroup blender data
* \todo check if \ref blo and \ref blenloader groups can be
* merged in docs.
*/
/** \defgroup quicktime QuickTime
/** \defgroup quicktime quicktime
* \ingroup blender
/** \defgroup gui GUI */
/** \defgroup wm Window Manager
/** \defgroup wm windowmanager
* \ingroup blender gui
*/
@@ -325,7 +314,7 @@
* \ingroup gui
*/
/** \defgroup externformats External Formats */
/** \defgroup externformats external formats */
/** \defgroup collada COLLADA
* \ingroup externformats
@@ -335,7 +324,7 @@
* \ingroup externformats
*/
/** \defgroup imbuf Image Buffer (ImBuf)
/** \defgroup imbuf IMage Buffer
* \ingroup blender
*/

View File

@@ -1,7 +1,6 @@
"""
Basic Sound Playback
++++++++++++++++++++
This script shows how to use the classes: :class:`Device`, :class:`Factory` and
:class:`Handle`.
"""

View File

@@ -1,10 +1,9 @@
"""
Texture Replacement
+++++++++++++++++++
Example of how to replace a texture in game with an external image.
``createTexture()`` and ``removeTexture()`` are to be called from a
module Python Controller.
createTexture() and removeTexture() are to be called from a module Python
Controller.
"""
from bge import logic
from bge import texture

View File

@@ -1,8 +1,7 @@
"""
Basic Video Playback
++++++++++++++++++++
Example of how to replace a texture in game with a video. It needs to run
everyframe.
Example of how to replace a texture in game with a video. It needs to run everyframe
"""
import bge
from bge import texture

View File

@@ -1,7 +1,6 @@
"""
Basic Handler Example
+++++++++++++++++++++
This script shows the most simple example of adding a handler.
"""

View File

@@ -7,9 +7,8 @@ act on specified rather than the selected or active data, or to execute an
operator in the different part of the user interface.
The context overrides are passed as a dictionary, with keys matching the context
member names in bpy.context.
For example to override ``bpy.context.active_object``,
you would pass ``{'active_object': object}``.
member names in bpy.context. For example to override bpy.context.active_object,
you would pass {'active_object': object}.
"""
# remove all objects in scene rather than the selected ones

View File

@@ -1,6 +1,6 @@
"""
.. _operator-execution_context:
"""
Execution Context
-----------------

View File

@@ -3,21 +3,21 @@ Calling Operators
-----------------
Provides python access to calling operators, this includes operators written in
C, Python or macros.
C, Python or Macros.
Only keyword arguments can be used to pass operator properties.
Operators don't have return values as you might expect,
instead they return a set() which is made up of:
``{'RUNNING_MODAL', 'CANCELLED', 'FINISHED', 'PASS_THROUGH'}``.
Common return values are ``{'FINISHED'}`` and ``{'CANCELLED'}``.
Operators don't have return values as you might expect, instead they return a
set() which is made up of: {'RUNNING_MODAL', 'CANCELLED', 'FINISHED',
'PASS_THROUGH'}.
Common return values are {'FINISHED'} and {'CANCELLED'}.
Calling an operator in the wrong context will raise a ``RuntimeError``,
Calling an operator in the wrong context will raise a RuntimeError,
there is a poll() method to avoid this problem.
Note that the operator ID (bl_idname) in this example is ``mesh.subdivide``,
``bpy.ops`` is just the access path for python.
Note that the operator ID (bl_idname) in this example is 'mesh.subdivide',
'bpy.ops' is just the access path for python.
Keywords and Positional Arguments
@@ -32,9 +32,9 @@ There are 3 optional positional arguments (documented in detail below).
bpy.ops.test.operator(override_context, execution_context, undo)
- override_context - ``dict`` type.
- execution_context - ``str`` (enum).
- undo - ``bool`` type.
* override_context - dict type
* execution_context - string (enum)
* undo - boolean
Each of these arguments is optional, but must be given in the order above.

View File

@@ -8,8 +8,7 @@ bl_info = {
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Object",
}
"category": "Object"}
import bpy

View File

@@ -1,7 +1,6 @@
"""
Submenus
++++++++
This menu demonstrates some different functions.
"""
import bpy

View File

@@ -1,7 +1,6 @@
"""
Extending Menus
+++++++++++++++
When creating menus for addons you can't reference menus in Blender's default
scripts.
Instead, the addon can add menu items to existing menus.

View File

@@ -1,7 +1,6 @@
"""
Basic Menu Example
++++++++++++++++++
Here is an example of a simple menu. Menus differ from panels in that they must
reference from a header, panel or another menu.

View File

@@ -7,10 +7,10 @@ for more flexible mesh editing from python see :mod:`bmesh`.
Blender stores 4 main arrays to define mesh geometry.
- :class:`Mesh.vertices` (3 points in space)
- :class:`Mesh.edges` (reference 2 vertices)
- :class:`Mesh.loops` (reference a single vertex and edge)
- :class:`Mesh.polygons`: (reference a range of loops)
* :class:`Mesh.vertices` (3 points in space)
* :class:`Mesh.edges` (reference 2 vertices)
* :class:`Mesh.loops` (reference a single vertex and edge)
* :class:`Mesh.polygons`: (reference a range of loops)
Each polygon reference a slice in the loop array, this way, polygons do not store vertices or corner data such as UV's directly,

View File

@@ -1,7 +1,6 @@
"""
Poll Function
+++++++++++++++
The :class:`NodeTree.poll` function determines if a node tree is visible
in the given context (similar to how :class:`Panel.poll`
and :class:`Menu.poll` define visibility). If it returns False,

View File

@@ -1,7 +1,6 @@
"""
Basic Object Operations Example
+++++++++++++++++++++++++++++++
This script demonstrates basic operations on object like creating new
object, placing it into scene, selecting it and making it active.
"""

View File

@@ -1,7 +1,6 @@
"""
Invoke Function
+++++++++++++++
:class:`Operator.invoke` is used to initialize the operator from the context
at the moment the operator is called.
invoke() is typically used to assign properties which are then used by
@@ -32,7 +31,7 @@ class SimpleMouseOperator(bpy.types.Operator):
y = bpy.props.IntProperty()
def execute(self, context):
# rather than printing, use the report function,
# rather then printing, use the report function,
# this way the message appears in the header,
self.report({'INFO'}, "Mouse coords are %d %d" % (self.x, self.y))
return {'FINISHED'}

View File

@@ -4,7 +4,7 @@ Calling a File Selector
This example shows how an operator can use the file selector.
Notice the invoke function calls a window manager method and returns
``{'RUNNING_MODAL'}``, this means the file selector stays open and the operator does not
RUNNING_MODAL, this means the file selector stays open and the operator does not
exit immediately after invoke finishes.
The file selector runs the operator, calling :class:`Operator.execute` when the

View File

@@ -1,7 +1,6 @@
"""
Dialog Box
++++++++++
This operator uses its :class:`Operator.invoke` function to call a popup.
"""
import bpy

View File

@@ -1,7 +1,6 @@
"""
Custom Drawing
++++++++++++++
By default operator properties use an automatic user interface layout.
If you need more control you can create your own layout with a
:class:`Operator.draw` function.

View File

@@ -1,9 +1,8 @@
"""
Modal Execution
+++++++++++++++
This operator defines a :class:`Operator.modal` function which running,
handling events until it returns ``{'FINISHED'}`` or ``{'CANCELLED'}``.
handling events until it returns {'FINISHED'} or {'CANCELLED'}.
Grab, Rotate, Scale and Fly-Mode are examples of modal operators.
They are especially useful for interactive tools,
@@ -11,9 +10,9 @@ your operator can have its own state where keys toggle options as the operator
runs.
:class:`Operator.invoke` is used to initialize the operator as being by
returning ``{'RUNNING_MODAL'}``, initializing the modal loop.
returning {'RUNNING_MODAL'}, initializing the modal loop.
Notice ``__init__()`` and ``__del__()`` are declared.
Notice __init__() and __del__() are declared.
For other operator types they are not useful but for modal operators they will
be called before the :class:`Operator.invoke` and after the operator finishes.
"""

View File

@@ -1,7 +1,6 @@
"""
Basic Operator Example
++++++++++++++++++++++
This script shows simple operator which prints a message.
Since the operator only has an :class:`Operator.execute` function it takes no

View File

@@ -1,7 +1,6 @@
"""
Simple Object Panel
+++++++++++++++++++
This panel has a :class:`Panel.poll` and :class:`Panel.draw_header` function,
even though the contents is basic this closely resembles blenders panels.
"""

View File

@@ -1,7 +1,6 @@
"""
Basic Panel Example
+++++++++++++++++++
This script is a simple panel which will draw into the object properties
section.

View File

@@ -1,8 +1,7 @@
"""
Advanced UIList Example - Filtering and Reordering
++++++++++++++++++++++++++++++++++++++++++++++++++
This script is an extended version of the ``UIList`` subclass used to show vertex groups. It is not used 'as is',
This script is an extended version of the UIList subclass used to show vertex groups. It is not used 'as is',
because iterating over all vertices in a 'draw' function is a very bad idea for UI performances! However, it's a good
example of how to create/use filtering/reordering callbacks.
"""

View File

@@ -1,7 +1,7 @@
"""
Note that when keying data paths which contain nested properties this must be
done from the :class:`ID` subclass, in this case the :class:`Armature` rather
than the bone.
then the bone.
"""
import bpy

View File

@@ -1,192 +0,0 @@
# Draws an off-screen buffer and display it in the corner of the view.
import bpy
from bgl import *
class OffScreenDraw(bpy.types.Operator):
bl_idname = "view3d.offscreen_draw"
bl_label = "View3D Offscreen Draw"
_handle_calc = None
_handle_draw = None
is_enabled = False
# manage draw handler
@staticmethod
def draw_callback_px(self, context):
scene = context.scene
aspect_ratio = scene.render.resolution_x / scene.render.resolution_y
self._update_offscreen(context, self._offscreen)
self._opengl_draw(context, self._texture, aspect_ratio, 0.2)
@staticmethod
def handle_add(self, context):
OffScreenDraw._handle_draw = bpy.types.SpaceView3D.draw_handler_add(
self.draw_callback_px, (self, context),
'WINDOW', 'POST_PIXEL',
)
@staticmethod
def handle_remove():
if OffScreenDraw._handle_draw is not None:
bpy.types.SpaceView3D.draw_handler_remove(OffScreenDraw._handle_draw, 'WINDOW')
OffScreenDraw._handle_draw = None
# off-screen buffer
@staticmethod
def _setup_offscreen(context):
import gpu
scene = context.scene
aspect_ratio = scene.render.resolution_x / scene.render.resolution_y
try:
offscreen = gpu.offscreen.new(512, int(512 / aspect_ratio))
except Exception as e:
print(e)
offscreen = None
return offscreen
@staticmethod
def _update_offscreen(context, offscreen):
scene = context.scene
render = scene.render
camera = scene.camera
modelview_matrix = camera.matrix_world.inverted()
projection_matrix = camera.calc_matrix_camera(
render.resolution_x,
render.resolution_y,
render.pixel_aspect_x,
render.pixel_aspect_y,
)
offscreen.draw_view3d(
scene,
context.space_data,
context.region,
projection_matrix,
modelview_matrix,
)
@staticmethod
def _opengl_draw(context, texture, aspect_ratio, scale):
"""
OpenGL code to draw a rectangle in the viewport
"""
glDisable(GL_DEPTH_TEST)
# view setup
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
glOrtho(-1, 1, -1, 1, -15, 15)
gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
act_tex = Buffer(GL_INT, 1)
glGetIntegerv(GL_TEXTURE_2D, act_tex)
viewport = Buffer(GL_INT, 4)
glGetIntegerv(GL_VIEWPORT, viewport)
width = int(scale * viewport[2])
height = int(width / aspect_ratio)
glViewport(viewport[0], viewport[1], width, height)
glScissor(viewport[0], viewport[1], width, height)
# draw routine
glEnable(GL_TEXTURE_2D)
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, texture)
texco = [(1, 1), (0, 1), (0, 0), (1, 0)]
verco = [(1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), (1.0, -1.0)]
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
glColor4f(1.0, 1.0, 1.0, 1.0)
glBegin(GL_QUADS)
for i in range(4):
glTexCoord3f(texco[i][0], texco[i][1], 0.0)
glVertex2f(verco[i][0], verco[i][1])
glEnd()
# restoring settings
glBindTexture(GL_TEXTURE_2D, act_tex[0])
glDisable(GL_TEXTURE_2D)
# reset view
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
glViewport(viewport[0], viewport[1], viewport[2], viewport[3])
glScissor(viewport[0], viewport[1], viewport[2], viewport[3])
# operator functions
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D'
def modal(self, context, event):
if context.area:
context.area.tag_redraw()
return {'PASS_THROUGH'}
def invoke(self, context, event):
if OffScreenDraw.is_enabled:
self.cancel(context)
return {'FINISHED'}
else:
self._offscreen = OffScreenDraw._setup_offscreen(context)
if self._offscreen:
self._texture = self._offscreen.color_texture
else:
self.report({'ERROR'}, "Error initializing offscreen buffer. More details in the console")
return {'CANCELLED'}
OffScreenDraw.handle_add(self, context)
OffScreenDraw.is_enabled = True
if context.area:
context.area.tag_redraw()
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
def cancel(self, context):
OffScreenDraw.handle_remove()
OffScreenDraw.is_enabled = False
if context.area:
context.area.tag_redraw()
def register():
bpy.utils.register_class(OffScreenDraw)
def unregister():
bpy.utils.unregister_class(OffScreenDraw)
if __name__ == "__main__":
register()

View File

@@ -1,47 +0,0 @@
Application Data (bge.app)
==========================
Module to access application values that remain unchanged during runtime.
.. module:: bge.app
.. data:: version
The Blender/BGE version as a tuple of 3 ints, eg. (2, 75, 1).
.. note:: Version tuples can be compared simply with (in)equality symbols;
for example, ``(2, 74, 5) <= (2, 75, 0)`` returns True (lexical order).
:type: tuple of three ints
.. data:: version_string
The Blender/BGE version formatted as a string, eg. "2.75 (sub 1)".
:type: str
.. data:: version_char
The Blender/BGE version character (for minor releases).
:type: str
.. data:: has_texture_ffmpeg
True if the BGE has been built with FFmpeg support, enabling use of :class:`~bge.texture.ImageFFmpeg` and :class:`~bge.texture.VideoFFmpeg`.
:type: bool
.. data:: has_joystick
True if the BGE has been built with joystick support.
:type: bool
.. data:: has_physics
True if the BGE has been built with physics support.
:type: bool

View File

@@ -4,77 +4,73 @@ Physics Constraints (bge.constraints)
.. module:: bge.constraints
Examples
--------
.. include:: ../examples/bge.constraints.py
:start-line: 1
:end-line: 4
.. literalinclude:: ../examples/bge.constraints.py
:language: rest
:lines: 2-4
.. literalinclude:: ../examples/bge.constraints.py
:lines: 6-
Functions
---------
.. function:: createConstraint( \
physicsid_1, physicsid_2, constraint_type, \
pivot_x=0.0, pivot_y=0.0, pivot_z=0.0, \
axis_x=0.0, axis_y=0.0, axis_z=0.0, flag=0)
.. function:: createConstraint(physicsid_1, physicsid_2, constraint_type, pivot_X, pivot_y, pivot_z, axis_x, axis_y, axis_z, flag)
Creates a constraint.
:arg physicsid_1: The physics id of the first object in constraint.
:type physicsid_1: int
:arg physicsid_1: the physics id of the first object in constraint
:type physicsid: int
:arg physicsid_2: The physics id of the second object in constraint.
:type physicsid_2: int
:arg physicsid_2: the physics id of the second object in constraint
:type physicsid2: int
:arg constraint_type: The type of the constraint, see `Create Constraint Constants`_.
:arg constrainttype: the type of the constraint. The constraint types are:
:type constrainttype: int
- :class:`POINTTOPOINT_CONSTRAINT`
- :class:`LINEHINGE_CONSTRAINT`
- :class:`ANGULAR_CONSTRAINT`
- :class:`CONETWIST_CONSTRAINT`
- :class:`VEHICLE_CONSTRAINT`
- :class:`GENERIC_6DOF_CONSTRAINT`
:arg pivot_X: pivot X position
:type pivot_X: float (optional)
:type constraint_type: int
:arg pivot_Y: pivot Y position
:type pivot_Y: float (optional)
:arg pivot_x: Pivot X position. (optional)
:type pivot_x: float
:arg pivot_Z: pivot Z position
:type pivot_Z: float (optional)
:arg pivot_y: Pivot Y position. (optional)
:type pivot_y: float
:arg axis_X: X axis angle in degrees
:type axis_X: float (optional)
:arg pivot_z: Pivot Z position. (optional)
:type pivot_z: float
:arg axis_Y: Y axis angle in degrees
:type axis_Y: float (optional)
:arg axis_x: X axis angle in degrees. (optional)
:type axis_x: float
:arg axis_Z: Z axis angle in degrees
:type axis_Z: float (optional)
:arg axis_y: Y axis angle in degrees. (optional)
:type axis_y: float
:arg flag: 128 to disable collision between linked bodies
:type flag: int (optional)
:arg axis_z: Z axis angle in degrees. (optional)
:type axis_z: float
:return: a constraint wrapper.
:rtype: :class:`bge.types.KX_ConstraintWrapper`
:arg flag: 128 to disable collision between linked bodies. (optional)
:type flag: int
.. attribute:: error
:return: A constraint wrapper.
:rtype: :class:`~bge.types.KX_ConstraintWrapper`
Symbolic constant string that indicates error.
.. function:: exportBulletFile(filename)
Exports a file representing the dynamics world (usually using ``.bullet`` extension).
export a .bullet file
See `Bullet binary serialization <http://bulletphysics.org/mediawiki-1.5.8/index.php/Bullet_binary_serialization>`__.
:arg filename: File path.
:type filename: str
:arg filename: File name
:type filename: string
.. function:: getAppliedImpulse(constraintId)
:arg constraintId: The id of the constraint.
:type constraintId: int
:return: The most recent applied impulse.
:return: the most recent applied impulse.
:rtype: float
.. function:: getVehicleConstraint(constraintId)
@@ -82,16 +78,16 @@ Functions
:arg constraintId: The id of the vehicle constraint.
:type constraintId: int
:return: A vehicle constraint object.
:rtype: :class:`~bge.types.KX_VehicleWrapper`
:return: a vehicle constraint object.
:rtype: :class:`bge.types.KX_VehicleWrapper`
.. function:: getCharacter(gameobj)
:arg gameobj: The game object with the character physics.
:type gameobj: :class:`~bge.types.KX_GameObject`
:type gameobj: :class:`bge.types.KX_GameObject`
:return: Character wrapper.
:rtype: :class:`~bge.types.KX_CharacterWrapper`
:return: character wrapper
:rtype: :class:`bge.types.KX_CharacterWrapper`
.. function:: removeConstraint(constraintId)
@@ -145,8 +141,23 @@ Functions
Sets the debug mode.
:arg mode: The new debug mode, see `Debug Mode Constants`_.
Debug modes:
- :class:`DBG_NODEBUG`
- :class:`DBG_DRAWWIREFRAME`
- :class:`DBG_DRAWAABB`
- :class:`DBG_DRAWFREATURESTEXT`
- :class:`DBG_DRAWCONTACTPOINTS`
- :class:`DBG_NOHELPTEXT`
- :class:`DBG_DRAWTEXT`
- :class:`DBG_PROFILETIMINGS`
- :class:`DBG_ENABLESATCOMPARISION`
- :class:`DBG_DISABLEBULLETLCP`
- :class:`DBG_ENABLECCD`
- :class:`DBG_DRAWCONSTRAINTS`
- :class:`DBG_DRAWCONSTRAINTLIMITS`
- :class:`DBG_FASTWIREFRAME`
:arg mode: The new debug mode.
:type mode: int
.. function:: setGravity(x, y, z)
@@ -165,8 +176,7 @@ Functions
.. function:: setLinearAirDamping(damping)
.. note::
Not implemented
Not implemented.
Sets the linear air damping for rigidbodies.
@@ -226,111 +236,144 @@ Functions
.. function:: setUseEpa(epa)
.. note::
Not implemented
Constants
+++++++++
.. attribute:: error
Symbolic constant string that indicates error.
:type: str
Debug Mode Constants
^^^^^^^^^^^^^^^^^^^^
Debug mode to be used with :func:`setDebugMode`.
Not implemented.
.. data:: DBG_NODEBUG
.. note::
Debug mode to be used with function :class:`setDebugMode`
No debug.
.. data:: DBG_DRAWWIREFRAME
.. note::
Debug mode to be used with function :class:`setDebugMode`
Draw wireframe in debug.
.. data:: DBG_DRAWAABB
.. note::
Debug mode to be used with function :class:`setDebugMode`
Draw Axis Aligned Bounding Box in debug.
.. data:: DBG_DRAWFREATURESTEXT
Draw features text in debug.
.. note::
Debug mode to be used with function :class:`setDebugMode`
Draw freatures text in debug.
.. data:: DBG_DRAWCONTACTPOINTS
.. note::
Debug mode to be used with function :class:`setDebugMode`
Draw contact points in debug.
.. data:: DBG_NOHELPTEXT
.. note::
Debug mode to be used with function :class:`setDebugMode`
Debug without help text.
.. data:: DBG_DRAWTEXT
.. note::
Debug mode to be used with function :class:`setDebugMode`
Draw text in debug.
.. data:: DBG_PROFILETIMINGS
.. note::
Debug mode to be used with function :class:`setDebugMode`
Draw profile timings in debug.
.. data:: DBG_ENABLESATCOMPARISION
.. note::
Debug mode to be used with function :class:`setDebugMode`
Enable sat comparision in debug.
.. data:: DBG_DISABLEBULLETLCP
.. note::
Debug mode to be used with function :class:`setDebugMode`
Disable Bullet LCP.
.. data:: DBG_ENABLECCD
Enable Continous Collision Detection in debug.
.. note::
Debug mode to be used with function :class:`setDebugMode`
Enable Continous Colision Detection in debug.
.. data:: DBG_DRAWCONSTRAINTS
.. note::
Debug mode to be used with function :class:`setDebugMode`
Draw constraints in debug.
.. data:: DBG_DRAWCONSTRAINTLIMITS
.. note::
Debug mode to be used with function :class:`setDebugMode`
Draw constraint limits in debug.
.. data:: DBG_FASTWIREFRAME
.. note::
Debug mode to be used with function :class:`setDebugMode`
Draw a fast wireframe in debug.
Create Constraint Constants
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Constraint type to be used with :func:`createConstraint`.
.. data:: POINTTOPOINT_CONSTRAINT
.. note::
Constraint type to be used with function :class:`createConstraint`
.. to do
.. data:: LINEHINGE_CONSTRAINT
.. note::
Constraint type to be used with function :class:`createConstraint`
.. to do
.. data:: ANGULAR_CONSTRAINT
.. note::
Constraint type to be used with function :class:`createConstraint`
.. to do
.. data:: CONETWIST_CONSTRAINT
.. note::
Constraint type to be used with function :class:`createConstraint`
.. to do
.. data:: VEHICLE_CONSTRAINT
.. note::
Constraint type to be used with function :class:`createConstraint`
.. to do
.. data:: GENERIC_6DOF_CONSTRAINT
.. to do
.. note::
Constraint type to be used with function :class:`createConstraint`
.. to do

View File

@@ -258,8 +258,7 @@ General functions
Sets the world gravity.
:arg gravity: gravity vector
:type gravity: Vector((fx, fy, fz))
:type gravity: list [fx, fy, fz]
.. function:: getSpectrum()
@@ -338,28 +337,6 @@ General functions
.. warning: Not implimented yet
.. function:: getAnimRecordFrame()
Gets the current frame number used for recording animations. This
number is incremented automatically by Blender when the "Record
animation" feature is turned on.
:rtype: int
.. function:: setAnimRecordFrame(framenr)
Sets the current frame number used for recording animations. This
number is automatically incremented by Blender when the "Record
animation" feature is turned on.
The frame number Must be non-negative, unless Blender has
:attr:`bpy.types.UserPreferencesEdit.use_negative_frames` enabled
in its user preferences. Only use non-negative numbers to be on
the safe side, unless you know what you are doing.
:arg framenr: The new frame number.
:type framenr: int
.. function:: getExitKey()
Gets the key used to exit the game engine
@@ -917,8 +894,6 @@ Various
2D Filter
---------
.. _Two-D-FilterActuator-mode:
.. data:: RAS_2DFILTER_BLUR
:value: 2
@@ -1313,3 +1288,5 @@ See :class:`bge.types.KX_StateActuator.operation`
Add bits to state mask
:value: 3
.. _Two-D-FilterActuator-mode:

View File

@@ -8,8 +8,7 @@ Intro
.. module:: bge.render
Example of using a :class:`bge.types.SCA_MouseSensor`,
and two :class:`bge.types.KX_ObjectActuator` to implement MouseLook:
Example of using a :class:`bge.types.SCA_MouseSensor`, and two :class:`bge.types.KX_ObjectActuator` to implement MouseLook:
.. note::
This can also be achieved with the :class:`bge.types.KX_MouseActuator`.
@@ -78,9 +77,7 @@ Constants
.. DATA:: VSYNC_ADAPTIVE
Enables adaptive vsync if supported.
Adaptive vsync enables vsync if the framerate is above the monitors refresh rate.
Otherwise, vsync is diabled if the framerate is too low.
Enables adaptive vsync if supported. Adaptive vsync enables vsync if the framerate is above the monitors refresh rate. Otherwise, vsync is diabled if the framerate is too low.
.. data:: LEFT_EYE
@@ -111,55 +108,40 @@ Functions
Set the width and height of the window (in pixels). This also works for fullscreen applications.
.. note:: Only works in the standalone player, not the Blender-embedded player.
:arg width: width in pixels
:type width: integer
:arg height: height in pixels
:type height: integer
.. function:: setFullScreen(enable)
Set whether or not the window should be fullscreen.
.. note:: Only works in the standalone player, not the Blender-embedded player.
:arg enable: ``True`` to set full screen, ``False`` to set windowed.
:type enable: bool
.. function:: getFullScreen()
Returns whether or not the window is fullscreen.
.. note:: Only works in the standalone player, not the Blender-embedded player; there it always returns False.
:rtype: bool
.. function:: getDisplayDimensions()
Get the display dimensions, in pixels, of the display (e.g., the
monitor). Can return the size of the entire view, so the
combination of all monitors; for example, ``(3840, 1080)`` for two
side-by-side 1080p monitors.
Get the actual display dimensions, in pixels, of the physical display (e.g., the monitor).
:rtype: tuple (width, height)
:type dimension: list [width,heigh]
.. function:: makeScreenshot(filename)
Writes an image file with the current displayed frame.
The image is written to *'filename'*.
The path may be absolute (eg. ``/home/foo/image``) or relative when started with
``//`` (eg. ``//image``). Note that absolute paths are not portable between platforms.
If the filename contains a ``#``,
it will be replaced by an incremental index so that screenshots can be taken multiple
times without overwriting the previous ones (eg. ``image-#``).
The image is written to *'filename'*. The path may be absolute (eg. "/home/foo/image") or relative when started with
"//" (eg. "//image"). Note that absolute paths are not portable between platforms.
If the filename contains a "#", it will be replaced by an incremental index so that screenshots can be taken multiple
times without overwriting the previous ones (eg. "image-#").
Settings for the image are taken from the render settings (file format and respective settings,
gamma and colospace conversion, etc).
The image resolution matches the framebuffer, meaning, the window size and aspect ratio.
When running from the standalone player, instead of the embedded player, only PNG files are supported.
Additional color conversions are also not supported.
Settings for the image are taken from the render settings (file format and respective settings, gamma and colospace
conversion, etc). The image resolution matches the framebuffer, meaning, the window size and aspect ratio.
When running from the standalone player, instead of the embedded player, only PNG files are supported. Additional
color conversions are also not supported.
:arg filename: path and name of the file to write
:type filename: string
@@ -167,14 +149,13 @@ Functions
.. function:: enableVisibility(visible)
Deprecated; doesn't do anything.
Doesn't really do anything...
.. function:: showMouse(visible)
Enables or disables the operating system mouse cursor.
:arg visible:
:type visible: boolean
@@ -182,15 +163,15 @@ Functions
Sets the mouse cursor position.
:arg x: X-coordinate in screen pixel coordinates.
:type x: integer
:arg y: Y-coordinate in screen pixel coordinates.
:type y: integer
.. function:: setBackgroundColor(rgba)
Deprecated and no longer functional. Use :py:meth:`bge.types.KX_WorldInfo.backgroundColor` instead.
Sets the window background color. (Deprecated: use KX_WorldInfo.background_color)
:type rgba: list [r, g, b, a]
.. function:: setEyeSeparation(eyesep)
@@ -234,7 +215,6 @@ Functions
Set the material mode to use for OpenGL rendering.
:arg mode: material mode
:type mode: KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
.. note:: Changes will only affect newly created scenes.
@@ -251,17 +231,14 @@ Functions
Enables or disables a GLSL material setting.
:arg setting:
:type setting: string (lights, shaders, shadows, ramps, nodes, extra_textures)
:arg enable:
:type enable: boolean
.. function:: getGLSLMaterialSetting(setting)
.. function:: getGLSLMaterialSetting(setting, enable)
Get the state of a GLSL material setting.
:arg setting:
:type setting: string (lights, shaders, shadows, ramps, nodes, extra_textures)
:rtype: boolean
@@ -322,28 +299,24 @@ Functions
Show or hide the framerate.
:arg enable:
:type enable: boolean
.. function:: showProfile(enable)
Show or hide the profile.
:arg enable:
:type enable: boolean
.. function:: showProperties(enable)
Show or hide the debug properties.
:arg enable:
:type enable: boolean
.. function:: autoDebugList(enable)
Enable or disable auto adding debug properties to the debug list.
:arg enable:
:type enable: boolean
.. function:: clearDebugList()

File diff suppressed because it is too large Load Diff

View File

@@ -7,66 +7,11 @@ base class --- :class:`PyObjectPlus`
.. class:: KX_BlenderMaterial(PyObjectPlus)
This is the interface to materials in the game engine.
Materials define the render state to be applied to mesh objects.
The example below shows a simple GLSL shader setup allowing to dynamically mix two texture channels
in a material. All materials of the object executing this script should have two textures using
separate UV maps in the two first texture channels.
The code works for both Multitexture and GLSL rendering modes.
.. code-block:: python
from bge import logic
vertex_shader = """
void main(void)
{
// simple projection of the vertex position to view space
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
// coordinate of the 1st texture channel
gl_TexCoord[0] = gl_MultiTexCoord0;
// coordinate of the 2nd texture channel
gl_TexCoord[1] = gl_MultiTexCoord1;
}
"""
fragment_shader ="""
uniform sampler2D texture_0;
uniform sampler2D texture_1;
uniform float factor;
void main(void)
{
vec4 color_0 = texture2D(texture_0, gl_TexCoord[0].st);
vec4 color_1 = texture2D(texture_1, gl_TexCoord[1].st);
gl_FragColor = mix(color_0, color_1, factor);
}
"""
object = logic.getCurrentController().owner
for mesh in object.meshes:
for material in mesh.materials:
shader = material.getShader()
if shader is not None:
if not shader.isValid():
shader.setSource(vertex_shader, fragment_shader, True)
# get the first texture channel of the material
shader.setSampler('texture_0', 0)
# get the second texture channel of the material
shader.setSampler('texture_1', 1)
# pass another uniform to the shader
shader.setUniform1f('factor', 0.3)
KX_BlenderMaterial
.. attribute:: shader
The material's shader.
The materials shader.
:type: :class:`BL_Shader`
@@ -89,83 +34,39 @@ base class --- :class:`PyObjectPlus`
:return: the material's shader
:rtype: :class:`BL_Shader`
.. attribute:: alpha
The material's alpha transparency.
:type: float between 0.0 and 1.0 inclusive
.. attribute:: hardness
How hard (sharp) the material's specular reflection is.
:type: integer between 1 and 511 inclusive
.. attribute:: emit
Amount of light to emit.
:type: float between 0.0 and 2.0 inclusive
.. attribute:: specularIntensity
How intense (bright) the material's specular reflection is.
:type: float between 0.0 and 1.0 inclusive
.. attribute:: diffuseIntensity
The material's amount of diffuse reflection.
:type: float between 0.0 and 1.0 inclusive
.. attribute:: specularColor
The material's specular color.
:type: :class:`mathutils.Color`
.. attribute:: diffuseColor
The material's diffuse color.
:type: :class:`mathutils.Color`
.. method:: setBlending(src, dest)
Set the pixel color arithmetic functions.
:arg src: Specifies how the red, green, blue, and alpha source blending factors are computed, one of...
* :data:`~bgl.GL_ZERO`
* :data:`~bgl.GL_ONE`
* :data:`~bgl.GL_SRC_COLOR`
* :data:`~bgl.GL_ONE_MINUS_SRC_COLOR`
* :data:`~bgl.GL_DST_COLOR`
* :data:`~bgl.GL_ONE_MINUS_DST_COLOR`
* :data:`~bgl.GL_SRC_ALPHA`
* :data:`~bgl.GL_ONE_MINUS_SRC_ALPHA`
* :data:`~bgl.GL_DST_ALPHA`
* :data:`~bgl.GL_ONE_MINUS_DST_ALPHA`
* :data:`~bgl.GL_SRC_ALPHA_SATURATE`
:type src: int
:arg src: Specifies how the red, green, blue, and alpha source blending factors are computed.
:type src: Value in...
:arg dest: Specifies how the red, green, blue, and alpha destination blending factors are computed, one of...
* :data:`~bgl.GL_ZERO`
* :data:`~bgl.GL_ONE`
* :data:`~bgl.GL_SRC_COLOR`
* :data:`~bgl.GL_ONE_MINUS_SRC_COLOR`
* :data:`~bgl.GL_DST_COLOR`
* :data:`~bgl.GL_ONE_MINUS_DST_COLOR`
* :data:`~bgl.GL_SRC_ALPHA`
* :data:`~bgl.GL_ONE_MINUS_SRC_ALPHA`
* :data:`~bgl.GL_DST_ALPHA`
* :data:`~bgl.GL_ONE_MINUS_DST_ALPHA`
* :data:`~bgl.GL_SRC_ALPHA_SATURATE`
:type dest: int
* GL_ZERO,
* GL_ONE,
* GL_SRC_COLOR,
* GL_ONE_MINUS_SRC_COLOR,
* GL_DST_COLOR,
* GL_ONE_MINUS_DST_COLOR,
* GL_SRC_ALPHA,
* GL_ONE_MINUS_SRC_ALPHA,
* GL_DST_ALPHA,
* GL_ONE_MINUS_DST_ALPHA,
* GL_SRC_ALPHA_SATURATE
:arg dest: Specifies how the red, green, blue, and alpha destination blending factors are computed.
:type dest: Value in...
* GL_ZERO
* GL_ONE
* GL_SRC_COLOR
* GL_ONE_MINUS_SRC_COLOR
* GL_DST_COLOR
* GL_ONE_MINUS_DST_COLOR
* GL_SRC_ALPHA
* GL_ONE_MINUS_SRC_ALPHA
* GL_DST_ALPHA
* GL_ONE_MINUS_DST_ALPHA
* GL_SRC_ALPHA_SATURATE
.. method:: getMaterialIndex()

View File

@@ -51,18 +51,6 @@ base class --- :class:`KX_GameObject`
:type: float
.. attribute:: shift_x
The camera's horizontal shift.
:type: float
.. attribute:: shift_y
The camera's vertical shift.
:type: float
.. attribute:: perspective
True if this camera has a perspective transform, False for an orthographic projection.

View File

@@ -25,7 +25,7 @@ base class --- :class:`PyObjectPlus`
The maximum number of jumps a character can perform before having to touch the ground. By default this is set to 1. 2 allows for a double jump, etc.
:type: int in [0, 255], default 1
:type: int
.. attribute:: jumpCount

View File

@@ -28,8 +28,7 @@ base class --- :class:`PyObjectPlus`
* Lowerlimit > Upperlimit -> axis is free
* Lowerlimit < Upperlimit -> axis it limited in that range
For PHY_LINEHINGE_CONSTRAINT = 2 or PHY_ANGULAR_CONSTRAINT = 3:
PHY_LINEHINGE_CONSTRAINT = 2 or PHY_ANGULAR_CONSTRAINT = 3:
axis = 3 is a constraint limit, with low/high limit value
* 3: X axis angle
@@ -38,8 +37,7 @@ base class --- :class:`PyObjectPlus`
:arg value1 (max): Set the maximum limit of the axis
:type value1: float
For PHY_CONE_TWIST_CONSTRAINT = 4:
PHY_CONE_TWIST_CONSTRAINT = 3:
axis = 3..5 are constraint limits, high limit values
* 3: X axis angle
* 4: Y axis angle
@@ -50,8 +48,7 @@ base class --- :class:`PyObjectPlus`
:arg value1 (max): Set the maximum limit of the axis
:type value1: float
For PHY_GENERIC_6DOF_CONSTRAINT = 12:
PHY_GENERIC_6DOF_CONSTRAINT = 12:
axis = 0..2 are constraint limits, with low/high limit value
* 0: X axis position
* 1: Y axis position
@@ -133,11 +130,10 @@ base class --- :class:`PyObjectPlus`
Returns the contraint type (read only)
:type: integer
- :class:`~bge.constraints.POINTTOPOINT_CONSTRAINT`
- :class:`~bge.constraints.LINEHINGE_CONSTRAINT`
- :class:`~bge.constraints.ANGULAR_CONSTRAINT`
- :class:`~bge.constraints.CONETWIST_CONSTRAINT`
- :class:`~bge.constraints.VEHICLE_CONSTRAINT`
- :class:`~bge.constraints.GENERIC_6DOF_CONSTRAINT`
- 1 = :class:`~bge.constraints.POINTTOPOINT_CONSTRAINT`
- 2 = :class:`~bge.constraints.LINEHINGE_CONSTRAINT`
- 3 = :class:`~bge.constraints.ANGULAR_CONSTRAINT`
- 4 = :class:`~bge.constraints.CONETWIST_CONSTRAINT`
- 11 = :class:`~bge.constraints.VEHICLE_CONSTRAINT`
- 12 = :class:`~bge.constraints.GENERIC_6DOF_CONSTRAINT`

View File

@@ -7,26 +7,6 @@ base class --- :class:`KX_GameObject`
.. class:: KX_FontObject(KX_GameObject)
A Font object.
TODO.
.. code-block:: python
# Display a message about the exit key using a Font object.
import bge
co = bge.logic.getCurrentController()
font = co.owner
exit_key = bge.events.EventToString(bge.logic.getExitKey())
if exit_key.endswith("KEY"):
exit_key = exit_key[:-3]
font.text = "Press key '%s' to quit the game." % exit_key
.. attribute:: text
The text displayed by this Font object.
:type: string

View File

@@ -137,30 +137,7 @@ base class --- :class:`SCA_IObject`
.. note::
A value of 0.0 disables this option (rather than setting it stationary).
.. attribute:: angularVelocityMin
Enforces the object keeps rotating at a minimum velocity. A value of 0.0 disables this.
:type: non-negative float
.. note::
Applies to dynamic and rigid body objects only.
While objects are stationary the minimum velocity will not be applied.
.. attribute:: angularVelocityMax
Clamp the maximum angular velocity to prevent objects rotating beyond a set speed.
A value of 0.0 disables clamping; it does not stop rotation.
:type: non-negative float
.. note::
Applies to dynamic and rigid body objects only.
A value of 0.0 disables this option (rather then setting it stationary).
.. attribute:: localInertia
@@ -799,7 +776,7 @@ base class --- :class:`SCA_IObject`
:return: the first object hit or None if no object or object does not match prop
:rtype: :class:`KX_GameObject`
.. method:: rayCast(objto, objfrom, dist, prop, face, xray, poly, mask)
.. method:: rayCast(objto, objfrom, dist, prop, face, xray, poly)
Look from a point/object to another point/object and find first object hit within dist that matches prop.
if poly is 0, returns a 3-tuple with object reference, hit point and hit normal or (None, None, None) if no hit.
@@ -851,8 +828,6 @@ base class --- :class:`SCA_IObject`
* 2: return value is a 5-tuple and the 5th element is a 2-tuple (u, v) with the UV mapping of the hit point or None if no hit, or the object doesn't use a mesh collision shape, or doesn't have a UV mapping.
:type poly: integer
:arg mask: collision mask: The collision mask (16 layers mapped to a 16-bit integer) is combined with each object's collision group, to hit only a subset of the objects in the scene. Only those objects for which ``collisionGroup & mask`` is true can be hit.
:type mask: bitfield
:return: (object, hitpoint, hitnormal) or (object, hitpoint, hitnormal, polygon) or (object, hitpoint, hitnormal, polygon, hituv).
* object, hitpoint and hitnormal are None if no hit.
@@ -974,16 +949,6 @@ base class --- :class:`SCA_IObject`
:return: The current frame of the action
:rtype: float
.. method:: getActionName(layer=0)
Gets the name of the current action playing in the supplied layer.
:arg layer: The layer that you want to get the action name from.
:type layer: integer
:return: The name of the current action
:rtype: string
.. method:: setActionFrame(frame, layer=0)
Set the current frame of the action playing in the supplied layer.

View File

@@ -0,0 +1,65 @@
KX_IpoActuator(SCA_IActuator)
=============================
.. module:: bge.types
base class --- :class:`SCA_IActuator`
.. class:: KX_IpoActuator(SCA_IActuator)
IPO actuator activates an animation.
.. attribute:: frameStart
Start frame.
:type: float
.. attribute:: frameEnd
End frame.
:type: float
.. attribute:: propName
Use this property to define the Ipo position.
:type: string
.. attribute:: framePropName
Assign this property this action current frame number.
:type: string
.. attribute:: mode
Play mode for the ipo. Can be on of :ref:`these constants <ipo-actuator>`
:type: integer
.. attribute:: useIpoAsForce
Apply Ipo as a global or local force depending on the local option (dynamic objects only).
:type: boolean
.. attribute:: useIpoAdd
Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag.
:type: boolean
.. attribute:: useIpoLocal
Let the ipo acts in local coordinates, used in Force and Add mode.
:type: boolean
.. attribute:: useChildren
Update IPO on all children Objects as well.
:type: boolean

View File

@@ -25,12 +25,6 @@ base class --- :class:`PyObjectPlus`
:type: callable
.. attribute:: finished
The current status of the lib load.
:type: boolean
.. attribute:: progress
The current progress of the lib load as a normalized value from 0.0 to 1.0.

View File

@@ -51,7 +51,7 @@ base class --- :class:`SCA_IObject`
.. attribute:: materials
:type: list of :class:`KX_BlenderMaterial` type
:type: list of :class:`KX_BlenderMaterial` or :class:`KX_PolygonMaterial` types
.. attribute:: numPolygons

View File

@@ -23,7 +23,7 @@ base class --- :class:`SCA_IObject`
The material of the polygon.
:type: :class:`KX_BlenderMaterial`
:type: :class:`KX_PolygonMaterial` or :class:`KX_BlenderMaterial`
.. attribute:: texture_name
@@ -84,7 +84,7 @@ base class --- :class:`SCA_IObject`
.. method:: getMaterial()
:return: The polygon material
:rtype: :class:`KX_BlenderMaterial`
:rtype: :class:`KX_PolygonMaterial` or :class:`KX_BlenderMaterial`
.. method:: getTextureName()

View File

@@ -0,0 +1,250 @@
KX_PolygonMaterial(PyObjectPlus)
================================
.. module:: bge.types
base class --- :class:`PyObjectPlus`
.. class:: KX_PolygonMaterial(PyObjectPlus)
This is the interface to materials in the game engine.
Materials define the render state to be applied to mesh objects.
.. warning::
Some of the methods/variables are CObjects. If you mix these up, you will crash blender.
.. code-block:: python
from bge import logic
vertex_shader = """
void main(void)
{
// original vertex position, no changes
gl_Position = ftransform();
// coordinate of the 1st texture channel
gl_TexCoord[0] = gl_MultiTexCoord0;
// coordinate of the 2nd texture channel
gl_TexCoord[1] = gl_MultiTexCoord1;
}
"""
fragment_shader ="""
uniform sampler2D color_0;
uniform sampler2D color_1;
uniform float factor;
void main(void)
{
vec4 color_0 = texture2D(color_0, gl_TexCoord[0].st);
vec4 color_1 = texture2D(color_1, gl_TexCoord[1].st);
gl_FragColor = mix(color_0, color_1, factor);
}
"""
object = logic.getCurrentController().owner
object = cont.owner
for mesh in object.meshes:
for material in mesh.materials:
shader = material.getShader()
if shader != None:
if not shader.isValid():
shader.setSource(vertex_shader, fragment_shader, True)
# get the first texture channel of the material
shader.setSampler('color_0', 0)
# get the second texture channel of the material
shader.setSampler('color_1', 1)
# pass another uniform to the shader
shader.setUniform1f('factor', 0.3)
.. attribute:: texture
Texture name.
:type: string (read-only)
.. attribute:: gl_texture
OpenGL texture handle (eg for glBindTexture(GL_TEXTURE_2D, gl_texture).
:type: integer (read-only)
.. attribute:: material
Material name.
:type: string (read-only)
.. attribute:: tface
Texture face properties.
:type: CObject (read-only)
.. attribute:: tile
Texture is tiling.
:type: boolean
.. attribute:: tilexrep
Number of tile repetitions in x direction.
:type: integer
.. attribute:: tileyrep
Number of tile repetitions in y direction.
:type: integer
.. attribute:: drawingmode
Drawing mode for the material.
- 2 (drawingmode & 4) Textured
- 4 (drawingmode & 16) Light
- 14 (drawingmode & 16384) 3d Polygon Text.
:type: bitfield
.. attribute:: transparent
This material is transparent. All meshes with this
material will be rendered after non transparent meshes from back
to front.
:type: boolean
.. attribute:: zsort
Transparent polygons in meshes with this material will be sorted back to
front before rendering.
Non-Transparent polygons will be sorted front to back before rendering.
:type: boolean
.. attribute:: diffuse
The diffuse color of the material. black = [0.0, 0.0, 0.0] white = [1.0, 1.0, 1.0].
:type: list [r, g, b]
.. attribute:: specular
The specular color of the material. black = [0.0, 0.0, 0.0] white = [1.0, 1.0, 1.0].
:type: list [r, g, b]
.. attribute:: shininess
The shininess (specular exponent) of the material. 0.0 <= shininess <= 128.0.
:type: float
.. attribute:: specularity
The amount of specular of the material. 0.0 <= specularity <= 1.0.
:type: float
.. method:: updateTexture(tface, rasty)
Updates a realtime animation.
:arg tface: Texture face (eg mat.tface)
:type tface: CObject
:arg rasty: Rasterizer
:type rasty: CObject
.. method:: setTexture(tface)
Sets texture render state.
:arg tface: Texture face
:type tface: CObject
.. code-block:: python
mat.setTexture(mat.tface)
.. method:: activate(rasty, cachingInfo)
Sets material parameters for this object for rendering.
Material Parameters set:
#. Texture
#. Backface culling
#. Line drawing
#. Specular Colour
#. Shininess
#. Diffuse Colour
#. Polygon Offset.
:arg rasty: Rasterizer instance.
:type rasty: CObject
:arg cachingInfo: Material cache instance.
:type cachingInfo: CObject
.. method:: setCustomMaterial(material)
Sets the material state setup object.
Using this method, you can extend or completely replace the gameengine material
to do your own advanced multipass effects.
Use this method to register your material class. Instead of the normal material,
your class's activate method will be called just before rendering the mesh.
This should setup the texture, material, and any other state you would like.
It should return True to render the mesh, or False if you are finished. You should
clean up any state Blender does not set before returning False.
Activate Method Definition:
.. code-block:: python
def activate(self, rasty, cachingInfo, material):
:arg material: The material object.
:type material: instance
.. code-block:: python
class PyMaterial:
def __init__(self):
self.pass_no = -1
def activate(self, rasty, cachingInfo, material):
# Activate the material here.
#
# The activate method will be called until it returns False.
# Every time the activate method returns True the mesh will
# be rendered.
#
# rasty is a CObject for passing to material.updateTexture()
# and material.activate()
# cachingInfo is a CObject for passing to material.activate()
# material is the KX_PolygonMaterial instance this material
# was added to
# default material properties:
self.pass_no += 1
if self.pass_no == 0:
material.activate(rasty, cachingInfo)
# Return True to do this pass
return True
# clean up and return False to finish.
self.pass_no = -1
return False
# Create a new Python Material and pass it to the renderer.
mat.setCustomMaterial(PyMaterial())

View File

@@ -25,6 +25,12 @@ base class --- :class:`SCA_IObject`
:type: Vector((u, v))
.. attribute:: uvs
A list of all the texture coordinates of the vertex.
:type: list of Vector((u, v))
.. attribute:: normal
The normal of the vertex.
@@ -120,18 +126,24 @@ base class --- :class:`SCA_IObject`
:arg pos: the new position for this vertex in local coordinates.
.. method:: getUV()
.. method:: getUV(index=0)
Gets the UV (texture) coordinates of this vertex.
:arg index: the UV (texture) channel (optional).
:type index: integer
:return: this vertexes UV (texture) coordinates.
:rtype: Vector((u, v))
.. method:: setUV(uv)
.. method:: setUV(uv, index=0)
Sets the UV (texture) coordinates of this vertex.
:type: Vector((u, v))
:arg uv: the UV (texture) coordinate of this vertex.
:type uv: Vector((u, v))
:arg index: the UV (texture) channel (optional).
:type index: integer
.. method:: getUV2()
@@ -140,14 +152,16 @@ base class --- :class:`SCA_IObject`
:return: this vertexes UV (texture) coordinates.
:rtype: Vector((u, v))
.. method:: setUV2(uv, unit)
.. deprecated:: use :meth:`getUV`
.. method:: setUV2(uv)
Sets the 2nd UV (texture) coordinates of this vertex.
:type: Vector((u, v))
:arg uv: the 2nd (texture) UV coordinate of this vertex.
:type uv: Vector((u, v))
:arg unit: optional argument, FLAT==1, SECOND_UV==2, defaults to SECOND_UV
:arg unit: integer
.. deprecated:: use :meth:`setUV`
.. method:: getRGBA()

View File

@@ -1,4 +1,4 @@
KX_WorldInfo(PyObjectPlus)
KX_WordlInfo(PyObjectPlus)
=============================
.. module:: bge.types
@@ -7,7 +7,7 @@ base class --- :class:`PyObjectPlus`
.. class:: KX_WorldInfo(PyObjectPlus)
A world object.
A wolrd object.
.. code-block:: python
@@ -16,7 +16,11 @@ base class --- :class:`PyObjectPlus`
sce = bge.logic.getCurrentScene()
sce.world.mistColor = [1.0, 0.0, 0.0]
sce.world.mist_color = [1.0, 0.0, 0.0]
*********
Constants
*********
.. data:: KX_MIST_QUADRATIC
@@ -30,50 +34,54 @@ base class --- :class:`PyObjectPlus`
Type of inverse quadratic attenuation used to fade mist.
.. attribute:: mistEnable
**********
Attributes
**********
.. attribute:: mist_enable
Return the state of the mist.
:type: bool
.. attribute:: mistStart
.. attribute:: mist_start
The mist start point.
:type: float
.. attribute:: mistDistance
.. attribute:: mist_distance
The mist distance fom the start point to reach 100% mist.
:type: float
.. attribute:: mistIntensity
.. attribute:: mist_intensity
The mist intensity.
:type: float
.. attribute:: mistType
.. attribute:: mist_type
The type of mist - must be KX_MIST_QUADRATIC, KX_MIST_LINEAR or KX_MIST_INV_QUADRATIC
.. attribute:: mistColor
.. attribute:: mist_color
The color of the mist. Black = [0.0, 0.0, 0.0], White = [1.0, 1.0, 1.0].
Mist and background color sould always set to the same color.
:type: :class:`mathutils.Color`
:type: :class:`mathutils.Vector`
.. attribute:: backgroundColor
.. attribute:: background_color
The color of the background. Black = [0.0, 0.0, 0.0], White = [1.0, 1.0, 1.0].
Mist and background color sould always set to the same color.
:type: :class:`mathutils.Color`
:type: :class:`mathutils.Vector`
.. attribute:: ambientColor
.. attribute:: ambient_color
The color of the ambient light. Black = [0.0, 0.0, 0.0], White = [1.0, 1.0, 1.0].
:type: :class:`mathutils.Color`
:type: :class:`mathutils.Vector`

View File

@@ -7,7 +7,7 @@ base class --- :class:`SCA_IActuator`
.. class:: SCA_2DFilterActuator(SCA_IActuator)
Create, enable and disable 2D filters.
Create, enable and disable 2D filters
The following properties don't have an immediate effect.
You must active the actuator to get the result.
@@ -29,7 +29,7 @@ base class --- :class:`SCA_IActuator`
.. attribute:: mode
Type of 2D filter, use one of :ref:`these constants <Two-D-FilterActuator-mode>`.
Type of 2D filter, use one of :ref:`these constants <Two-D-FilterActuator-mode>`
:type: integer

File diff suppressed because it is too large Load Diff

View File

@@ -16,24 +16,24 @@ and in the game engine.
.. warning::
The API provided by this module is subject to change.
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).
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).
Constants
=========
GLSL Data Type
GLSL data type
--------------
.. _data-type:
Type of GLSL data.
For shader uniforms, the data type determines which ``glUniform`` function
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
For vertex attributes, the data type determines which glVertexAttrib function
variant to use to send the vertex attribute to the GPU.
See export_shader_
@@ -42,37 +42,53 @@ See export_shader_
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 Types
------------------
GLSL uniform type
-----------------
.. _uniform-type:
@@ -85,7 +101,7 @@ The calculation of some of the uniforms is based on matrices available in the sc
.. _mat4_cam_to_world:
.. _mat4_world_to_cam:
``mat4_cam_to_world``
*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.
@@ -96,7 +112,7 @@ The calculation of some of the uniforms is based on matrices available in the sc
.. _mat4_object_to_world:
.. _mat4_world_to_object:
``mat4_object_to_world``
*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.
@@ -106,7 +122,7 @@ The calculation of some of the uniforms is based on matrices available in the sc
.. _mat4_lamp_to_world:
.. _mat4_world_to_lamp:
``mat4_lamp_to_world``
*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.
@@ -114,305 +130,151 @@ The calculation of some of the uniforms is based on matrices available in the sc
Some uniform will need the *mat4_world_to_lamp* matrix
computed as the inverse of this matrix.
.. note::
Any uniforms used for view projections or transformations (object, lamp matrices for eg),
can only be set once per frame.
GLSL Object Uniforms
^^^^^^^^^^^^^^^^^^^^
.. note::
- Object transformations and color must be set before drawing the object.
- There is at most one uniform of these types per shader.
.. data:: GPU_DYNAMIC_OBJECT_VIEWMAT
A matrix that converts world coordinates to camera coordinates (see mat4_world_to_cam_).
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.
:type: matrix4x4
:value: 1
.. data:: GPU_DYNAMIC_OBJECT_MAT
A matrix that converts object coordinates to world coordinates (see mat4_object_to_world_).
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.
:type: matrix4x4
: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.
:type: matrix4x4
: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.
:type: matrix4x4
:value: 4
.. data:: GPU_DYNAMIC_OBJECT_COLOR
An RGB color + alpha defined at object level.
Each values between 0.0 and 1.0.
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.
See :class:`bpy.types.Object.color`.
:type: float4
.. data:: GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE
Multiplier for bump-map scaling.
:type: float
GLSL Lamp Uniforms
^^^^^^^^^^^^^^^^^^
.. note::
There is one uniform of that type per lamp lighting the material.
:value: 5
.. data:: GPU_DYNAMIC_LAMP_DYNVEC
Represents the direction of light in camera space.
The uniform is a vector of 3 float representing the direction of light in camera space.
In Blender, this is computed by
Computed as:
mat4_world_to_cam_ * (-vec3_lamp_Z_axis)
mat4_world_to_cam_ * (-vec3_lamp_Z_axis)
.. note::
- The lamp Z axis points to the opposite direction of light.
- The norm of the vector should be unit length.
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.
:type: float3
:value: 6
.. data:: GPU_DYNAMIC_LAMP_DYNCO
Represents the position of the light in camera space.
The uniform is a vector of 3 float representing the position of the light in camera space.
Computed as
Computed as:
mat4_world_to_cam_ * vec3_lamp_pos
mat4_world_to_cam_ * vec3_lamp_pos
:type: float3
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
Matrix that converts vector in camera space to lamp space.
The uniform is a 4x4 GL matrix that converts vector in camera space to lamp space.
Computed as
Computed as:
mat4_world_to_lamp_ * mat4_cam_to_world_
mat4_world_to_lamp_ * mat4_cam_to_world_
:type: matrix4x4
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
Matrix that converts a vector in camera space to shadow buffer depth space.
The uniform is a 4x4 GL matrix that converts a vector in camera space to shadow buffer depth space.
Computed as
Computed as:
mat4_perspective_to_depth_ * mat4_lamp_to_perspective_ * mat4_world_to_lamp_ * mat4_cam_to_world_.
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::
*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
.. note::
This uniform can be set once per frame. There is one uniform of that type per lamp casting shadow in the scene.
- There is one uniform of that type per lamp casting shadow in the scene.
:type: matrix4x4
:value: 9
.. data:: GPU_DYNAMIC_LAMP_DYNENERGY
See :class:`bpy.types.Lamp.energy`.
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.
:type: float
:value: 10
.. data:: GPU_DYNAMIC_LAMP_DYNCOL
See :class:`bpy.types.Lamp.color`.
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.
:type: float3
.. data:: GPU_DYNAMIC_LAMP_DISTANCE
See :class:`bpy.types.Lamp.distance`.
:type: float
.. data:: GPU_DYNAMIC_LAMP_ATT1
See
:class:`bpy.types.PointLamp.linear_attenuation`,
:class:`bpy.types.SpotLamp.linear_attenuation`.
:type: float
.. data:: GPU_DYNAMIC_LAMP_ATT2
See
:class:`bpy.types.PointLamp.quadratic_attenuation`,
:class:`bpy.types.SpotLamp.quadratic_attenuation`.
:type: float
.. data:: GPU_DYNAMIC_LAMP_SPOTSIZE
See :class:`bpy.types.SpotLamp.spot_size`.
:type: float
.. data:: GPU_DYNAMIC_LAMP_SPOTBLEND
See :class:`bpy.types.SpotLamp.spot_blend`.
:type: float
.. data:: GPU_DYNAMIC_LAMP_SPOTSCALE
Represents the SpotLamp local scale.
:type: float2
GLSL Sampler Uniforms
^^^^^^^^^^^^^^^^^^^^^
:value: 11
.. data:: GPU_DYNAMIC_SAMPLER_2DBUFFER
Represents an internal texture used for certain effect
The uniform is an integer representing an internal texture used for certain effect
(color band, etc).
:type: integer
:value: 12
.. data:: GPU_DYNAMIC_SAMPLER_2DIMAGE
Represents a texture loaded from an image file.
The uniform is an integer representing a texture loaded from an image file.
:type: integer
:value: 13
.. data:: GPU_DYNAMIC_SAMPLER_2DSHADOW
Represents a texture loaded from a shadow buffer file.
The uniform is an float representing the bumpmap scaling.
:type: integer
:value: 14
.. data:: GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE
The uniform is an integer representing a shadow buffer corresponding to a lamp
casting shadow.
:value: 15
GLSL Mist Uniforms
^^^^^^^^^^^^^^^^^^
.. data:: GPU_DYNAMIC_MIST_ENABLE:
See :class:`bpy.types.WorldMistSettings.use_mist`.
:type: float (0 or 1)
.. data:: GPU_DYNAMIC_MIST_START
See :class:`bpy.types.WorldMistSettings.start`.
:type: float
See :class:`bpy.types.WorldMistSettings.depth`.
.. data:: GPU_DYNAMIC_MIST_DISTANCE
:type: float
See :class:`bpy.types.WorldMistSettings.intensity`.
.. data:: GPU_DYNAMIC_MIST_INTENSITY
:type: float
.. data:: GPU_DYNAMIC_MIST_TYPE
See :class:`bpy.types.WorldMistSettings.falloff`.
:type: float (used as an index into the type)
.. data:: GPU_DYNAMIC_MIST_COLOR
GLSL World Uniforms
^^^^^^^^^^^^^^^^^^^
.. data:: GPU_DYNAMIC_HORIZON_COLOR
See :class:`bpy.types.World.horizon_color`.
:type: float3
.. data:: GPU_DYNAMIC_AMBIENT_COLOR
See :class:`bpy.types.World.ambient_color`.
:type: float3
GLSL Material Uniforms
^^^^^^^^^^^^^^^^^^^^^^
.. data:: GPU_DYNAMIC_MAT_DIFFRGB
See :class:`bpy.types.Material.diffuse_color`.
:type: float3
.. data:: GPU_DYNAMIC_MAT_REF
See :class:`bpy.types.Material.diffuse_intensity`.
:type: float
.. data:: GPU_DYNAMIC_MAT_SPECRGB
See :class:`bpy.types.Material.specular_color`.
:type: float3
.. data:: GPU_DYNAMIC_MAT_SPEC
See :class:`bpy.types.Material.specular_intensity`.
:type: float
.. data:: GPU_DYNAMIC_MAT_HARD
See :class:`bpy.types.Material.specular_hardness`.
:type: float
.. data:: GPU_DYNAMIC_MAT_EMIT
See :class:`bpy.types.Material.emit`.
:type: float
.. data:: GPU_DYNAMIC_MAT_AMB
See :class:`bpy.types.Material.ambient`.
:type: float
.. data:: GPU_DYNAMIC_MAT_ALPHA
See :class:`bpy.types.Material.alpha`.
:type: float
GLSL Attribute Type
GLSL attribute type
-------------------
.. _attribute-type:
@@ -429,7 +291,9 @@ layer that contains the vertex attribute.
.. code-block:: python
mesh.uv_layers[attribute["name"]]
mesh.uv_textures[attribute["name"]]
:value: 5
.. data:: CD_MCOL
@@ -442,6 +306,8 @@ layer that contains the vertex attribute.
mesh.vertex_colors[attribute["name"]]
:value: 6
.. data:: CD_ORCO
Vertex attribute is original coordinates. Data type is vector 3 float.
@@ -453,6 +319,8 @@ layer that contains the vertex attribute.
mesh.vertices
:value: 14
.. data:: CD_TANGENT
Vertex attribute is the tangent vector. Data type is vector 4 float.
@@ -462,6 +330,8 @@ layer that contains the vertex attribute.
C function to compute the tangent layer from the other layers can be obtained from
blender.org.
:value: 18
Functions
=========
@@ -471,12 +341,8 @@ Functions
.. 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
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.
@@ -488,91 +354,76 @@ Functions
The dictionary contains the following elements:
- ``["fragment"]``: string
* ["fragment"] : string
fragment shader source code.
- ``["vertex"]``: string
* ["vertex"] : string
vertex shader source code.
- ``["uniforms"]``: sequence
* ["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
* ["varname"] : string
name of the uniform in the fragment shader. Always of the form 'unf<number>'.
- ``["datatype"]``: integer
* ["datatype"] : integer
data type of the uniform variable. Can be one of the following:
.. hlist::
:columns: 2
* :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
- :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"] : 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:
* ["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: 2
: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`
* :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:
* 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 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:
* 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 ``lamp.energy`` and ``lamp.color``
from which you get la.energy and la.color
- Lamp duplication is not supported: if you have duplicated lamps in your scene
* 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:
* ["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
@@ -581,63 +432,60 @@ Functions
# image size as a 2-dimensional array of int
uniform["image"].size
- ``["texnumber"]``: integer
* ["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`.
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.
* ["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.
The texture data is provided so that you can make a real image out of it in the
exporter.
- ``["texsize"]``: integer
* ["texsize"] : integer
horizontal size of texture for uniform type :data:`gpu.GPU_DYNAMIC_SAMPLER_2DBUFFER`.
The texture data is in ["texpixels"].
- ``["attributes"]``: sequence
* ["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.
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
* ["varname"] : string
name of the uniform in the vertex shader. Always of the form 'att<number>'.
- ``["datatype"]``: integer
* ["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``
* :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,
* ["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.
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.
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"] : integer
type of the mesh custom data from which the vertex attribute is loaded.
See attribute-type_.
- ``["name"]``: string or integer
* ["name"] : string or integer
custom data layer name, used for attribute type :data:`gpu.CD_MTFACE` and :data:`gpu.CD_MCOL`.
Example:
@@ -664,14 +512,14 @@ Notes
.. _mat4_lamp_to_perspective:
#. Calculation of the ``mat4_lamp_to_perspective`` matrix for a spot lamp.
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
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:
.. code-block:: python
# Get the lamp datablock with:
#Get the lamp datablock with:
lamp = bpy.data.objects[uniform["lamp"]].data
# Compute the projection matrix:
@@ -683,11 +531,11 @@ Notes
# The size of the projection plane is computed with the usual formula:
wsize = lamp.clista * tan(lamp.spotsize/2)
# And the projection matrix:
#And the projection matrix:
mat4_lamp_to_perspective = glFrustum(-wsize, wsize, -wsize, wsize, lamp.clista, lamp.clipend)
#. Creation of the shadow map for a spot lamp.
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``:
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.

View File

@@ -121,7 +121,7 @@ Here are some more complex examples:
bpy.context.scene.render.layers["RenderLayer"].samples
# access to the current weight paint brush size
bpy.context.tool_settings.weight_paint.brush.size
bpy.context.tool_settings.weight_paint.brush.size
# check if the window is fullscreen
bpy.context.window.screen.show_fullscreen
@@ -141,16 +141,15 @@ When starting out scripting you will often run into the problem where you're not
There are a few ways to do this.
- Use the Python console's auto-complete to inspect properties.
*This can be hit-and-miss but has the advantage
- Use the Python console's auto-complete to inspect properties. *This can be hit-and-miss but has the advantage
that you can easily see the values of properties and assign them to interactively see the results.*
- Copy the Data-Path from the user interface.
*Explained further in :ref:`Copy Data Path <info_data_path_copy>`*
- Using the documentation to follow references.
*Explained further in :ref:`Indirect Data Access <info_data_path_indirect>`*
- Copy the Data-Path from the user interface. *Explained further in :ref:`Copy Data Path <info_data_path_copy>`*
- Using the documentation to follow references. *Explained further in :ref:`Indirect Data Access <info_data_path_indirect>`*
.. _info_data_path_copy:
.. _info_data_path_copy
Copy Data Path
--------------
@@ -173,8 +172,7 @@ you won't be doing collection look-ups on every access and typically you'll want
then access each :class:`bpy.types.ID` instance by name.
Type in the ID path into a Python console :mod:`bpy.context.active_object`.
Include the trailing dot and don't hit "enter", yet.
Type in the ID path into a Python console :mod:`bpy.context.active_object`. Include the trailing dot and don't hit "enter", yet.
Now right-click on the button and select **Copy Data Path**, then paste the result into the console.
@@ -193,7 +191,7 @@ Hit "enter" and you'll get the current value of 1. Now try changing the value to
You can see the value update in the Subdivision-Surface modifier's UI as well as the cube.
.. _info_data_path_indirect:
.. _info_data_path_indirect
Indirect Data Access
--------------------
@@ -203,24 +201,32 @@ For this example we'll go over something more involved, showing the steps to acc
Lets say we want to access the texture of a brush via Python, to adjust its ``contrast`` for example.
- Start in the default scene and enable 'Sculpt' mode from the 3D-View header.
- From the toolbar expand the **Texture** panel and add a new texture.
*Notice the texture button its self doesn't have very useful links (you can check the tool-tips).*
- The contrast setting isn't exposed in the sculpt toolbar, so view the texture in the properties panel...
- In the properties button select the Texture context.
- Select the Brush icon to show the brush texture.
- Expand the *Colors* panel to locate the *Contrast* button.
- Right click on the contrast button and select **Online Python Reference**
This takes you to ``bpy.types.Texture.contrast``
- Now we can see that ``contrast`` is a property of texture,
so next we'll check on how to access the texture from the brush.
- Expand the **Colors** panel to locate the **Contrast** button.
- Right click on the contrast button and select **Online Python Reference** This takes you to ``bpy.types.Texture.contrast``
- Now we can see that ``contrast`` is a property of texture, so next we'll check on how to access the texture from the brush.
- Check on the **References** at the bottom of the page, sometimes there are many references, and it may take
some guess work to find the right one, but in this case its obviously ``Brush.texture``.
*Now we know that the texture can be accessed from* ``bpy.data.brushes["BrushName"].texture``
*but normally you won't want to access the brush by name, so we'll see now to access the active brush instead.*
- So the next step is to check on where brushes are accessed from via the **References**.
In this case there is simply ``bpy.context.brush`` which is all we need.
Now you can use the Python console to form the nested properties needed to access brush textures contrast,
logically we now know.
@@ -276,8 +282,7 @@ are interested to check on the source code.
.. note::
Not all operators can be called usefully from Python,
for more on this see :ref:`using operators <using_operators>`.
Not all operators can be called usefully from Python, for more on this see :ref:`using operators <using_operators>`.
Info View
@@ -289,8 +294,7 @@ This is located above the file-menu which can be dragged down to display its con
Select the **Script** screen that comes default with Blender to see its output.
You can perform some actions and see them show up - delete a vertex for example.
Each entry can be selected (Right-Mouse-Button),
then copied :kbd:`Control-C`, usually to paste in the text editor or python console.
Each entry can be selected (Right-Mouse-Button), then copied :kbd:`Control-C`, usually to paste in the text editor or python console.
.. note::

View File

@@ -1,20 +1,16 @@
*************
Best Practice
*************
When writing your own scripts python is great for new developers to pick up and become productive,
but you can also pick up odd habits or at least write scripts that are not easy for others to understand.
When writing your own scripts python is great for new developers to pick up and become productive, but you can also pick up odd habits or at least write scripts that are not easy for others to understand.
For your own work this is of course fine,
but if you want to collaborate with others or have your work included with blender there are practices we encourage.
For your own work this is of course fine, but if you want to collaborate with others or have your work included with blender there are practices we encourage.
Style Conventions
=================
For Blender/Python development 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.
For Blender/Python development 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.
@@ -22,17 +18,22 @@ This style guide is known as pep8 and can be found `here <http://www.python.org/
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.
* 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.
* 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.
@@ -41,11 +42,9 @@ As well as pep8 we have other conventions used for blender python scripts.
bpy.context.scene.render.image_settings.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.
* 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.
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>``
@@ -59,75 +58,72 @@ User Interface Layout
Some notes to keep in mind when writing UI layouts:
- UI code is quite simple. Layout declarations are there to easily create a decent layout.
General rule here: If you need more code for the layout declaration,
then for the actual properties, you do it wrong.
* UI code is quite simple. Layout declarations are there to easily create a decent layout.
General rule here: If you need more code for the layout declaration, then for the actual properties, you do it wrong.
Example layouts:
- layout()
The basic layout is a simple Top -> Bottom layout.
* layout()
The basic layout is a simple Top -> Bottom layout.
.. code-block:: python
layout.prop()
layout.prop()
layout.prop()
layout.prop()
- layout.row()
Use row(), when you want more than 1 property in one line.
* layout.row()
Use row(), when you want more than 1 property in one line.
.. code-block:: python
row = layout.row()
row.prop()
row.prop()
row = layout.row()
row.prop()
row.prop()
- layout.column()
* layout.column()
Use column(), when you want your properties in a column.
.. code-block:: python
col = layout.column()
col.prop()
col.prop()
col = layout.column()
col.prop()
col.prop()
* layout.split()
- layout.split()
This can be used to create more complex layouts.
For example you can split the layout and create two column() layouts next to each other.
This can be used to create more complex layouts. For example you can split the layout and create two column() layouts next to each other.
Don't use split, when you simply want two properties in a row. Use row() for that.
.. code-block:: python
split = layout.split()
col = split.column()
col.prop()
col.prop()
col = split.column()
col.prop()
col.prop()
split = layout.split()
col = split.column()
col.prop()
col.prop()
col = split.column()
col.prop()
col.prop()
Declaration names:
Try to only use these variable names for layout declarations:
- row for a row() layout
- col for a column() layout
- split for a split() layout
- flow for a column_flow() layout
- sub for a sub layout (a column inside a column for example)
* row for a row() layout
* col for a column() layout
* split for a split() layout
* flow for a column_flow() layout
* sub for a sub layout (a column inside a column for example)
Script Efficiency
=================
List Manipulation (General Python Tips)
---------------------------------------
@@ -137,8 +133,7 @@ Searching for list items
In Python there are some handy list functions that save you having to search through the list.
Even though you're not looping on the list data **python is**,
so you need to be aware of functions that will slow down your script by searching the whole list.
Even though you're not looping on the list data **python is**, so you need to be aware of functions that will slow down your script by searching the whole list.
.. code-block:: python
@@ -150,16 +145,11 @@ so you need to be aware of functions that will slow down your script by searchin
Modifying Lists
^^^^^^^^^^^^^^^
In python we can add and remove from a list, this is slower when the list length is modified,
especially at the start of the list, since all the data after the index of
modification needs to be moved up or down 1 place.
In python we can add and remove from a list, this is slower when the list length is modified, especially at the start of the list, since all the data after the index of modification needs to be moved up or down 1 place.
The most simple way to add onto the end of the list is to use
``my_list.append(list_item)`` or ``my_list.extend(some_list)`` and the fastest way to
remove an item is ``my_list.pop()`` or ``del my_list[-1]``.
The most simple way to add onto the end of the list is to use ``my_list.append(list_item)`` or ``my_list.extend(some_list)`` and the fastest way to remove an item is ``my_list.pop()`` or ``del my_list[-1]``.
To use an index you can use ``my_list.insert(index, list_item)`` or ``list.pop(index)``
for list removal, but these are slower.
To use an index you can use ``my_list.insert(index, list_item)`` or ``list.pop(index)`` for list removal, but these are slower.
Sometimes its faster (but more memory hungry) to just rebuild the list.
@@ -203,8 +193,7 @@ Use...
my_list.extend([a, b, c...])
Note that insert can be used when needed,
but it is slower than append especially when inserting at the start of a long list.
Note that insert can be used when needed, but it is slower than append especially when inserting at the start of a long list.
This example shows a very sub-optimal way of making a reversed list.
@@ -216,8 +205,7 @@ This example shows a very sub-optimal way of making a reversed list.
reverse_list.insert(0, list_item)
Python provides more convenient ways to reverse a list using the slice method,
but you may want to time this before relying on it too much:
Python provides more convenient ways to reverse a list using the slice method, but you may want to time this before relying on it too much:
.. code-block:: python
@@ -232,8 +220,7 @@ Use ``my_list.pop(index)`` rather than ``my_list.remove(list_item)``
This requires you to have the index of the list item but is faster since ``remove()`` will search the list.
Here is an example of how to remove items in 1 loop,
removing the last items first, which is faster (as explained above).
Here is an example of how to remove items in 1 loop, removing the last items first, which is faster (as explained above).
.. code-block:: python
@@ -245,9 +232,7 @@ removing the last items first, which is faster (as explained above).
my_list.pop(list_index)
This example shows a fast way of removing items,
for use in cases where you can alter the list order without breaking the scripts functionality.
This works by swapping 2 list items, so the item you remove is always last.
This example shows a fast way of removing items, for use in cases where you can alter the list order without breaking the scripts functionality. This works by swapping 2 list items, so the item you remove is always last.
.. code-block:: python
@@ -266,9 +251,7 @@ When removing many items in a large list this can provide a good speedup.
Avoid Copying Lists
^^^^^^^^^^^^^^^^^^^
When passing a list/dictionary to a function,
it is faster to have the function modify the list rather than returning
a new list so python doesn't have to duplicate the list in memory.
When passing a list/dictionary to a function, it is faster to have the function modify the list rather than returning a new list so python doesn't have to duplicate the list in memory.
Functions that modify a list in-place are more efficient than functions that create new lists.
@@ -313,26 +296,20 @@ Pythons string joining function. To join a list of strings
>>> file.write(" ".join([str1, str2, str3, "\n"]))
join is fastest on many strings,
`string formatting <http://docs.python.org/py3k/library/string.html#string-formatting>`__
is quite fast too (better for converting data types). String arithmetic is slowest.
join is fastest on many strings, `string formatting <http://docs.python.org/py3k/library/string.html#string-formatting>`_ is quite fast too (better for converting data types). String arithmetic is slowest.
Parsing Strings (Import/Exporting)
----------------------------------
Since many file formats are ASCII,
the way you parse/export strings can make a large difference in how fast your script runs.
Since many file formats are ASCII, the way you parse/export strings can make a large difference in how fast your script runs.
There are a few ways to parse strings when importing them into Blender.
Parsing Numbers
^^^^^^^^^^^^^^^
Use ``float(string)`` rather than ``eval(string)``, if you know the value will be an int then ``int(string)``,
float() will work for an int too but it's faster to read ints with int().
Use ``float(string)`` rather than ``eval(string)``, if you know the value will be an int then ``int(string)``, float() will work for an int too but it's faster to read ints with int().
Checking String Start/End
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -345,8 +322,7 @@ Use...
>>> if line.startswith("vert "):
Using ``startswith()`` is slightly faster (approx 5%) and also avoids a possible
error with the slice length not matching the string length.
Using ``startswith()`` is slightly faster (approx 5%) and also avoids a possible error with the slice length not matching the string length.
my_string.endswith("foo_bar") can be used for line endings too.
@@ -360,19 +336,15 @@ Use try/except Sparingly
The **try** statement is useful to save time writing error checking code.
However **try** is significantly slower than an **if** since an exception has to be set each time,
so avoid using **try** in areas of your code that execute in a loop and runs many times.
However **try** is significantly slower than an **if** since an exception has to be set each time, so avoid using **try** in areas of your code that execute in a loop and runs many times.
There are cases where using **try** is faster than checking whether the condition will raise an error,
so it is worth experimenting.
There are cases where using **try** is faster than checking whether the condition will raise an error, so it is worth experimenting.
Value Comparison
----------------
Python has two ways to compare values ``a == b`` and ``a is b``,
the difference is that ``==`` may run the objects comparison function ``__cmp__()`` whereas ``is`` compares identity,
that both variables reference the same item in memory.
Python has two ways to compare values ``a == b`` and ``a is b``, the difference is that ``==`` may run the objects comparison function ``__cmp__()`` whereas ``is`` compares identity, that both variables reference the same item in memory.
In cases where you know you are checking for the same value which is referenced from multiple places, ``is`` is faster.
@@ -390,4 +362,3 @@ While developing a script it's good to time it to be aware of any changes in per
# do something...
print("My Script Finished: %.4f sec" % time.time() - time_start)

View File

@@ -2,8 +2,7 @@
Gotchas
*******
This document attempts to help you work with the Blender API in areas
that can be troublesome and avoid practices that are known to give instability.
This document attempts to help you work with the Blender API in areas that can be troublesome and avoid practices that are known to give instability.
.. _using_operators:
@@ -11,15 +10,16 @@ that can be troublesome and avoid practices that are known to give instability.
Using Operators
===============
Blender's operators are tools for users to access, that Python can access them too is very useful
nevertheless operators have limitations that can make them cumbersome to script.
Blender's operators are tools for users to access, that python can access them too is very useful nevertheless operators have limitations that can make them cumbersome to script.
Main limits are...
- Can't pass data such as objects, meshes or materials to operate on (operators use the context instead)
- The return value from calling an operator gives the success (if it finished or was canceled),
* Can't pass data such as objects, meshes or materials to operate on (operators use the context instead)
* The return value from calling an operator gives the success (if it finished or was canceled),
in some cases it would be more logical from an API perspective to return the result of the operation.
- Operators poll function can fail where an API function would raise an exception giving details on exactly why.
* Operators poll function can fail where an API function would raise an exception giving details on exactly why.
Why does an operator's poll fail?
@@ -32,28 +32,20 @@ When calling an operator gives an error like this:
Which raises the question as to what the correct context might be?
Typically operators check for the active area type, a selection or active object they can operate on,
but some operators are more picky about when they run.
Typically operators check for the active area type, a selection or active object they can operate on, but some operators are more picky about when they run.
In most cases you can figure out what context an operator needs
simply be seeing how it's used in Blender and thinking about what it does.
In most cases you can figure out what context an operator needs simply be seeing how it's used in Blender and thinking about what it does.
Unfortunately if you're still stuck - the only way to **really** know
whats going on is to read the source code for the poll function and see what its checking.
Unfortunately if you're still stuck - the only way to **really** know whats going on is to read the source code for the poll function and see what its checking.
For Python operators it's not so hard to find the source
since it's included with Blender and the source file/line is included in the operator reference docs.
For python operators it's not so hard to find the source since it's included with Blender and the source file/line is included in the operator reference docs.
Downloading and searching the C code isn't so simple,
especially if you're not familiar with the C language but by searching the
operator name or description you should be able to find the poll function with no knowledge of C.
Downloading and searching the C code isn't so simple, especially if you're not familiar with the C language but by searching the operator name or description you should be able to find the poll function with no knowledge of C.
.. note::
Blender does have the functionality for poll functions to describe why they fail,
but its currently not used much, if you're interested to help improve our API
feel free to add calls to ``CTX_wm_operator_poll_msg_set`` where its not obvious why poll fails.
Blender does have the functionality for poll functions to describe why they fail, but its currently not used much, if you're interested to help improve our API feel free to add calls to ``CTX_wm_operator_poll_msg_set`` where its not obvious why poll fails.
>>> bpy.ops.gpencil.draw()
RuntimeError: Operator bpy.ops.gpencil.draw.poll() Failed to find Grease Pencil data to draw into
@@ -62,45 +54,36 @@ operator name or description you should be able to find the poll function with n
The operator still doesn't work!
--------------------------------
Certain operators in Blender are only intended for use in a specific context,
some operators for example are only called from the properties window where they check the current material,
modifier or constraint.
Certain operators in Blender are only intended for use in a specific context, some operators for example are only called from the properties window where they check the current material, modifier or constraint.
Examples of this are:
- :mod:`bpy.ops.texture.slot_move`
- :mod:`bpy.ops.constraint.limitdistance_reset`
- :mod:`bpy.ops.object.modifier_copy`
- :mod:`bpy.ops.buttons.file_browse`
* :mod:`bpy.ops.texture.slot_move`
* :mod:`bpy.ops.constraint.limitdistance_reset`
* :mod:`bpy.ops.object.modifier_copy`
* :mod:`bpy.ops.buttons.file_browse`
Another possibility is that you are the first person to attempt to use this operator
in a script and some modifications need to be made to the operator to run in a different context,
if the operator should logically be able to run but fails when accessed from a script
it should be reported to the bug tracker.
Another possibility is that you are the first person to attempt to use this operator in a script and some modifications need to be made to the operator to run in a different context, if the operator should logically be able to run but fails when accessed from a script it should be reported to the bug tracker.
Stale Data
==========
No updates after setting values
-------------------------------
Sometimes you want to modify values from Python and immediately access the updated values, eg:
Sometimes you want to modify values from python and immediately access the updated values, eg:
Once changing the objects :class:`bpy.types.Object.location`
you may want to access its transformation right after from :class:`bpy.types.Object.matrix_world`,
but this doesn't work as you might expect.
Once changing the objects :class:`bpy.types.Object.location` you may want to access its transformation right after from :class:`bpy.types.Object.matrix_world`, but this doesn't work as you might expect.
Consider the calculations that might go into working out the object's final transformation, this includes:
- animation function curves.
- drivers and their Python expressions.
- constraints
- parent objects and all of their f-curves, constraints etc.
* animation function curves.
* drivers and their pythons expressions.
* constraints
* parent objects and all of their f-curves, constraints etc.
To avoid expensive recalculations every time a property is modified,
Blender defers making the actual calculations until they are needed.
To avoid expensive recalculations every time a property is modified, Blender defers making the actual calculations until they are needed.
However, while the script runs you may want to access the updated values.
In this case you need to call :class:`bpy.types.Scene.update` after modifying values, for example:
@@ -111,9 +94,7 @@ In this case you need to call :class:`bpy.types.Scene.update` after modifying va
bpy.context.scene.update()
Now all dependent data (child objects, modifiers, drivers... etc)
has been recalculated and is available to the script.
Now all dependent data (child objects, modifiers, drivers... etc) has been recalculated and is available to the script.
Can I redraw during the script?
-------------------------------
@@ -122,33 +103,23 @@ The official answer to this is no, or... *"You don't want to do that"*.
To give some background on the topic...
While a script executes Blender waits for it to finish and is effectively locked until its done,
while in this state Blender won't redraw or respond to user input.
Normally this is not such a problem because scripts distributed with Blender
tend not to run for an extended period of time,
nevertheless scripts *can* take ages to execute and its nice to see whats going on in the view port.
While a script executes Blender waits for it to finish and is effectively locked until its done, while in this state Blender won't redraw or respond to user input.
Normally this is not such a problem because scripts distributed with Blender tend not to run for an extended period of time, nevertheless scripts *can* take ages to execute and its nice to see whats going on in the view port.
Tools that lock Blender in a loop and redraw are highly discouraged
since they conflict with Blenders ability to run multiple operators
at once and update different parts of the interface as the tool runs.
Tools that lock Blender in a loop and redraw are highly discouraged since they conflict with Blenders ability to run multiple operators at once and update different parts of the interface as the tool runs.
So the solution here is to write a **modal** operator, that is - an operator which defines a modal() function,
See the modal operator template in the text editor.
So the solution here is to write a **modal** operator, that is - an operator which defines a modal() function, See the modal operator template in the text editor.
Modal operators execute on user input or setup their own timers to run frequently,
they can handle the events or pass through to be handled by the keymap or other modal operators.
Modal operators execute on user input or setup their own timers to run frequently, they can handle the events or pass through to be handled by the keymap or other modal operators.
Transform, Painting, Fly-Mode and File-Select are example of a modal operators.
Writing modal operators takes more effort than a simple ``for`` loop
that happens to redraw but is more flexible and integrates better with Blenders design.
Writing modal operators takes more effort than a simple ``for`` loop that happens to redraw but is more flexible and integrates better with Blenders design.
**Ok, Ok! I still want to draw from Python**
**Ok, Ok! I still want to draw from python**
If you insist - yes its possible, but scripts that use this hack wont be considered
for inclusion in Blender and any issues with using it wont be considered bugs,
this is also not guaranteed to work in future releases.
If you insist - yes its possible, but scripts that use this hack wont be considered for inclusion in Blender and any issues with using it wont be considered bugs, this is also not guaranteed to work in future releases.
.. code-block:: python
@@ -158,18 +129,16 @@ this is also not guaranteed to work in future releases.
Modes and Mesh Access
=====================
When working with mesh data you may run into the problem where a script fails to run as expected in edit-mode.
This is caused by edit-mode having its own data which is only written back to the mesh when exiting edit-mode.
When working with mesh data you may run into the problem where a script fails to run as expected in edit-mode. This is caused by edit-mode having its own data which is only written back to the mesh when exiting edit-mode.
A common example is that exporters may access a mesh through ``obj.data`` (a :class:`bpy.types.Mesh`)
but the user is in edit-mode, where the mesh data is available but out of sync with the edit mesh.
A common example is that exporters may access a mesh through ``obj.data`` (a :class:`bpy.types.Mesh`) but the user is in edit-mode, where the mesh data is available but out of sync with the edit mesh.
In this situation you can...
- Exit edit-mode before running the tool.
- Explicitly update the mesh by calling :class:`bmesh.types.BMesh.to_mesh`.
- Modify the script to support working on the edit-mode data directly, see: :mod:`bmesh.from_edit_mesh`.
- Report the context as incorrect and only allow the script to run outside edit-mode.
* Exit edit-mode before running the tool.
* Explicitly update the mesh by calling :class:`bmesh.types.BMesh.to_mesh`.
* Modify the script to support working on the edit-mode data directly, see: :mod:`bmesh.from_edit_mesh`.
* Report the context as incorrect and only allow the script to run outside edit-mode.
.. _info_gotcha_mesh_faces:
@@ -177,55 +146,35 @@ In this situation you can...
NGons and Tessellation Faces
============================
Since 2.63 NGons are supported, this adds some complexity
since in some cases you need to access triangles/quads still (some exporters for example).
Since 2.63 NGons are supported, this adds some complexity since in some cases you need to access triangles/quads still (some exporters for example).
There are now 3 ways to access faces:
- :class:`bpy.types.MeshPolygon` -
this is the data structure which now stores faces in object mode
(access as ``mesh.polygons`` rather than ``mesh.faces``).
- :class:`bpy.types.MeshTessFace` -
the result of triangulating (tessellated) polygons,
the main method of face access in 2.62 or older (access as ``mesh.tessfaces``).
- :class:`bmesh.types.BMFace` -
the polygons as used in editmode.
* :class:`bpy.types.MeshPolygon` - this is the data structure which now stores faces in object mode (access as ``mesh.polygons`` rather then ``mesh.faces``).
* :class:`bpy.types.MeshTessFace` - the result of triangulating (tessellated) polygons, the main method of face access in 2.62 or older (access as ``mesh.tessfaces``).
* :class:`bmesh.types.BMFace` - the polygons as used in editmode.
For the purpose of the following documentation,
these will be referred to as polygons, tessfaces and bmesh-faces respectively.
For the purpose of the following documentation, these will be referred to as polygons, tessfaces and bmesh-faces respectively.
5+ sided faces will be referred to as ``ngons``.
Support Overview
----------------
.. list-table::
:header-rows: 1
:stub-columns: 1
+--------------+------------------------------+--------------------------------+--------------------------------+
|Usage |:class:`bpy.types.MeshPolygon`|:class:`bpy.types.MeshTessFace` |:class:`bmesh.types.BMFace` |
+==============+==============================+================================+================================+
|Import/Create |Bad (inflexible) |Fine (supported as upgrade path)|Best |
+--------------+------------------------------+--------------------------------+--------------------------------+
|Manipulate |Bad (inflexible) |Bad (loses ngons) |Best |
+--------------+------------------------------+--------------------------------+--------------------------------+
|Export/Output |Good (ngons) |Good (When ngons can't be used) |Good (ngons, memory overhead) |
+--------------+------------------------------+--------------------------------+--------------------------------+
* - Usage
- :class:`bpy.types.MeshPolygon`
- :class:`bpy.types.MeshTessFace`
- :class:`bmesh.types.BMFace`
* - Import/Create
- Poor *(inflexible)*
- Good *(supported as upgrade path)*
- Best
* - Manipulate
- Poor *(inflexible)*
- Poor *(loses ngons)*
- Best
* - Export/Output
- Good *(ngon support)*
- Good *(When ngons can't be used)*
- Good *(ngons, extra memory overhead)*
.. note::
Using the :mod:`bmesh` api is completely separate api from :mod:`bpy`,
typically you would would use one or the other based on the level of editing needed,
not simply for a different way to access faces.
Using the :mod:`bmesh` api is completely separate api from :mod:`bpy`, typically you would would use one or the other based on the level of editing needed, not simply for a different way to access faces.
Creating
@@ -233,18 +182,9 @@ Creating
All 3 datatypes can be used for face creation.
- polygons are the most efficient way to create faces but the data structure is _very_ rigid and inflexible,
you must have all your vertes and faces ready and create them all at once.
This is further complicated by the fact that each polygon does not store its own verts (as with tessfaces),
rather they reference an index and size in :class:`bpy.types.Mesh.loops` which are a fixed array too.
- tessfaces ideally should not be used for creating faces since they are really only tessellation cache of polygons,
however for scripts upgrading from 2.62 this is by far the most straightforward option.
This works by creating tessfaces and when finished -
they can be converted into polygons by calling :class:`bpy.types.Mesh.update`.
The obvious limitation is ngons can't be created this way.
- bmesh-faces are most likely the easiest way for new scripts to create faces,
since faces can be added one by one and the api has features intended for mesh manipulation.
While :class:`bmesh.types.BMesh` uses more memory it can be managed by only operating on one mesh at a time.
* polygons are the most efficient way to create faces but the data structure is _very_ rigid and inflexible, you must have all your vertes and faces ready and create them all at once. This is further complicated by the fact that each polygon does not store its own verts (as with tessfaces), rather they reference an index and size in :class:`bpy.types.Mesh.loops` which are a fixed array too.
* tessfaces ideally should not be used for creating faces since they are really only tessellation cache of polygons, however for scripts upgrading from 2.62 this is by far the most straightforward option. This works by creating tessfaces and when finished - they can be converted into polygons by calling :class:`bpy.types.Mesh.update`. The obvious limitation is ngons can't be created this way.
* bmesh-faces are most likely the easiest way for new scripts to create faces, since faces can be added one by one and the api has features intended for mesh manipulation. While :class:`bmesh.types.BMesh` uses more memory it can be managed by only operating on one mesh at a time.
Editing
@@ -252,24 +192,18 @@ Editing
Editing is where the 3 data types vary most.
- Polygons are very limited for editing,
changing materials and options like smooth works but for anything else
they are too inflexible and are only intended for storage.
- Tessfaces should not be used for editing geometry because doing so will cause existing ngons to be tessellated.
- BMesh-Faces are by far the best way to manipulate geometry.
* polygons are very limited for editing, changing materials and options like smooth works but for anything else they are too inflexible and are only intended for storage.
* tessfaces should not be used for editing geometry because doing so will cause existing ngons to be tessellated.
* bmesh-faces are by far the best way to manipulate geometry.
Exporting
---------
All 3 data types can be used for exporting,
the choice mostly depends on whether the target format supports ngons or not.
All 3 data types can be used for exporting, the choice mostly depends on whether the target format supports ngons or not.
- Polygons are the most direct & efficient way to export providing they convert into the output format easily enough.
- Tessfaces work well for exporting to formats which dont support ngons,
in fact this is the only place where their use is encouraged.
- BMesh-Faces can work for exporting too but may not be necessary if polygons can be used
since using bmesh gives some overhead because its not the native storage format in object mode.
* polygons are the most direct & efficient way to export providing they convert into the output format easily enough.
* tessfaces work well for exporting to formats which dont support ngons, in fact this is the only place where their use is encouraged.
* bmesh-faces can work for exporting too but may not be necessary if polygons can be used since using bmesh gives some overhead because its not the native storage format in object mode.
Upgrading Importers from 2.62
@@ -279,9 +213,9 @@ Importers can be upgraded to work with only minor changes.
The main change to be made is used the tessellation versions of each attribute.
- mesh.faces --> :class:`bpy.types.Mesh.tessfaces`
- mesh.uv_textures --> :class:`bpy.types.Mesh.tessface_uv_textures`
- mesh.vertex_colors --> :class:`bpy.types.Mesh.tessface_vertex_colors`
* mesh.faces --> :class:`bpy.types.Mesh.tessfaces`
* mesh.uv_textures --> :class:`bpy.types.Mesh.tessface_uv_textures`
* mesh.vertex_colors --> :class:`bpy.types.Mesh.tessface_vertex_colors`
Once the data is created call :class:`bpy.types.Mesh.update` to convert the tessfaces into polygons.
@@ -289,9 +223,7 @@ Once the data is created call :class:`bpy.types.Mesh.update` to convert the tess
Upgrading Exporters from 2.62
-----------------------------
For exporters the most direct way to upgrade is to use tessfaces as with importing
however its important to know that tessfaces may **not** exist for a mesh,
the array will be empty as if there are no faces.
For exporters the most direct way to upgrade is to use tessfaces as with importing however its important to know that tessfaces may **not** exist for a mesh, the array will be empty as if there are no faces.
So before accessing tessface data call: :class:`bpy.types.Mesh.update` ``(calc_tessface=True)``.
@@ -299,8 +231,7 @@ So before accessing tessface data call: :class:`bpy.types.Mesh.update` ``(calc_t
EditBones, PoseBones, Bone... Bones
===================================
Armature Bones in Blender have three distinct data structures that contain them.
If you are accessing the bones through one of them, you may not have access to the properties you really need.
Armature Bones in Blender have three distinct data structures that contain them. If you are accessing the bones through one of them, you may not have access to the properties you really need.
.. note::
@@ -310,9 +241,7 @@ If you are accessing the bones through one of them, you may not have access to t
Edit Bones
----------
``bpy.context.object.data.edit_bones`` contains a editbones;
to access them you must set the armature mode to edit mode first (editbones do not exist in object or pose mode).
Use these to create new bones, set their head/tail or roll, change their parenting relationships to other bones, etc.
``bpy.context.object.data.edit_bones`` contains a editbones; to access them you must set the armature mode to edit mode first (editbones do not exist in object or pose mode). Use these to create new bones, set their head/tail or roll, change their parenting relationships to other bones, etc.
Example using :class:`bpy.types.EditBone` in armature editmode:
@@ -332,9 +261,7 @@ Returns an editbone only in edit mode.
Bones (Object Mode)
-------------------
``bpy.context.object.data.bones`` contains bones.
These *live* in object mode, and have various properties you can change,
note that the head and tail properties are read-only.
``bpy.context.object.data.bones`` contains bones. These *live* in object mode, and have various properties you can change, note that the head and tail properties are read-only.
Example using :class:`bpy.types.Bone` in object or pose mode:
@@ -354,9 +281,7 @@ Accessible but read-only
Pose Bones
----------
``bpy.context.object.pose.bones`` contains pose bones.
This is where animation data resides, i.e. animatable transformations
are applied to pose bones, as are constraints and ik-settings.
``bpy.context.object.pose.bones`` contains pose bones. This is where animation data resides, i.e. animatable transformations are applied to pose bones, as are constraints and ik-settings.
Examples using :class:`bpy.types.PoseBone` in object or pose mode:
@@ -371,27 +296,19 @@ Examples using :class:`bpy.types.PoseBone` in object or pose mode:
.. note::
Notice the pose is accessed from the object rather than the object data,
this is why blender can have 2 or more objects sharing the same armature in different poses.
Notice the pose is accessed from the object rather than the object data, this is why blender can have 2 or more objects sharing the same armature in different poses.
.. note::
Strictly speaking PoseBone's are not bones, they are just the state of the armature,
stored in the :class:`bpy.types.Object` rather than the :class:`bpy.types.Armature`,
the real bones are however accessible from the pose bones - :class:`bpy.types.PoseBone.bone`
Strictly speaking PoseBone's are not bones, they are just the state of the armature, stored in the :class:`bpy.types.Object` rather than the :class:`bpy.types.Armature`, the real bones are however accessible from the pose bones - :class:`bpy.types.PoseBone.bone`
Armature Mode Switching
-----------------------
While writing scripts that deal with armatures you may find you have to switch between modes,
when doing so take care when switching out of edit-mode not to keep references
to the edit-bones or their head/tail vectors.
Further access to these will crash blender so its important the script
clearly separates sections of the code which operate in different modes.
While writing scripts that deal with armatures you may find you have to switch between modes, when doing so take care when switching out of editmode not to keep references to the edit-bones or their head/tail vectors. Further access to these will crash blender so its important the script clearly separates sections of the code which operate in different modes.
This is mainly an issue with editmode since pose data can be manipulated without having to be in pose mode,
however for operator access you may still need to enter pose mode.
This is mainly an issue with editmode since pose data can be manipulated without having to be in pose mode, however for operator access you may still need to enter pose mode.
Data Names
@@ -426,13 +343,10 @@ Or with name assignment...
Data names may not match the assigned values if they exceed the maximum length, are already used or an empty string.
Its better practice not to reference objects by names at all,
once created you can store the data in a list, dictionary, on a class etc,
there is rarely a reason to have to keep searching for the same data by name.
Its better practice not to reference objects by names at all, once created you can store the data in a list, dictionary, on a class etc, there is rarely a reason to have to keep searching for the same data by name.
If you do need to use name references, its best to use a dictionary to maintain
a mapping between the names of the imported assets and the newly created data,
this way you don't run this risk of referencing existing data from the blend file, or worse modifying it.
If you do need to use name references, its best to use a dictionary to maintain a mapping between the names of the imported assets and the newly created data, this way you don't run this risk of referencing existing data from the blend file, or worse modifying it.
.. code-block:: python
@@ -444,22 +358,18 @@ this way you don't run this risk of referencing existing data from the blend fil
# normally some code, or function calls...
# use own dictionary rather than bpy.data
# use own dictionary rather then bpy.data
mesh = mesh_name_mapping[meshid]
Library Collisions
------------------
Blender keeps data names unique - :class:`bpy.types.ID.name` so you can't name two objects,
meshes, scenes etc the same thing by accident.
Blender keeps data names unique - :class:`bpy.types.ID.name` so you can't name two objects, meshes, scenes etc the same thing by accident.
However when linking in library data from another blend file naming collisions can occur,
so its best to avoid referencing data by name at all.
However when linking in library data from another blend file naming collisions can occur, so its best to avoid referencing data by name at all.
This can be tricky at times and not even blender handles this correctly in some case
(when selecting the modifier object for eg you can't select between multiple objects with the same name),
but its still good to try avoid problems in this area.
This can be tricky at times and not even blender handles this correctly in some case (when selecting the modifier object for eg you can't select between multiple objects with the same name), but its still good to try avoid problems in this area.
If you need to select between local and library data, there is a feature in ``bpy.data`` members to allow for this.
@@ -484,23 +394,21 @@ If you need to select between local and library data, there is a feature in ``bp
Relative File Paths
===================
Blenders relative file paths are not compatible with standard Python modules such as ``sys`` and ``os``.
Blenders relative file paths are not compatible with standard python modules such as ``sys`` and ``os``.
Built in Python functions don't understand blenders ``//`` prefix which denotes the blend file path.
Built in python functions don't understand blenders ``//`` prefix which denotes the blend file path.
A common case where you would run into this problem is when exporting a material with associated image paths.
>>> bpy.path.abspath(image.filepath)
>>> bpy.path.abspath(image.filepath)
When using blender data from linked libraries there is an unfortunate complication
since the path will be relative to the library rather than the open blend file.
When the data block may be from an external blend file pass the library argument from the :class:`bpy.types.ID`.
When using blender data from linked libraries there is an unfortunate complication since the path will be relative to the library rather then the open blend file. When the data block may be from an external blend file pass the library argument from the :class:`bpy.types.ID`.
>>> bpy.path.abspath(image.filepath, library=image.library)
>>> bpy.path.abspath(image.filepath, library=image.library)
These returns the absolute path which can be used with native Python modules.
These returns the absolute path which can be used with native python modules.
Unicode Problems
@@ -541,28 +449,23 @@ Here are 2 ways around filesystem encoding issues:
>>> bpy.context.object.name = filepath_utf8
Unicode encoding/decoding is a big topic with comprehensive Python documentation,
to avoid getting stuck too deep in encoding problems - here are some suggestions:
Unicode encoding/decoding is a big topic with comprehensive python documentation, to avoid getting stuck too deep in encoding problems - here are some suggestions:
- Always use utf-8 encoding or convert to utf-8 where the input is unknown.
- Avoid manipulating filepaths as strings directly, use ``os.path`` functions instead.
- Use ``os.fsencode()`` / ``os.fsdecode()`` instead of built in string decoding functions when operating on paths.
- To print paths or to include them in the user interface use ``repr(path)`` first
or ``"%r" % path`` with string formatting.
* Always use utf-8 encoiding or convert to utf-8 where the input is unknown.
.. note::
* Avoid manipulating filepaths as strings directly, use ``os.path`` functions instead.
Sometimes it's preferrable to avoid string encoding issues by using bytes instead of Python strings,
when reading some input its less trouble to read it as binary data
though you will still need to decide how to treat any strings you want to use with Blender,
some importers do this.
* Use ``os.fsencode()`` / ``os.fsdecode()`` rather then the built in string decoding functions when operating on paths.
* To print paths or to include them in the user interface use ``repr(path)`` first or ``"%r" % path`` with string formatting.
* **Possibly** - use bytes instead of python strings, when reading some input its less trouble to read it as binary data though you will still need to decide how to treat any strings you want to use with Blender, some importers do this.
Strange errors using 'threading' module
=======================================
Python threading with Blender only works properly when the threads finish up before the script does.
By using ``threading.join()`` for example.
Python threading with Blender only works properly when the threads finish up before the script does. By using ``threading.join()`` for example.
Heres an example of threading supported by Blender:
@@ -601,8 +504,7 @@ Heres an example of threading supported by Blender:
t.join()
This an example of a timer which runs many times a second and moves
the default cube continuously while Blender runs **(Unsupported)**.
This an example of a timer which runs many times a second and moves the default cube continuously while Blender runs **(Unsupported)**.
.. code-block:: python
@@ -619,48 +521,38 @@ the default cube continuously while Blender runs **(Unsupported)**.
my_timer()
Use cases like the one above which leave the thread running once the script finishes
may seem to work for a while but end up causing random crashes or errors in Blender's own drawing code.
Use cases like the one above which leave the thread running once the script finishes may seem to work for a while but end up causing random crashes or errors in Blender's own drawing code.
So far, no work has gone into making Blender's Python integration thread safe,
so until its properly supported, best not make use of this.
So far, no work has gone into making Blender's python integration thread safe, so until its properly supported, best not make use of this.
.. note::
Pythons threads only allow co-currency and won't speed up your scripts on multi-processor systems,
the ``subprocess`` and ``multiprocess`` modules can be used with Blender and make use of multiple CPU's too.
Pythons threads only allow co-currency and won't speed up your scripts on multi-processor systems, the ``subprocess`` and ``multiprocess`` modules can be used with Blender and make use of multiple CPU's too.
Help! My script crashes Blender
===============================
Ideally it would be impossible to crash Blender from Python
however there are some problems with the API where it can be made to crash.
Ideally it would be impossible to crash Blender from python however there are some problems with the API where it can be made to crash.
Strictly speaking this is a bug in the API but fixing it would mean adding memory verification
on every access since most crashes are caused by the Python objects referencing Blenders memory directly,
whenever the memory is freed, further Python access to it can crash the script.
But fixing this would make the scripts run very slow,
or writing a very different kind of API which doesn't reference the memory directly.
Strictly speaking this is a bug in the API but fixing it would mean adding memory verification on every access since most crashes are caused by the python objects referencing Blenders memory directly, whenever the memory is freed, further python access to it can crash the script. But fixing this would make the scripts run very slow, or writing a very different kind of API which doesn't reference the memory directly.
Here are some general hints to avoid running into these problems.
- Be aware of memory limits,
especially when working with large lists since Blender can crash simply by running out of memory.
- Many hard to fix crashes end up being because of referencing freed data,
when removing data be sure not to hold any references to it.
- Modules or classes that remain active while Blender is used,
should not hold references to data the user may remove, instead,
fetch data from the context each time the script is activated.
- Crashes may not happen every time, they may happen more on some configurations/operating-systems.
* Be aware of memory limits, especially when working with large lists since Blender can crash simply by running out of memory.
* Many hard to fix crashes end up being because of referencing freed data, when removing data be sure not to hold any references to it.
* Modules or classes that remain active while Blender is used, should not hold references to data the user may remove, instead, fetch data from the context each time the script is activated.
* Crashes may not happen every time, they may happen more on some configurations/operating-systems.
.. note::
To find the line of your script that crashes you can use the ``faulthandler`` module.
See `faulthandler docs <http://docs.python.org/dev/library/faulthandler.html>`_.
While the crash may be in Blenders C/C++ code,
this can help a lot to track down the area of the script that causes the crash.
While the crash may be in Blenders C/C++ code, this can help a lot to track down the area of the script that causes the crash.
Undo/Redo
@@ -680,36 +572,28 @@ This example shows how you can tell undo changes the memory locations.
>>> hash(bpy.context.object)
-9223372036849951740
As suggested above, simply not holding references to data when Blender is used
interactively by the user is the only way to ensure the script doesn't become unstable.
As suggested above, simply not holding references to data when Blender is used interactively by the user is the only way to ensure the script doesn't become unstable.
Undo & Library Data
^^^^^^^^^^^^^^^^^^^
One of the advantages with Blenders library linking system that undo
can skip checking changes in library data since it is assumed to be static.
One of the advantages with Blenders library linking system that undo can skip checking changes in library data since it is assumed to be static.
Tools in Blender are not allowed to modify library data.
Python however does not enforce this restriction.
This can be useful in some cases, using a script to adjust material values for example.
But its also possible to use a script to make library data point to newly created local data,
which is not supported since a call to undo will remove the local data
but leave the library referencing it and likely crash.
But its also possible to use a script to make library data point to newly created local data, which is not supported since a call to undo will remove the local data but leave the library referencing it and likely crash.
So it's best to consider modifying library data an advanced usage of the API
and only to use it when you know what you're doing.
So it's best to consider modifying library data an advanced usage of the API and only to use it when you know what you're doing.
Edit Mode / Memory Access
-------------------------
Switching edit-mode ``bpy.ops.object.mode_set(mode='EDIT')`` / ``bpy.ops.object.mode_set(mode='OBJECT')``
will re-allocate objects data,
any references to a meshes vertices/polygons/uvs, armatures bones,
curves points etc cannot be accessed after switching edit-mode.
Switching edit-mode ``bpy.ops.object.mode_set(mode='EDIT')`` / ``bpy.ops.object.mode_set(mode='OBJECT')`` will re-allocate objects data, any references to a meshes vertices/polygons/uvs, armatures bones, curves points etc cannot be accessed after switching edit-mode.
Only the reference to the data its self can be re-accessed, the following example will crash.
@@ -724,8 +608,7 @@ Only the reference to the data its self can be re-accessed, the following exampl
print(polygons)
So after switching edit-mode you need to re-access any object data variables,
the following example shows how to avoid the crash above.
So after switching edit-mode you need to re-access any object data variables, the following example shows how to avoid the crash above.
.. code-block:: python
@@ -739,15 +622,13 @@ the following example shows how to avoid the crash above.
print(polygons)
These kinds of problems can happen for any functions which re-allocate
the object data but are most common when switching edit-mode.
These kinds of problems can happen for any functions which re-allocate the object data but are most common when switching edit-mode.
Array Re-Allocation
-------------------
When adding new points to a curve or vertices's/edges/polygons to a mesh,
internally the array which stores this data is re-allocated.
When adding new points to a curve or vertices's/edges/polygons to a mesh, internally the array which stores this data is re-allocated.
.. code-block:: python
@@ -758,20 +639,15 @@ internally the array which stores this data is re-allocated.
# this will crash!
point.co = 1.0, 2.0, 3.0
This can be avoided by re-assigning the point variables after adding the new one or by storing
indices's to the points rather than the points themselves.
This can be avoided by re-assigning the point variables after adding the new one or by storing indices's to the points rather then the points themselves.
The best way is to sidestep the problem altogether add all the points to the curve at once.
This means you don't have to worry about array re-allocation and its faster too
since reallocating the entire array for every point added is inefficient.
The best way is to sidestep the problem altogether add all the points to the curve at once. This means you don't have to worry about array re-allocation and its faster too since reallocating the entire array for every point added is inefficient.
Removing Data
-------------
**Any** data that you remove shouldn't be modified or accessed afterwards,
this includes f-curves, drivers, render layers, timeline markers, modifiers, constraints
along with objects, scenes, groups, bones.. etc.
**Any** data that you remove shouldn't be modified or accessed afterwards, this includes f-curves, drivers, render layers, timeline markers, modifiers, constraints along with objects, scenes, groups, bones.. etc.
The ``remove()`` api calls will invalidate the data they free to prevent common mistakes.
@@ -782,13 +658,12 @@ The following example shows how this precortion works.
mesh = bpy.data.meshes.new(name="MyMesh")
# normally the script would use the mesh here...
bpy.data.meshes.remove(mesh)
print(mesh.name) # <- give an exception rather than crashing:
print(mesh.name) # <- give an exception rather then crashing:
# ReferenceError: StructRNA of type Mesh has been removed
But take care because this is limited to scripts accessing the variable which is removed,
the next example will still crash.
But take care because this is limited to scripts accessing the variable which is removed, the next example will still crash.
.. code-block:: python
@@ -801,11 +676,9 @@ the next example will still crash.
sys.exit
========
Some Python modules will call ``sys.exit()`` themselves when an error occurs,
while not common behavior this is something to watch out for because it may seem
as if Blender is crashing since ``sys.exit()`` will close Blender immediately.
Some python modules will call ``sys.exit()`` themselves when an error occurs, while not common behavior this is something to watch out for because it may seem as if blender is crashing since ``sys.exit()`` will quit blender immediately.
For example, the ``argparse`` module will print an error and exit if the arguments are invalid.
For example, the ``optparse`` module will print an error and exit if the arguments are invalid.
An ugly way of troubleshooting this is to set ``sys.exit = None`` and see what line of python code is quitting, you could of course replace ``sys.exit`` with your own function but manipulating python in this way is bad practice.
An ugly way of troubleshooting this is to set ``sys.exit = None`` and see what line of Python code is quitting,
you could of course replace ``sys.exit`` with your own function but manipulating Python in this way is bad practice.

View File

@@ -1,25 +1,18 @@
.. _info_overview:
*******************
Python API Overview
*******************
This document is to give an understanding of how Python and Blender fit together,
covering some of the functionality that isn't obvious from reading the API reference and example scripts.
This document is to give an understanding of how python and blender fit together, covering some of the functionality that isn't obvious from reading the API reference and example scripts.
Python in Blender
=================
Blender embeds a Python interpreter which is started with Blender and stays active.
This interpreter runs scripts to draw the user interface and is used for some of Blender's internal tools too.
Blender embeds a python interpreter which is started with blender and stays active. This interpreter runs scripts to draw the user interface and is used for some of Blender's internal tools too.
This is a typical Python environment so tutorials on how to write Python scripts
will work running the scripts in Blender too.
Blender provides the :mod:`bpy` module to the Python interpreter.
This module can be imported in a script and gives access to Blender data, classes, and functions.
Scripts that deal with Blender data will need to import this module.
This is a typical python environment so tutorials on how to write python scripts will work running the scripts in blender too. Blender provides the :mod:`bpy` module to the python interpreter. This module can be imported in a script and gives access to blender data, classes, and functions. Scripts that deal with blender data will need to import this module.
Here is a simple example of moving a vertex of the object named **Cube**:
@@ -28,96 +21,84 @@ Here is a simple example of moving a vertex of the object named **Cube**:
import bpy
bpy.data.objects["Cube"].data.vertices[0].co.x += 1.0
This modifies Blender's internal data directly.
When you run this in the interactive console you will see the 3D viewport update.
This modifies Blender's internal data directly. When you run this in the interactive console you will see the 3D viewport update.
The Default Environment
=======================
When developing your own scripts it may help to understand how Blender sets up its Python environment.
Many Python scripts come bundled with Blender and can be used as a reference
because they use the same API that script authors write tools in.
Typical usage for scripts include: user interface, import/export,
scene manipulation, automation, defining your own toolset and customization.
When developing your own scripts it may help to understand how blender sets up its python environment. Many python scripts come bundled with blender and can be used as a reference because they use the same API that script authors write tools in. Typical usage for scripts include: user interface, import/export, scene manipulation, automation, defining your own toolset and customization.
On startup Blender scans the ``scripts/startup/`` directory for Python modules and imports them.
The exact location of this directory depends on your installation.
`See the directory layout docs
<https://www.blender.org/manual/getting_started/installing_blender/directorylayout.html>`__
On startup blender scans the ``scripts/startup/`` directory for python modules and imports them. The exact location of this directory depends on your installation. `See the directory layout docs <http://wiki.blender.org/index.php/Doc:2.6/Manual/Introduction/Installing_Blender/DirectoryLayout>`_
Script Loading
==============
This may seem obvious but it's important to note the difference
between executing a script directly or importing it as a module.
This may seem obvious but it's important to note the difference between executing a script directly or importing it as a module.
Scripts that extend Blender - define classes that exist beyond the scripts execution,
this makes future access to these classes (to unregister for example)
more difficult than importing as a module where class instance is kept
in the module and can be accessed by importing that module later on.
Scripts that extend blender - define classes that exist beyond the scripts execution, this makes future access to these classes (to unregister for example) more difficult than importing as a module where class instance is kept in the module and can be accessed by importing that module later on.
For this reason it's preferable to only use directly execute scripts that don't extend Blender by registering classes.
For this reason it's preferable to only use directly execute scripts that don't extend blender by registering classes.
Here are some ways to run scripts directly in Blender.
Here are some ways to run scripts directly in blender.
- Loaded in the text editor and press **Run Script**.
- Typed or pasted into the interactive console.
- Execute a Python file from the command line with Blender, eg:
* Loaded in the text editor and press **Run Script**.
.. code-block:: sh
* Typed or pasted into the interactive console.
blender --python /home/me/my_script.py
* Execute a python file from the command line with blender, eg:
``blender --python /home/me/my_script.py``
To run as modules:
- The obvious way, ``import some_module`` command from the text window or interactive console.
- Open as a text block and tick "Register" option, this will load with the blend file.
- copy into one of the directories ``scripts/startup``, where they will be automatically imported on startup.
- define as an addon, enabling the addon will load it as a Python module.
* The obvious way, ``import some_module`` command from the text window or interactive console.
* Open as a text block and tick "Register" option, this will load with the blend file.
* copy into one of the directories ``scripts/startup``, where they will be automatically imported on startup.
* define as an addon, enabling the addon will load it as a python module.
Addons
------
Some of Blenders functionality is best kept optional,
alongside scripts loaded at startup we have addons which are kept in their own directory ``scripts/addons``,
and only load on startup if selected from the user preferences.
Some of blenders functionality is best kept optional, alongside scripts loaded at startup we have addons which are kept in their own directory ``scripts/addons``, and only load on startup if selected from the user preferences.
The only difference between addons and built-in Python modules is that addons must contain a ``bl_info``
variable which Blender uses to read metadata such as name, author, category and URL.
The only difference between addons and built-in python modules is that addons must contain a **bl_info** variable which blender uses to read metadata such as name, author, category and URL.
The user preferences addon listing uses **bl_info** to display information about each addon.
`See Addons <http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons>`__
for details on the ``bl_info`` dictionary.
`See Addons <http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons>`_ for details on the **bl_info** dictionary.
Integration through Classes
===========================
Running Python scripts in the text editor is useful for testing but you'll
want to extend Blender to make tools accessible like other built-in functionality.
Running python scripts in the text editor is useful for testing but youll want to extend blender to make tools accessible like other built-in functionality.
The Blender Python api allows integration for:
The blender python api allows integration for:
- :class:`bpy.types.Panel`
- :class:`bpy.types.Menu`
- :class:`bpy.types.Operator`
- :class:`bpy.types.PropertyGroup`
- :class:`bpy.types.KeyingSet`
- :class:`bpy.types.RenderEngine`
* :class:`bpy.types.Panel`
* :class:`bpy.types.Menu`
* :class:`bpy.types.Operator`
* :class:`bpy.types.PropertyGroup`
* :class:`bpy.types.KeyingSet`
* :class:`bpy.types.RenderEngine`
This is intentionally limited. Currently, for more advanced features such as mesh modifiers,
object types, or shader nodes, C/C++ must be used.
This is intentionally limited. Currently, for more advanced features such as mesh modifiers, object types, or shader nodes, C/C++ must be used.
For Python integration Blender defines methods which are common to all types.
This works by creating a Python subclass of a Blender class which contains variables and functions
specified by the parent class which are pre-defined to interface with Blender.
For python intergration Blender defines methods which are common to all types. This works by creating a python subclass of a Blender class which contains variables and functions specified by the parent class which are pre-defined to interface with Blender.
For example:
@@ -134,20 +115,15 @@ For example:
bpy.utils.register_class(SimpleOperator)
First note that we subclass a member of :mod:`bpy.types`,
this is common for all classes which can be integrated with Blender and
used so we know if this is an Operator and not a Panel when registering.
First note that we subclass a member of :mod:`bpy.types`, this is common for all classes which can be integrated with blender and used so we know if this is an Operator and not a Panel when registering.
Both class properties start with a ``bl_`` prefix.
This is a convention used to distinguish Blender properties from those you add yourself.
Both class properties start with a **bl_** prefix. This is a convention used to distinguish blender properties from those you add yourself.
Next see the execute function, which takes an instance of the operator and the current context.
A common prefix is not used for functions.
Next see the execute function, which takes an instance of the operator and the current context. A common prefix is not used for functions.
Lastly the register function is called, this takes the class and loads it into Blender. See `Class Registration`_.
Lastly the register function is called, this takes the class and loads it into blender. See `Class Registration`_.
Regarding inheritance, Blender doesn't impose restrictions on the kinds of class inheritance used,
the registration checks will use attributes and functions defined in parent classes.
Regarding inheritance, blender doesn't impose restrictions on the kinds of class inheritance used, the registration checks will use attributes and functions defined in parent classes.
class mix-in example:
@@ -165,20 +141,11 @@ class mix-in example:
bpy.utils.register_class(SimpleOperator)
Notice these classes don't define an ``__init__(self)`` function.
While ``__init__()`` and ``__del__()`` will be called if defined,
the class instances lifetime only spans the execution.
So a panel for example will have a new instance for every redraw,
for this reason there is rarely a cause to store variables in the panel instance.
Instead, persistent variables should be stored in Blenders
ata so that the state can be restored when Blender is restarted.
Notice these classes don't define an ``__init__(self)`` function. While ``__init__()`` and ``__del__()`` will be called if defined, the class instances lifetime only spans the execution. So a panel for example will have a new instance for every redraw, for this reason there is rarely a cause to store variables in the panel instance. Instead, persistent variables should be stored in Blenders data so that the state can be restored when blender is restarted.
.. note::
.. note:: Modal operators are an exception, keeping their instance variable as blender runs, see modal operator template.
Modal operators are an exception, keeping their instance variable as Blender runs, see modal operator template.
So once the class is registered with Blender, instancing the class and calling the functions is left up to Blender.
In fact you cannot instance these classes from the script as you would expect with most Python API's.
So once the class is registered with blender, instancing the class and calling the functions is left up to blender. In fact you cannot instance these classes from the script as you would expect with most python API's.
To run operators you can call them through the operator api, eg:
@@ -187,8 +154,7 @@ To run operators you can call them through the operator api, eg:
import bpy
bpy.ops.object.simple_operator()
User interface classes are given a context in which to draw, buttons window, file header, toolbar etc,
then they are drawn when that area is displayed so they are never called by Python scripts directly.
User interface classes are given a context in which to draw, buttons window, file header, toolbar etc, then they are drawn when that area is displayed so they are never called by python scripts directly.
Registration
@@ -198,10 +164,9 @@ Registration
Module Registration
-------------------
Blender modules loaded at startup require ``register()`` and ``unregister()`` functions.
These are the *only* functions that Blender calls from your code, which is otherwise a regular Python module.
Blender modules loaded at startup require ``register()`` and ``unregister()`` functions. These are the *only* functions that blender calls from your code, which is otherwise a regular python module.
A simple Blender/Python module can look like this:
A simple blender/python module can look like this:
.. code-block:: python
@@ -219,16 +184,12 @@ A simple Blender/Python module can look like this:
if __name__ == "__main__":
register()
These functions usually appear at the bottom of the script containing class registration sometimes adding menu items.
You can also use them for internal purposes setting up data for your own tools but take care
since register won't re-run when a new blend file is loaded.
These functions usually appear at the bottom of the script containing class registration sometimes adding menu items. You can also use them for internal purposes setting up data for your own tools but take care since register won't re-run when a new blend file is loaded.
The register/unregister calls are used so it's possible to toggle addons and reload scripts while Blender runs.
If the register calls were placed in the body of the script, registration would be called on import,
meaning there would be no distinction between importing a module or loading its classes into Blender.
The register/unregister calls are used so it's possible to toggle addons and reload scripts while blender runs.
If the register calls were placed in the body of the script, registration would be called on import, meaning there would be no distinction between importing a module or loading its classes into blender.
This becomes problematic when a script imports classes from another module
making it difficult to manage which classes are being loaded and when.
This becomes problematic when a script imports classes from another module making it difficult to manage which classes are being loaded and when.
The last 2 lines are only for testing:
@@ -238,24 +199,19 @@ The last 2 lines are only for testing:
register()
This allows the script to be run directly in the text editor to test changes.
This ``register()`` call won't run when the script is imported as a module
since ``__main__`` is reserved for direct execution.
This ``register()`` call won't run when the script is imported as a module since ``__main__`` is reserved for direct execution.
Class Registration
------------------
Registering a class with Blender results in the class definition being loaded into Blender,
where it becomes available alongside existing functionality.
Registering a class with blender results in the class definition being loaded into blender, where it becomes available alongside existing functionality.
Once this class is loaded you can access it from :mod:`bpy.types`,
using the bl_idname rather than the classes original name.
Once this class is loaded you can access it from :mod:`bpy.types`, using the bl_idname rather than the classes original name.
When loading a class, Blender performs sanity checks making sure all required properties and functions are found,
that properties have the correct type, and that functions have the right number of arguments.
When loading a class, blender performs sanity checks making sure all required properties and functions are found, that properties have the correct type, and that functions have the right number of arguments.
Mostly you will not need concern yourself with this but if there is a problem
with the class definition it will be raised on registering:
Mostly you will not need concern yourself with this but if there is a problem with the class definition it will be raised on registering:
Using the function arguments ``def execute(self, context, spam)``, will raise an exception:
@@ -269,13 +225,9 @@ Using ``bl_idname = 1`` will raise.
Multiple-Classes
^^^^^^^^^^^^^^^^
Loading classes into Blender is described above,
for simple cases calling :mod:`bpy.utils.register_class` (SomeClass) is sufficient,
but when there are many classes or a packages submodule has its own
classes it can be tedious to list them all for registration.
Loading classes into blender is described above, for simple cases calling :mod:`bpy.utils.register_class` (SomeClass) is sufficient, but when there are many classes or a packages submodule has its own classes it can be tedious to list them all for registration.
For more convenient loading/unloading :mod:`bpy.utils.register_module` (module)
and :mod:`bpy.utils.unregister_module` (module) functions exist.
For more convenient loading/unloading :mod:`bpy.utils.register_module` (module) and :mod:`bpy.utils.unregister_module` (module) functions exist.
A script which defines many of its own operators, panels menus etc. you only need to write:
@@ -287,19 +239,13 @@ A script which defines many of its own operators, panels menus etc. you only nee
def unregister():
bpy.utils.unregister_module(__name__)
Internally Blender collects subclasses on registrable types, storing them by the module in which they are defined.
By passing the module name to :mod:`bpy.utils.register_module`
Blender can register all classes created by this module and its submodules.
Internally blender collects subclasses on registrable types, storing them by the module in which they are defined. By passing the module name to :mod:`bpy.utils.register_module` blender can register all classes created by this module and its submodules.
Inter Classes Dependencies
^^^^^^^^^^^^^^^^^^^^^^^^^^
When customizing Blender you may want to group your own settings together,
after all, they will likely have to co-exist with other scripts.
To group these properties classes need to be defined,
for groups within groups or collections within groups
you can find yourself having to deal with order of registration/unregistration.
When customizing blender you may want to group your own settings together, after all, they will likely have to co-exist with other scripts. To group these properties classes need to be defined, for groups within groups or collections within groups you can find yourself having to deal with order of registration/unregistration.
Custom properties groups are themselves classes which need to be registered.
@@ -365,9 +311,7 @@ Say you want to store material settings for a custom engine.
Manipulating Classes
^^^^^^^^^^^^^^^^^^^^
Properties can be added and removed as Blender runs,
normally happens on register or unregister but for some
special cases it may be useful to modify types as the script runs.
Properties can be added and removed as blender runs, normally happens on register or unregister but for some special cases it may be useful to modify types as the script runs.
For example:
@@ -397,8 +341,7 @@ This works just as well for PropertyGroup subclasses you define yourself.
Dynamic Defined-Classes (Advanced)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In some cases the specifier for data may not be in Blender,
renderman shader definitions for example and it may be useful to define types and remove them on the fly.
In some cases the specifier for data may not be in blender, renderman shader definitions for example and it may be useful to define types and remove them on the fly.
.. code-block:: python
@@ -417,8 +360,7 @@ renderman shader definitions for example and it may be useful to define types an
.. note::
``type()`` is called to define the class.
This is an alternative syntax for class creation in Python, better suited to constructing classes dynamically.
Notice ``type()`` is called to define the class. This is an alternative syntax for class creation in python, better suited to constructing classes dynamically.
Calling these operators:

View File

@@ -1,4 +1,3 @@
.. _info_quickstart:
***********************
@@ -33,15 +32,13 @@ The Blender/Python API **can't** (yet)...
Before Starting
===============
This document isn't intended to fully cover each topic.
Rather, its purpose is to familiarize you with Blender Python API.
This document isn't intended to fully cover each topic. Rather, its purpose is to familiarize you with Blender Python API.
A quick list of helpful things to know before starting:
- Blender uses Python 3.x; some online documentation still assumes 2.x.
- The interactive console is great for testing one-liners.
It also has autocompletion so you can inspect the API quickly.
- The interactive console is great for testing one-liners, It also has autocompletion so you can inspect the API quickly.
- Button tool tips show Python attributes and operator names.
- Right clicking on buttons and menu items directly links to API documentation.
- For more examples, the text menu has a templates section where some example operators can be found.
@@ -54,19 +51,15 @@ A quick list of helpful things to know before starting:
Running Scripts
---------------
The two most common ways to execute Python scripts are using the built-in
text editor or entering commands in the Python console.
The two most common ways to execute Python scripts are using the built-in text editor or entering commands in the Python console.
Both the *Text Editor* and *Python Console* are space types you can select from the view header.
Both the **Text Editor** and **Python Console** are space types you can select from the view header.
Rather than manually configuring your spaces for Python development,
you may prefer to use the *Scripting* screen, included default with Blender,
accessible from the top headers screen selector.
Rather then manually configuring your spaces for Python development, you may prefer to use the **Scripting** screen, included default with Blender, accessible from the top headers screen selector.
From the text editor you can open ``.py`` files or paste then from the clipboard, then test using *Run Script*.
From the text editor you can open ``.py`` files or paste then from the clipboard, then test using **Run Script**.
The Python Console is typically used for typing in snippets and for testing to get immediate feedback,
but can also have entire scripts pasted into it.
The Python Console is typically used for typing in snippets and for testing to get immediate feedback, but can also have entire scripts pasted into it.
Scripts can also run from the command line with Blender but to learn Blender/Python this isn't essential.
@@ -80,11 +73,9 @@ Data Access
Accessing DataBlocks
^^^^^^^^^^^^^^^^^^^^
Python accesses Blender's data in the same way as the animation system and user interface;
this implies that any setting that can be changed via a button can also be changed from Python.
Python accesses Blender's data in the same way as the animation system and user interface; this implies that any setting that can be changed via a button can also be changed from Python.
Accessing data from the currently loaded blend file is done with the module :mod:`bpy.data`.
This gives access to library data. For example:
Accessing data from the currently loaded blend file is done with the module :mod:`bpy.data`. This gives access to library data. For example:
>>> bpy.data.objects
<bpy_collection[3], BlendDataObjects>
@@ -101,8 +92,7 @@ About Collections
You'll notice that an index as well as a string can be used to access members of the collection.
Unlike Python's dictionaries, both methods are acceptable;
however, the index of a member may change while running Blender.
Unlike Python's dictionaries, both methods are acceptable; however, the index of a member may change while running Blender.
>>> list(bpy.data.objects)
[bpy.data.objects["Cube"], bpy.data.objects["Plane"]]
@@ -117,10 +107,7 @@ however, the index of a member may change while running Blender.
Accessing Attributes
^^^^^^^^^^^^^^^^^^^^
Once you have a data block, such as a material, object, groups etc.,
its attributes can be accessed much like you would change a setting using the graphical interface.
In fact, the tooltip for each button also displays the Python attribute
which can help in finding what settings to change in a script.
Once you have a data block, such as a material, object, groups etc., its attributes can be accessed much like you would change a setting using the graphical interface. In fact, the tooltip for each button also displays the Python attribute which can help in finding what settings to change in a script.
>>> bpy.data.objects[0].name
'Camera'
@@ -132,8 +119,7 @@ which can help in finding what settings to change in a script.
bpy.data.materials['MyMaterial']
For testing what data to access it's useful to use the "Console", which is its own space type.
This supports auto-complete, giving you a fast way to dig into different data in your file.
For testing what data to access it's useful to use the "Console", which is its own space type. This supports auto-complete, giving you a fast way to dig into different data in your file.
Example of a data path that can be quickly found via the console:
@@ -146,8 +132,7 @@ Example of a data path that can be quickly found via the console:
Data Creation/Removal
^^^^^^^^^^^^^^^^^^^^^
Those of you familiar with other Python API's may be surprised that
new datablocks in the bpy API can't be created by calling the class:
Those of you familiar with other Python API's may be surprised that new datablocks in the bpy API can't be created by calling the class:
>>> bpy.types.Mesh()
Traceback (most recent call last):
@@ -156,8 +141,7 @@ new datablocks in the bpy API can't be created by calling the class:
This is an intentional part of the API design.
The Blender/Python API can't create Blender data that exists outside the main Blender database
(accessed through :mod:`bpy.data`), because this data is managed by Blender (save/load/undo/append... etc).
The Blender/Python API can't create Blender data that exists outside the main Blender database (accessed through :mod:`bpy.data`), because this data is managed by Blender (save/load/undo/append... etc).
Data is added and removed via methods on the collections in :mod:`bpy.data`, eg:
@@ -171,10 +155,8 @@ Data is added and removed via methods on the collections in :mod:`bpy.data`, eg:
Custom Properties
^^^^^^^^^^^^^^^^^
Python can access properties on any datablock that has an ID
(data that can be linked in and accessed from :mod:`bpy.data`.
When assigning a property, you can make up your own names,
these will be created when needed or overwritten if they exist.
Python can access properties on any datablock that has an ID (data that can be linked in and accessed from :mod:`bpy.data`.
When assigning a property, you can make up your own names, these will be created when needed or overwritten if they exist.
This data is saved with the blend file and copied with objects.
@@ -210,10 +192,8 @@ These properties are valid outside of Python. They can be animated by curves or
Context
-------
While it's useful to be able to access data directly by name or as a list,
it's more common to operate on the user's selection.
The context is always available from ``bpy.context`` and can be used to get the active object, scene,
tool settings along with many other attributes.
While it's useful to be able to access data directly by name or as a list, it's more common to operate on the user's selection.
The context is always available from ``bpy.context`` and can be used to get the active object, scene, tool settings along with many other attributes.
Common-use cases:
@@ -221,9 +201,7 @@ Common-use cases:
>>> bpy.context.selected_objects
>>> bpy.context.visible_bones
Note that the context is read-only.
These values cannot be modified directly,
though they may be changed by running API functions or by using the data API.
Note that the context is read-only. These values cannot be modified directly, though they may be changed by running API functions or by using the data API.
So ``bpy.context.object = obj`` will raise an error.
@@ -231,8 +209,7 @@ But ``bpy.context.scene.objects.active = obj`` will work as expected.
The context attributes change depending on where they are accessed.
The 3D view has different context members than the console,
so take care when accessing context attributes that the user state is known.
The 3D view has different context members than the console, so take care when accessing context attributes that the user state is known.
See :mod:`bpy.context` API reference.
@@ -240,9 +217,7 @@ See :mod:`bpy.context` API reference.
Operators (Tools)
-----------------
Operators are tools generally accessed by the user from buttons, menu items or key shortcuts.
From the user perspective they are a tool but Python can run these with its own settings
through the :mod:`bpy.ops` module.
Operators are tools generally accessed by the user from buttons, menu items or key shortcuts. From the user perspective they are a tool but Python can run these with its own settings through the :mod:`bpy.ops` module.
Examples:
@@ -255,16 +230,14 @@ Examples:
.. note::
The menu item: :menuselection:`Help --> Operator Cheat Sheet`
gives a list of all operators and their default values in Python syntax, along with the generated docs.
The menu item: :menuselection:`Help --> Operator Cheat Sheet` gives a list of all operators and their default values in Python syntax, along with the generated docs.
This is a good way to get an overview of all Blender's operators.
Operator Poll()
^^^^^^^^^^^^^^^
Many operators have a "poll" function which may check that the cursor
is in a valid area or that the object is in the correct mode (Edit Mode, Weight Paint etc).
Many operators have a "poll" function which may check that the mouse is in a valid area or that the object is in the correct mode (Edit Mode, Weight Paint etc).
When an operator's poll function fails within Python, an exception is raised.
For example, calling ``bpy.ops.view3d.render_border()`` from the console raises the following error:
@@ -275,8 +248,7 @@ For example, calling ``bpy.ops.view3d.render_border()`` from the console raises
In this case the context must be the 3d view with an active camera.
To avoid using try/except clauses wherever operators are called you can call the operators
own ``poll()`` function to check if it can run in the current context.
To avoid using try/except clauses wherever operators are called you can call the operators own .poll() function to check if it can run in the current context.
.. code-block:: python
@@ -303,8 +275,7 @@ Example Operator
.. literalinclude:: ../../../release/scripts/templates_py/operator_simple.py
Once this script runs, ``SimpleOperator`` is registered with Blender
and can be called from the operator search popup or added to the toolbar.
Once this script runs, ``SimpleOperator`` is registered with Blender and can be called from the operator search popup or added to the toolbar.
To run the script:
@@ -314,23 +285,19 @@ To run the script:
#. Click the button labeled ``New`` and the confirmation pop up in order to create a new text block.
#. Press :kbd:`Ctrl-V` to paste the code into the text panel (the upper left frame).
#. Click on the button **Run Script**.
#. Move your cursor into the 3D view, press spacebar for the operator search menu, and type "Simple".
#. Move your mouse into the 3D view, press spacebar for the operator search menu, and type "Simple".
#. Click on the "Simple Operator" item found in search.
.. seealso:: The class members with the ``bl_`` prefix are documented in the API
reference :class:`bpy.types.Operator`
.. note::
The output from the ``main`` function is sent to the terminal;
in order to see this, be sure to :ref:`use the terminal <use_the_terminal>`.
.. note:: The output from the ``main`` function is sent to the terminal; in order to see this, be sure to :ref:`use the terminal <use_the_terminal>`.
Example Panel
-------------
Panels register themselves as a class, like an operator.
Notice the extra ``bl_`` variables used to set the context they display in.
Panels register themselves as a class, like an operator. Notice the extra ``bl_`` variables used to set the context they display in.
.. literalinclude:: ../../../release/scripts/templates_py/ui_panel_simple.py
@@ -367,8 +334,7 @@ Blender's Python API can be split up into 3 categories.
Native Types
------------
In simple cases returning a number or a string as a custom type would be cumbersome,
so these are accessed as normal Python types.
In simple cases returning a number or a string as a custom type would be cumbersome, so these are accessed as normal Python types.
- Blender float/int/boolean -> float/int/boolean
- Blender enumerator -> string
@@ -393,8 +359,7 @@ Used for Blender datablocks and collections: :class:`bpy.types.bpy_struct`
For data that contains its own attributes groups/meshes/bones/scenes... etc.
There are 2 main types that wrap Blenders data, one for datablocks
(known internally as ``bpy_struct``), another for properties.
There are 2 main types that wrap Blenders data, one for datablocks (known internally as ``bpy_struct``), another for properties.
>>> bpy.context.object
bpy.data.objects['Cube']
@@ -410,9 +375,7 @@ Mathutils Types
Used for vectors, quaternion, eulers, matrix and color types, accessible from :mod:`mathutils`
Some attributes such as :class:`bpy.types.Object.location`,
:class:`bpy.types.PoseBone.rotation_euler` and :class:`bpy.types.Scene.cursor_location`
can be accessed as special math types which can be used together and manipulated in various useful ways.
Some attributes such as :class:`bpy.types.Object.location`, :class:`bpy.types.PoseBone.rotation_euler` and :class:`bpy.types.Scene.cursor_location` can be accessed as special math types which can be used together and manipulated in various useful ways.
Example of a matrix, vector multiplication:
@@ -447,9 +410,7 @@ Animation
There are 2 ways to add keyframes through Python.
The first is through key properties directly, which is similar to inserting a keyframe from the button as a user.
You can also manually create the curves and keyframe data, then set the path to the property.
Here are examples of both methods.
The first is through key properties directly, which is similar to inserting a keyframe from the button as a user. You can also manually create the curves and keyframe data, then set the path to the property. Here are examples of both methods.
Both examples insert a keyframe on the active object's Z axis.

View File

@@ -1,12 +1,10 @@
***************
Tips and Tricks
***************
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.
Some of these are just python features that scripters may not have thought to use with blender, others are blender specific.
.. _use_the_terminal:
@@ -14,21 +12,18 @@ others are Blender specific.
Use The Terminal
================
When writing Python scripts, it's useful to have a terminal open,
this is not the built-in Python console but a terminal application which is used to start Blender.
When writing python scripts, it's 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:
- You can see the output of ``print()`` as your script runs, which is useful to view debug info.
- The error trace-back is printed in full to the terminal which won't always generate an error popup in
Blender's user interface (depending on how the script is executed).
- If the script runs for too long or you accidentally enter an infinite loop,
:kbd:`Ctrl-C` in the terminal (:kbd:`Ctrl-Break` on Windows) will quit the script early.
* You can see the output of ``print()`` as your script runs, which is useful to view debug info.
* The error trace-back is printed in full to the terminal which won't always generate an error popup in blender's 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.
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.
Interface Tricks
@@ -38,56 +33,43 @@ Interface Tricks
Access Operator Commands
------------------------
You may have noticed that the tooltip for menu items and buttons includes the ``bpy.ops.[...])`` command
to run that button, a handy (hidden) feature is that you can press :kbd:`Ctrl-C` over
any menu item/button to copy this command into the clipboard.
You may have noticed that the tooltip for menu items and buttons includes the ``bpy.ops``... command to run that button, a handy (hidden) feature is that you can press Ctrl+C over any menu item/button to copy this command into the clipboard.
Access Data Path
----------------
To find the path from an :class:`ID` datablock to its setting isn't always so simple since it may be nested away.
To get this quickly you can right click on the setting and select select **Copy Data Path**,
To find the path from an :class:`ID` datablock to its setting isn't always so simple since it may be nested away. To get this quickly you can right click on the setting and select select **Copy Data Path**,
if this can't be generated, only the property name is copied.
.. note::
This uses the same method for creating the animation path used by
:class:`bpy.types.FCurve.data_path` and
:class:`bpy.types.DriverTarget.data_path` drivers.
This uses the same method for creating the animation path used by :class:`bpy.types.FCurve.data_path` and :class:`bpy.types.DriverTarget.data_path` drivers.
.. _info_show_all_operators:
.. _info_show_all_operators
Show All Operators
==================
While Blender logs operators in the Info space,
this only reports operators with the ``REGISTER`` option enabeld so as not to flood the *Info* view
with calls to ``bpy.ops.view3d.smoothview`` and ``bpy.ops.view3d.zoom``.
While blender logs operators in the Info space, this only reports operators with the ``REGISTER`` option enabeld so as not to flood the Info view with calls to ``bpy.ops.view3d.smoothview`` and ``bpy.ops.view3d.zoom``.
However, for testing it can be useful to see **every** operator called in a terminal,
do this by enabling the debug option either by passing the ``--debug-wm`` argument when starting Blender
or by setting :mod:`bpy.app.debug_wm` to ``True`` while Blender is running.
However, for testing it can be useful to see **every** operator called in a terminal, do this by enabling the debug option either by passing the ``--debug-wm`` argument when starting blender or by setting :mod:`bpy.app.debug_wm` to True while blender is running.
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.
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 than including it directly.
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 text-block.
This is the equivalent to running the script directly, referencing a scripts path from a 2 line textblock.
.. code-block:: python
@@ -114,23 +96,18 @@ This example shows loading a script in as a module and executing a module functi
.. code-block:: python
import myscript
import importlib
import imp
importlib.reload(myscript)
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.
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 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.
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
@@ -143,94 +120,79 @@ this example adds the current blend files directory to the search path, then loa
sys.path.append(blend_dir)
import myscript
import importlib
importlib.reload(myscript)
import imp
imp.reload(myscript)
myscript.main()
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.
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.
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:: sh
.. 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:: sh
.. code-block:: python
blender myscene.blend --background --python myscript.py
.. note::
Depending on your setup you might have to enter the full path to the Blender executable.
Depending on your 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.
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.
* 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.
While this can take a little time to setup, it can be well worth the effort
to reduce the time it takes to test changes - you can even have
Blender running the script every few seconds with a viewer updating the results,
so no need to leave your text editor to see changes.
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 your text editor to see changes.
Use External Tools
==================
When there are no readily available Python modules to perform specific tasks it's
worth keeping in mind you may be able to have Python execute an external command
on your data and read the result back in.
When there are no readily available python modules to perform specific tasks it's worth keeping in mind you may be able to have python execute an external command on your 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 your own custom pipeline or writing one-off scripts this can be handy.
Using external programs adds an extra dependency and may limit who can use the script but to quickly setup your 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.
* 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
===========================
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 your 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 your systems python wont be found by blender.
There are 2 ways around this:
- remove Blender Python sub-directory, Blender will then fallback on the systems Python and use that instead
.. warning::
* 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**.
The 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.
* 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 Your 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.
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
@@ -255,13 +217,10 @@ The next example is an equivalent single line version of the script above which
__import__('code').interact(local=dict(globals(), **locals()))
``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.
``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.
If you have **IPython** installed you can use its ``embed()`` function which uses the current namespace.
The IPython prompt has auto-complete and some useful features that the standard Python eval-loop doesn't have.
If you have **IPython** installed you can use their ``embed()`` function which will implicitly use the current namespace, this has autocomplete and some useful features that the standard python eval-loop doesn't have.
.. code-block:: python
@@ -269,7 +228,7 @@ The IPython prompt has auto-complete and some useful features that the standard
IPython.embed()
Admittedly this highlights the lack of any Python debugging support built into Blender, but its still handy to know.
Admittedly this highlights the lack of any python debugging support built into blender, but its still handy to know.
.. note::
@@ -283,32 +242,27 @@ Advanced
Blender as a module
-------------------
From a Python perspective it's nicer to have everything as an extension
which lets the Python script combine many components.
From a python perspective it's 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.
* 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.
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>`_
For instructions on building see `Building blender as a python module <http://wiki.blender.org/index.php/User:Ideasman42/BlenderAsPyModule>`_
Python Safety (Build Option)
----------------------------
Since it's possible to access data which has been removed (see Gotcha's),
this can be hard to track down the cause of crashes.
Since it's possible to access data which has been removed (see Gotcha's), this can be hard to track down the cause of crashes.
To raise Python exceptions on accessing freed data (rather than 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 isn't enabled in release builds.
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.

View File

@@ -208,7 +208,6 @@ The objects should move as before.
*Keep this addon open in Blender for the next step - Installing.*
Install The Addon
-----------------
@@ -222,11 +221,10 @@ restrictions that apply to Python modules and end with a ``.py`` extension.
Once the file is on disk, you can install it as you would for an addon downloaded online.
Open the user :menuselection:`File -> User Preferences`,
Select the *Addon* section, press *Install Addon...* and select the file.
Open the user **File -> User Preferences**, Select the **Addon** section, press **Install Addon...** and select the file.
Now the addon will be listed and you can enable it by pressing the check-box,
if you want it to be enabled on restart, press *Save as Default*.
Now the addon will be listed and you can enable it by pressing the check-box, if you want it to be enabled on restart,
press **Save as Default**.
.. note::
@@ -240,7 +238,7 @@ if you want it to be enabled on restart, press *Save as Default*.
print(addon_utils.paths())
More is written on this topic here:
`Directory Layout <https://www.blender.org/manual/getting_started/installing_blender/directorylayout.html>`_
`Directory Layout <http://wiki.blender.org/index.php/Doc:2.6/Manual/Introduction/Installing_Blender/DirectoryLayout>`_
Your Second Addon

View File

@@ -163,9 +163,6 @@ def main():
for i, l in enumerate(b):
l = l.strip()
# casts
l = l.replace("(int)", "")
l = l.replace("{", "(")
l = l.replace("}", ")")

View File

@@ -234,7 +234,6 @@ else:
EXCLUDE_MODULES = [
"aud",
"bge",
"bge.app"
"bge.constraints",
"bge.events",
"bge.logic",
@@ -258,13 +257,10 @@ else:
"bpy.props",
"bpy.types", # supports filtering
"bpy.utils",
"bpy.utils.previews",
"bpy_extras",
"gpu",
"gpu.offscreen",
"mathutils",
"mathutils.geometry",
"mathutils.bvhtree",
"mathutils.kdtree",
"mathutils.noise",
"freestyle",
@@ -458,11 +454,9 @@ ClassMethodDescriptorType = type(dict.__dict__['fromkeys'])
MethodDescriptorType = type(dict.get)
GetSetDescriptorType = type(int.real)
StaticMethodType = type(staticmethod(lambda: None))
from types import (
MemberDescriptorType,
MethodType,
FunctionType,
)
from types import (MemberDescriptorType,
MethodType,
)
_BPY_STRUCT_FAKE = "bpy_struct"
_BPY_PROP_COLLECTION_FAKE = "bpy_prop_collection"
@@ -473,18 +467,6 @@ else:
_BPY_PROP_COLLECTION_ID = "collection"
def escape_rst(text):
""" Escape plain text which may contain characters used by RST.
"""
return text.translate(escape_rst.trans)
escape_rst.trans = str.maketrans({
"`": "\\`",
"|": "\\|",
"*": "\\*",
"\\": "\\\\",
})
def is_struct_seq(value):
return isinstance(value, tuple) and type(tuple) != tuple and hasattr(value, "n_fields")
@@ -645,32 +627,25 @@ def pyfunc2sphinx(ident, fw, module_name, type_name, identifier, py_func, is_cla
if type(py_func) == MethodType:
return
arg_str = inspect.formatargspec(*inspect.getfullargspec(py_func))
arg_str = inspect.formatargspec(*inspect.getargspec(py_func))
if not is_class:
func_type = "function"
# ther rest are class methods
elif arg_str.startswith("(self, ") or arg_str == "(self)":
arg_str = "()" if (arg_str == "(self)") else ("(" + arg_str[7:])
elif arg_str.startswith("(self, "):
arg_str = "(" + arg_str[7:]
func_type = "method"
elif arg_str.startswith("(cls, "):
arg_str = "()" if (arg_str == "(cls)") else ("(" + arg_str[6:])
arg_str = "(" + arg_str[6:]
func_type = "classmethod"
else:
func_type = "staticmethod"
doc = py_func.__doc__
if (not doc) or (not doc.startswith(".. %s:: " % func_type)):
fw(ident + ".. %s:: %s%s\n\n" % (func_type, identifier, arg_str))
ident_temp = ident + " "
else:
ident_temp = ident
if doc:
write_indented_lines(ident_temp, fw, doc)
fw(ident + ".. %s:: %s%s\n\n" % (func_type, identifier, arg_str))
if py_func.__doc__:
write_indented_lines(ident + " ", fw, py_func.__doc__)
fw("\n")
del doc, ident_temp
if is_class:
write_example_ref(ident + " ", fw, module_name + "." + type_name + "." + identifier)
@@ -886,7 +861,7 @@ def pymodule2sphinx(basepath, module_name, module, title):
module_dir_value_type.sort(key=lambda triple: str(triple[2]))
for attribute, value, value_type in module_dir_value_type:
if value_type == FunctionType:
if value_type == types.FunctionType:
pyfunc2sphinx("", fw, module_name, None, attribute, value, is_class=False)
elif value_type in {types.BuiltinMethodType, types.BuiltinFunctionType}: # both the same at the moment but to be future proof
# note: can't get args from these, so dump the string as is
@@ -941,24 +916,19 @@ def pymodule2sphinx(basepath, module_name, module, title):
fw(value.__doc__)
else:
fw(".. class:: %s\n\n" % type_name)
write_indented_lines(" ", fw, value.__doc__, True)
write_indented_lines(" ", fw, value.__doc__, False)
else:
fw(".. class:: %s\n\n" % type_name)
fw("\n")
write_example_ref(" ", fw, module_name + "." + type_name)
descr_items = [(key, descr) for key, descr in sorted(value.__dict__.items()) if not key.startswith("_")]
descr_items = [(key, descr) for key, descr in sorted(value.__dict__.items()) if not key.startswith("__")]
for key, descr in descr_items:
if type(descr) == ClassMethodDescriptorType:
py_descr2sphinx(" ", fw, descr, module_name, type_name, key)
# needed for pure python classes
for key, descr in descr_items:
if type(descr) == FunctionType:
pyfunc2sphinx(" ", fw, module_name, type_name, key, descr, is_class=True)
for key, descr in descr_items:
if type(descr) == MethodDescriptorType:
py_descr2sphinx(" ", fw, descr, module_name, type_name, key)
@@ -1152,7 +1122,7 @@ def pycontext2sphinx(basepath):
def pyrna_enum2sphinx(prop, use_empty_descriptions=False):
""" write a bullet point list of enum + descriptions
""" write a bullet point list of enum + descrptons
"""
if use_empty_descriptions:
@@ -1167,7 +1137,7 @@ def pyrna_enum2sphinx(prop, use_empty_descriptions=False):
if ok:
return "".join(["* ``%s`` %s.\n" %
(identifier,
", ".join(escape_rst(val) for val in (name, description) if val),
", ".join(val for val in (name, description) if val),
)
for identifier, name, description in prop.enum_items
])
@@ -1269,7 +1239,6 @@ def pyrna2sphinx(basepath):
fw("\n\n")
subclass_ids = [s.identifier for s in structs.values() if s.base is struct if not rna_info.rna_id_ignore(s.identifier)]
subclass_ids.sort()
if subclass_ids:
fw("subclasses --- \n" + ", ".join((":class:`%s`" % s) for s in subclass_ids) + "\n\n")
@@ -1613,7 +1582,7 @@ def write_rst_contents(basepath):
fw("\n")
# fw("`A PDF version of this document is also available <%s>`_\n" % BLENDER_PDF_FILENAME)
fw("This site can be downloaded for offline use `Download the full Documentation (zipped HTML files) <%s>`_\n" % BLENDER_ZIP_FILENAME)
fw("`A compressed ZIP file of this site is available <%s>`_\n" % BLENDER_ZIP_FILENAME)
fw("\n")
@@ -1638,7 +1607,6 @@ def write_rst_contents(basepath):
# py modules
"bpy.utils",
"bpy.utils.previews",
"bpy.path",
"bpy.app",
"bpy.app.handlers",
@@ -1658,11 +1626,9 @@ def write_rst_contents(basepath):
standalone_modules = (
# mathutils
"mathutils", "mathutils.geometry", "mathutils.bvhtree", "mathutils.kdtree", "mathutils.noise",
"mathutils", "mathutils.geometry", "mathutils.kdtree", "mathutils.noise",
# misc
"freestyle", "bgl", "blf",
"gpu", "gpu.offscreen",
"aud", "bpy_extras",
"freestyle", "bgl", "blf", "gpu", "aud", "bpy_extras",
# bmesh, submodules are in own page
"bmesh",
)
@@ -1686,7 +1652,6 @@ def write_rst_contents(basepath):
fw(" bge.texture.rst\n\n")
fw(" bge.events.rst\n\n")
fw(" bge.constraints.rst\n\n")
fw(" bge.app.rst\n\n")
# rna generated change log
fw(title_string("API Info", "=", double=True))
@@ -1802,7 +1767,6 @@ def write_rst_importable_modules(basepath):
# C_modules
"aud" : "Audio System",
"blf" : "Font Drawing",
"gpu.offscreen" : "GPU Off-Screen Buffer",
"bmesh" : "BMesh Module",
"bmesh.types" : "BMesh Types",
"bmesh.utils" : "BMesh Utilities",
@@ -1813,7 +1777,6 @@ def write_rst_importable_modules(basepath):
"bpy.props" : "Property Definitions",
"mathutils" : "Math Types & Utilities",
"mathutils.geometry" : "Geometry Utilities",
"mathutils.bvhtree" : "BVHTree Utilities",
"mathutils.kdtree" : "KDTree Utilities",
"mathutils.noise" : "Noise Utilities",
"freestyle" : "Freestyle Module",
@@ -1845,7 +1808,6 @@ def copy_handwritten_rsts(basepath):
"bge.texture",
"bge.events",
"bge.constraints",
"bge.app",
"bgl", # "Blender OpenGl wrapper"
"gpu", # "GPU Shader Module"

View File

@@ -18,10 +18,8 @@ DO_OUT_HTML=true
DO_OUT_HTML_ZIP=true
DO_OUT_PDF=false
if [ -z $BLENDER_BIN ] ; then
BLENDER_BIN="./blender.bin"
fi
BLENDER="./blender.bin"
SSH_USER=$1
SSH_HOST=$SSH_USER"@blender.org"
SSH_UPLOAD="/data/www/vhosts/www.blender.org/api" # blender_python_api_VERSION, added after
@@ -54,7 +52,7 @@ SPHINXBASE=doc/python_api
if $DO_EXE_BLENDER ; then
# dont delete existing docs, now partial updates are used for quick builds.
$BLENDER_BIN --background -noaudio --factory-startup --python $SPHINXBASE/sphinx_doc_gen.py
$BLENDER --background -noaudio --factory-startup --python $SPHINXBASE/sphinx_doc_gen.py
fi

View File

@@ -29,7 +29,6 @@ remove_strict_flags()
add_subdirectory(rangetree)
add_subdirectory(wcwidth)
add_subdirectory(libmv)
add_subdirectory(Eigen3)
if(WITH_OPENNL)
add_subdirectory(colamd)
@@ -78,7 +77,7 @@ if(WITH_LZMA)
add_subdirectory(lzma)
endif()
if(WITH_CYCLES OR WITH_COMPOSITOR OR WITH_OPENSUBDIV)
if(WITH_CYCLES OR WITH_COMPOSITOR)
add_subdirectory(clew)
add_subdirectory(cuew)
endif()

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