This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/blenloader/intern/writefile.c

4658 lines
143 KiB
C
Raw Normal View History

/*
2002-10-12 11:37:38 +00:00
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
2002-10-12 11:37:38 +00:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2002-10-12 11:37:38 +00:00
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*/
/** \file
* \ingroup blenloader
2011-02-27 20:35:41 +00:00
*/
/**
*
* FILE FORMAT
* ===========
*
2019-10-15 12:02:40 +11:00
* IFF-style structure (but not IFF compatible!)
2012-10-04 13:26:15 +00:00
*
2019-10-15 12:02:40 +11:00
* Start file:
* <pre>
2019-10-15 12:02:40 +11:00
* `BLENDER_V100` `12` bytes (version 1.00 is just an example).
* `V` = big endian, `v` = little endian.
* `_` = 4 byte pointer, `-` = 8 byte pointer.
* </pre>
2012-10-04 13:26:15 +00:00
*
2019-06-12 09:04:10 +10:00
* data-blocks: (also see struct #BHead).
* <pre>
2019-10-15 12:02:40 +11:00
* `bh.code` `char[4]` see `BLO_blend_defs.h` for a list of known types.
* `bh.len` `int32` length data after #BHead in bytes.
* `bh.old` `void *` old pointer (the address at the time of writing the file).
* `bh.SDNAnr` `int32` struct index of structs stored in #DNA1 data.
* `bh.nr` `int32` in case of array: number of structs.
* data
* ...
* ...
* </pre>
2012-10-04 13:26:15 +00:00
*
* Almost all data in Blender are structures. Each struct saved
* gets a BHead header. With BHead the struct can be linked again
2019-10-15 12:02:40 +11:00
* and compared with #StructDNA.
2012-10-04 13:26:15 +00:00
* WRITE
* =====
2012-10-04 13:26:15 +00:00
*
* Preferred writing order: (not really a must, but why would you do it random?)
2019-10-15 12:02:40 +11:00
* Any case: direct data is ALWAYS after the lib block.
2012-10-04 13:26:15 +00:00
*
* (Local file data)
* - for each LibBlock
* - write LibBlock
* - write associated direct data
2012-10-04 13:26:15 +00:00
* (External file data)
* - per library
* - write library block
* - per LibBlock
* - write the ID of LibBlock
* - write #TEST (#RenderInfo struct. 128x128 blend file preview is optional).
* - write #GLOB (#FileGlobal struct) (some global vars).
* - write #DNA1 (#SDNA struct)
* - write #USER (#UserDef struct) if filename is ``~/.config/blender/X.XX/config/startup.blend``.
2012-10-04 13:26:15 +00:00
*/
#include <fcntl.h>
Merge of the PyNodes branch (aka "custom nodes") into trunk. PyNodes opens up the node system in Blender to scripters and adds a number of UI-level improvements. === Dynamic node type registration === Node types can now be added at runtime, using the RNA registration mechanism from python. This enables addons such as render engines to create a complete user interface with nodes. Examples of how such nodes can be defined can be found in my personal wiki docs atm [1] and as a script template in release/scripts/templates_py/custom_nodes.py [2]. === Node group improvements === Each node editor now has a tree history of edited node groups, which allows opening and editing nested node groups. The node editor also supports pinning now, so that different spaces can be used to edit different node groups simultaneously. For more ramblings and rationale see (really old) blog post on code.blender.org [3]. The interface of node groups has been overhauled. Sockets of a node group are no longer displayed in columns on either side, but instead special input/output nodes are used to mirror group sockets inside a node tree. This solves the problem of long node lines in groups and allows more adaptable node layout. Internal sockets can be exposed from a group by either connecting to the extension sockets in input/output nodes (shown as empty circle) or by adding sockets from the node property bar in the "Interface" panel. Further details such as the socket name can also be changed there. [1] http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes [2] http://projects.blender.org/scm/viewvc.php/trunk/blender/release/scripts/templates_py/custom_nodes.py?view=markup&root=bf-blender [3] http://code.blender.org/index.php/2012/01/improving-node-group-interface-editing/
2013-03-18 16:34:57 +00:00
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
# include "BLI_winstuff.h"
# include "winsock2.h"
# include <io.h>
# include <zlib.h> /* odd include order-issue */
#else
# include <unistd.h> /* FreeBSD, for write() and close(). */
2002-10-12 11:37:38 +00:00
#endif
#include "BLI_utildefines.h"
/* allow writefile to use deprecated functionality (for forward compatibility code) */
#define DNA_DEPRECATED_ALLOW
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
#include "DNA_brush_types.h"
#include "DNA_cachefile_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_camera_types.h"
#include "DNA_cloth_types.h"
#include "DNA_collection_types.h"
Added custom vertex/edge/face data for meshes: All data layers, including MVert/MEdge/MFace, are now managed as custom data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are still used of course, but allocating, copying or freeing these arrays should be done through the CustomData API. Work in progress documentation on this is here: http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData Replaced TFace by MTFace: This is the same struct, except that it does not contain color, that now always stays separated in MCol. This was not a good design decision to begin with, and it is needed for adding multiple color layers later. Note that this does mean older Blender versions will not be able to read UV coordinates from the next release, due to an SDNA limitation. Removed DispListMesh: This now fully replaced by DerivedMesh. To provide access to arrays of vertices, edges and faces, like DispListMesh does. The semantics of the DerivedMesh.getVertArray() and similar functions were changed to return a pointer to an array if one exists, or otherwise allocate a temporary one. On releasing the DerivedMesh, this temporary array will be removed automatically. Removed ssDM and meshDM DerivedMesh backends: The ssDM backend was for DispListMesh, so that became obsolete automatically. The meshDM backend was replaced by the custom data backend, that now figures out which layers need to be modified, and only duplicates those. This changes code in many places, and overall removes 2514 lines of code. So, there's a good chance this might break some stuff, although I've been testing it for a few days now. The good news is, adding multiple color and uv layers should now become easy.
2006-11-20 04:28:02 +00:00
#include "DNA_constraint_types.h"
#include "DNA_curveprofile_types.h"
#include "DNA_dynamicpaint_types.h"
#include "DNA_fileglobal_types.h"
#include "DNA_fluid_types.h"
#include "DNA_genfile.h"
#include "DNA_gpencil_modifier_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_hair_types.h"
#include "DNA_key_types.h"
#include "DNA_lattice_types.h"
Render Layers and Collections (merge from render-layers) Design Documents ---------------- * https://wiki.blender.org/index.php/Dev:2.8/Source/Layers * https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised User Commit Log --------------- * New Layer and Collection system to replace render layers and viewport layers. * A layer is a set of collections of objects (and their drawing options) required for specific tasks. * A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers. * All Scenes have a master collection that all other collections are children of. * New collection "context" tab (in Properties Editor) * New temporary viewport "collections" panel to control per-collection visibility Missing User Features --------------------- * Collection "Filter" Option to add objects based on their names * Collection Manager operators The existing buttons are placeholders * Collection Manager drawing The editor main region is empty * Collection Override * Per-Collection engine settings This will come as a separate commit, as part of the clay-engine branch Dev Commit Log -------------- * New DNA file (DNA_layer_types.h) with the new structs We are replacing Base by a new extended Base while keeping it backward compatible with some legacy settings (i.e., lay, flag_legacy). Renamed all Base to BaseLegacy to make it clear the areas of code that still need to be converted Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp * Unittesting for main syncronization requirements - read, write, add/copy/remove objects, copy scene, collection link/unlinking, context) * New Editor: Collection Manager Based on patch by Julian Eisel This is extracted from the layer-manager branch. With the following changes: - Renamed references of layer manager to collections manager - I doesn't include the editors/space_collections/ draw and util files - The drawing code itself will be implemented separately by Julian * Base / Object: A little note about them. Original Blender code would try to keep them in sync through the code, juggling flags back and forth. This will now be handled by Depsgraph, keeping Object and Bases more separated throughout the non-rendering code. Scene.base is being cleared in doversion, and the old viewport drawing code was poorly converted to use the new bases while the new viewport code doesn't get merged and replace the old one. Python API Changes ------------------ ``` - scene.layers + # no longer exists - scene.objects + scene.scene_layers.active.objects - scene.objects.active + scene.render_layers.active.objects.active - bpy.context.scene.objects.link() + bpy.context.scene_collection.objects.link() - bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None) + bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None) - bpy.context.object.select + bpy.context.object.select = True + bpy.context.object.select = False + bpy.context.object.select_get() + bpy.context.object.select_set(action='SELECT') + bpy.context.object.select_set(action='DESELECT') -AddObjectHelper.layers + # no longer exists ```
2017-02-07 10:18:38 +01:00
#include "DNA_layer_types.h"
#include "DNA_light_types.h"
#include "DNA_lightprobe_types.h"
#include "DNA_linestyle_types.h"
#include "DNA_mask_types.h"
#include "DNA_material_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_meta_types.h"
#include "DNA_movieclip_types.h"
Christmas coding work! ********* Node editor work: - To enable Nodes for Materials, you have to set the "Use Nodes" button, in the new Material buttons "Nodes" Panel or in header of the Node editor. Doing this will disable Material-Layers. - Nodes now execute materials ("shaders"), but still only using the previewrender code. - Nodes have (optional) previews for rendered images. - Node headers allow to hide buttons and/or preview image - Nodes can be dragged larger/smaller (right-bottom corner) - Nodes can be hidden (minimized) with hotkey H - CTRL+click on an Input Socket gives a popup with default values. - Changing Material/Texture or Mix node will adjust Node title. - Click-drag outside of a Node changes cursor to "Knife' and allows to draw a rect where to cut Links. - Added new node types RGBtoBW, Texture, In/Output, ColorRamp - Material Nodes have options to ouput diffuse or specular, or to use a negative normal. The input socket 'Normal' will force the material to use that normal, otherwise it uses the normal from the Material that has the node tree. - When drawing a link between two not-matching sockets, Blender inserts a converting node (now only for value/rgb combos) - When drawing a link to an input socket that's already in use, the old link will either disappear or flip to another unused socket. - A click on a Material Node will activate it, and show all its settings in the Material Buttons. Active Material Nodes draw the material icon in red. - A click on any node will show its options in the Node Panel in the Material buttons. - Multiple Output Nodes can be used, to sample contents of a tree, but only one Output is the real one, which is indicated in a different color and red material icon. - Added ThemeColors for node types - ALT+C will convert existing Material-Layers to Node... this currently only adds the material/mix nodes and connects them. Dunno if this is worth a lot of coding work to make perfect? - Press C to call another "Solve order", which will show all possible cyclic conflicts (if there are). - Technical: nodes now use "Type" structs which define the structure of nodes and in/output sockets. The Type structs store all fixed info, callbacks, and allow to reconstruct saved Nodes to match what is required by Blender. - Defining (new) nodes now is as simple as filling in a fixed Type struct, plus code some callbacks. A doc will be made! - Node preview images are by default float ********* Icon drawing: - Cleanup of how old icons were implemented in new system, making them 16x16 too, correctly centered *and* scaled. - Made drawing Icons use float coordinates - Moved BIF_calcpreview_image() into interface_icons.c, renamed it icon_from_image(). Removed a lot of unneeded Imbuf magic here! :) - Skipped scaling and imbuf copying when icons are OK size ********* Preview render: - Huge cleanup of code.... - renaming BIF_xxx calls that only were used internally - BIF_previewrender() now accepts an argument for rendering method, so it supports icons, buttonwindow previewrender and node editor - Only a single BIF_preview_changed() call now exists, supporting all signals as needed for buttos and node editor ********* More stuff: - glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format argument for GL_FLOAT rects - Made the ColorBand become a built-in button for interface.c Was a load of cleanup work in buttons_shading.c... - removed a load of unneeded glBlendFunc() calls - Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
#include "DNA_node_types.h"
#include "DNA_object_force_types.h"
#include "DNA_object_types.h"
#include "DNA_packedFile_types.h"
#include "DNA_particle_types.h"
#include "DNA_pointcache_types.h"
#include "DNA_pointcloud_types.h"
#include "DNA_rigidbody_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_sdna_types.h"
#include "DNA_sequence_types.h"
#include "DNA_shader_fx_types.h"
#include "DNA_simulation_types.h"
#include "DNA_sound_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_space_types.h"
#include "DNA_speaker_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_text_types.h"
#include "DNA_vfont_types.h"
#include "DNA_view3d_types.h"
#include "DNA_volume_types.h"
#include "DNA_windowmanager_types.h"
Main Workspace Integration This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup) Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know! (Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.) == Main Changes/Features * Introduces the new Workspaces as data-blocks. * Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces. * Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces). * Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead. * Store screen-layouts (`bScreen`) per workspace. * Store an active screen-layout per workspace. Changing the workspace will enable this layout. * Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.) * Store an active render layer per workspace. * Moved mode switch from 3D View header to Info Editor header. * Store active scene in window (not directly workspace related, but overlaps quite a bit). * Removed 'Use Global Scene' User Preference option. * Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well. * Default .blend only contains one workspace ("General"). * Support appending workspaces. Opening files without UI and commandline rendering should work fine. Note that the UI is temporary! We plan to introduce a new global topbar that contains the workspace options and tabs for switching workspaces. == Technical Notes * Workspaces are data-blocks. * Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now. * A workspace can be active in multiple windows at the same time. * The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned). * The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that). * Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs. * `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those. * Added scene operators `SCENE_OT_`. Was previously done through screen operators. == BPY API Changes * Removed `Screen.scene`, added `Window.scene` * Removed `UserPreferencesView.use_global_scene` * Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces` * Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer` * Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name) == What's left? * There are a few open design questions (T50521). We should find the needed answers and implement them. * Allow adding and removing individual workspaces from workspace configuration (needs UI design). * Get the override system ready and support overrides per workspace. * Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc). * Allow enabling add-ons per workspace. * Support custom workspace keymaps. * Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later. * Get the topbar done. * Workspaces need a proper icon, current one is just a placeholder :) Reviewed By: campbellbarton, mont29 Tags: #user_interface, #bf_blender_2.8 Maniphest Tasks: T50521 Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
#include "DNA_workspace_types.h"
#include "DNA_world_types.h"
2002-10-12 11:37:38 +00:00
#include "BLI_bitmap.h"
2002-10-12 11:37:38 +00:00
#include "BLI_blenlib.h"
#include "BLI_mempool.h"
#include "MEM_guardedalloc.h" // MEM_freeN
2002-10-12 11:37:38 +00:00
#include "BKE_action.h"
#include "BKE_blender_version.h"
#include "BKE_bpath.h"
Collections and groups unification OVERVIEW * In 2.7 terminology, all layers and groups are now collection datablocks. * These collections are nestable, linkable, instanceable, overrideable, .. which opens up new ways to set up scenes and link + override data. * Viewport/render visibility and selectability are now a part of the collection and shared across all view layers and linkable. * View layers define which subset of the scene collection hierarchy is excluded for each. For many workflows one view layer can be used, these are more of an advanced feature now. OUTLINER * The outliner now has a "View Layer" display mode instead of "Collections", which can display the collections and/or objects in the view layer. * In this display mode, collections can be excluded with the right click menu. These will then be greyed out and their objects will be excluded. * To view collections not linked to any scene, the "Blender File" display mode can be used, with the new filtering option to just see Colleciton datablocks. * The outliner right click menus for collections and objects were reorganized. * Drag and drop still needs to be improved. Like before, dragging the icon or text gives different results, we'll unify this later. LINKING AND OVERRIDES * Collections can now be linked into the scene without creating an instance, with the link/append operator or from the collections view in the outliner. * Collections can get static overrides with the right click menu in the outliner, but this is rather unreliable and not clearly communicated at the moment. * We still need to improve the make override operator to turn collection instances into collections with overrides directly in the scene. PERFORMANCE * We tried to make performance not worse than before and improve it in some cases. The main thing that's still a bit slower is multiple scenes, we have to change the layer syncing to only updated affected scenes. * Collections keep a list of their parent collections for faster incremental updates in syncing and caching. * View layer bases are now in a object -> base hash to avoid quadratic time lookups internally and in API functions like visible_get(). VERSIONING * Compatibility with 2.7 files should be improved due to the new visibility controls. Of course users may not want to set up their scenes differently now to avoid having separate layers and groups. * Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero files. There's a few things which are know to be not quite compatible, like nested layer collections inside groups. * The versioning code for 2.8 files is quite complicated, and isolated behind #ifdef so it can be removed at the end of the release cycle. KNOWN ISSUES * The G-key group operators in the 3D viewport were left mostly as is, they need to be modified still to fit better. * Same for the groups panel in the object properties. This needs to be updated still, or perhaps replaced by something better. * Collections must all have a unique name. Less restrictive namespacing is to be done later, we'll have to see how important this is as all objects within the collections must also have a unique name anyway. * Full scene copy and delete scene are exactly doing the right thing yet. Differential Revision: https://developer.blender.org/D3383 https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
#include "BKE_collection.h"
2002-10-12 11:37:38 +00:00
#include "BKE_constraint.h"
#include "BKE_curve.h"
#include "BKE_fcurve.h"
#include "BKE_fcurve_driver.h"
#include "BKE_global.h" // for G
#include "BKE_gpencil_modifier.h"
#include "BKE_idtype.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_lib_override.h"
#include "BKE_main.h"
#include "BKE_modifier.h"
Christmas coding work! ********* Node editor work: - To enable Nodes for Materials, you have to set the "Use Nodes" button, in the new Material buttons "Nodes" Panel or in header of the Node editor. Doing this will disable Material-Layers. - Nodes now execute materials ("shaders"), but still only using the previewrender code. - Nodes have (optional) previews for rendered images. - Node headers allow to hide buttons and/or preview image - Nodes can be dragged larger/smaller (right-bottom corner) - Nodes can be hidden (minimized) with hotkey H - CTRL+click on an Input Socket gives a popup with default values. - Changing Material/Texture or Mix node will adjust Node title. - Click-drag outside of a Node changes cursor to "Knife' and allows to draw a rect where to cut Links. - Added new node types RGBtoBW, Texture, In/Output, ColorRamp - Material Nodes have options to ouput diffuse or specular, or to use a negative normal. The input socket 'Normal' will force the material to use that normal, otherwise it uses the normal from the Material that has the node tree. - When drawing a link between two not-matching sockets, Blender inserts a converting node (now only for value/rgb combos) - When drawing a link to an input socket that's already in use, the old link will either disappear or flip to another unused socket. - A click on a Material Node will activate it, and show all its settings in the Material Buttons. Active Material Nodes draw the material icon in red. - A click on any node will show its options in the Node Panel in the Material buttons. - Multiple Output Nodes can be used, to sample contents of a tree, but only one Output is the real one, which is indicated in a different color and red material icon. - Added ThemeColors for node types - ALT+C will convert existing Material-Layers to Node... this currently only adds the material/mix nodes and connects them. Dunno if this is worth a lot of coding work to make perfect? - Press C to call another "Solve order", which will show all possible cyclic conflicts (if there are). - Technical: nodes now use "Type" structs which define the structure of nodes and in/output sockets. The Type structs store all fixed info, callbacks, and allow to reconstruct saved Nodes to match what is required by Blender. - Defining (new) nodes now is as simple as filling in a fixed Type struct, plus code some callbacks. A doc will be made! - Node preview images are by default float ********* Icon drawing: - Cleanup of how old icons were implemented in new system, making them 16x16 too, correctly centered *and* scaled. - Made drawing Icons use float coordinates - Moved BIF_calcpreview_image() into interface_icons.c, renamed it icon_from_image(). Removed a lot of unneeded Imbuf magic here! :) - Skipped scaling and imbuf copying when icons are OK size ********* Preview render: - Huge cleanup of code.... - renaming BIF_xxx calls that only were used internally - BIF_previewrender() now accepts an argument for rendering method, so it supports icons, buttonwindow previewrender and node editor - Only a single BIF_preview_changed() call now exists, supporting all signals as needed for buttos and node editor ********* More stuff: - glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format argument for GL_FLOAT rects - Made the ColorBand become a built-in button for interface.c Was a load of cleanup work in buttons_shading.c... - removed a load of unneeded glBlendFunc() calls - Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
#include "BKE_node.h"
#include "BKE_object.h"
#include "BKE_pointcache.h"
#include "BKE_report.h"
#include "BKE_sequencer.h"
#include "BKE_shader_fx.h"
#include "BKE_subsurf.h"
Main Workspace Integration This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup) Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know! (Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.) == Main Changes/Features * Introduces the new Workspaces as data-blocks. * Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces. * Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces). * Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead. * Store screen-layouts (`bScreen`) per workspace. * Store an active screen-layout per workspace. Changing the workspace will enable this layout. * Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.) * Store an active render layer per workspace. * Moved mode switch from 3D View header to Info Editor header. * Store active scene in window (not directly workspace related, but overlaps quite a bit). * Removed 'Use Global Scene' User Preference option. * Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well. * Default .blend only contains one workspace ("General"). * Support appending workspaces. Opening files without UI and commandline rendering should work fine. Note that the UI is temporary! We plan to introduce a new global topbar that contains the workspace options and tabs for switching workspaces. == Technical Notes * Workspaces are data-blocks. * Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now. * A workspace can be active in multiple windows at the same time. * The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned). * The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that). * Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs. * `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those. * Added scene operators `SCENE_OT_`. Was previously done through screen operators. == BPY API Changes * Removed `Screen.scene`, added `Window.scene` * Removed `UserPreferencesView.use_global_scene` * Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces` * Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer` * Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name) == What's left? * There are a few open design questions (T50521). We should find the needed answers and implement them. * Allow adding and removing individual workspaces from workspace configuration (needs UI design). * Get the override system ready and support overrides per workspace. * Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc). * Allow enabling add-ons per workspace. * Support custom workspace keymaps. * Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later. * Get the topbar done. * Workspaces need a proper icon, current one is just a placeholder :) Reviewed By: campbellbarton, mont29 Tags: #user_interface, #bf_blender_2.8 Maniphest Tasks: T50521 Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
#include "BKE_workspace.h"
2002-10-12 11:37:38 +00:00
#include "BLO_blend_defs.h"
#include "BLO_blend_validate.h"
#include "BLO_read_write.h"
2002-10-12 11:37:38 +00:00
#include "BLO_readfile.h"
#include "BLO_undofile.h"
#include "BLO_writefile.h"
2002-10-12 11:37:38 +00:00
#include "readfile.h"
#include <errno.h>
/* Make preferences read-only. */
#define U (*((const UserDef *)&U))
/* ********* my write, buffered writing with minimum size chunks ************ */
/* Use optimal allocation since blocks of this size are kept in memory for undo. */
#define MYWRITE_BUFFER_SIZE (MEM_SIZE_OPTIMAL(1 << 17)) /* 128kb */
#define MYWRITE_MAX_CHUNK (MEM_SIZE_OPTIMAL(1 << 15)) /* ~32kb */
/** Use if we want to store how many bytes have been written to the file. */
// #define USE_WRITE_DATA_LEN
/* -------------------------------------------------------------------- */
/** \name Internal Write Wrapper's (Abstracts Compression)
* \{ */
typedef enum {
WW_WRAP_NONE = 1,
WW_WRAP_ZLIB,
} eWriteWrapType;
typedef struct WriteWrap WriteWrap;
struct WriteWrap {
/* callbacks */
bool (*open)(WriteWrap *ww, const char *filepath);
bool (*close)(WriteWrap *ww);
size_t (*write)(WriteWrap *ww, const char *data, size_t data_len);
/* Buffer output (we only want when output isn't already buffered). */
bool use_buf;
/* internal */
union {
int file_handle;
gzFile gz_handle;
} _user_data;
};
/* none */
#define FILE_HANDLE(ww) (ww)->_user_data.file_handle
static bool ww_open_none(WriteWrap *ww, const char *filepath)
{
int file;
file = BLI_open(filepath, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
if (file != -1) {
FILE_HANDLE(ww) = file;
return true;
}
else {
return false;
}
}
static bool ww_close_none(WriteWrap *ww)
{
return (close(FILE_HANDLE(ww)) != -1);
}
static size_t ww_write_none(WriteWrap *ww, const char *buf, size_t buf_len)
{
return write(FILE_HANDLE(ww), buf, buf_len);
}
#undef FILE_HANDLE
/* zlib */
#define FILE_HANDLE(ww) (ww)->_user_data.gz_handle
static bool ww_open_zlib(WriteWrap *ww, const char *filepath)
{
gzFile file;
file = BLI_gzopen(filepath, "wb1");
if (file != Z_NULL) {
FILE_HANDLE(ww) = file;
return true;
}
else {
return false;
}
}
static bool ww_close_zlib(WriteWrap *ww)
{
return (gzclose(FILE_HANDLE(ww)) == Z_OK);
}
static size_t ww_write_zlib(WriteWrap *ww, const char *buf, size_t buf_len)
{
return gzwrite(FILE_HANDLE(ww), buf, buf_len);
}
#undef FILE_HANDLE
/* --- end compression types --- */
static void ww_handle_init(eWriteWrapType ww_type, WriteWrap *r_ww)
{
memset(r_ww, 0, sizeof(*r_ww));
switch (ww_type) {
case WW_WRAP_ZLIB: {
r_ww->open = ww_open_zlib;
r_ww->close = ww_close_zlib;
r_ww->write = ww_write_zlib;
r_ww->use_buf = false;
break;
}
default: {
r_ww->open = ww_open_none;
r_ww->close = ww_close_none;
r_ww->write = ww_write_none;
r_ww->use_buf = true;
break;
}
}
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Write Data Type & Functions
* \{ */
2002-10-12 11:37:38 +00:00
typedef struct {
const struct SDNA *sdna;
2002-10-12 11:37:38 +00:00
/** Use for file and memory writing (fixed size of #MYWRITE_BUFFER_SIZE). */
uchar *buf;
/** Number of bytes used in #WriteData.buf (flushed when exceeded). */
int buf_used_len;
#ifdef USE_WRITE_DATA_LEN
/** Total number of bytes written. */
size_t write_len;
#endif
/** Set on unlikely case of an error (ignores further file writing). */
bool error;
/** #MemFile writing (used for undo). */
MemFileWriteData mem;
/** When true, write to #WriteData.current, could also call 'is_undo'. */
bool use_memfile;
/**
* Wrap writing, so we can use zlib or
* other compression types later, see: G_FILE_COMPRESS
* Will be NULL for UNDO.
*/
WriteWrap *ww;
2002-10-12 11:37:38 +00:00
} WriteData;
typedef struct BlendWriter {
WriteData *wd;
} BlendWriter;
static WriteData *writedata_new(WriteWrap *ww)
2002-10-12 11:37:38 +00:00
{
WriteData *wd = MEM_callocN(sizeof(*wd), "writedata");
2002-10-12 11:37:38 +00:00
wd->sdna = DNA_sdna_current_get();
wd->ww = ww;
2002-10-12 11:37:38 +00:00
if ((ww == NULL) || (ww->use_buf)) {
wd->buf = MEM_mallocN(MYWRITE_BUFFER_SIZE, "wd->buf");
}
return wd;
2002-10-12 11:37:38 +00:00
}
static void writedata_do_write(WriteData *wd, const void *mem, int memlen)
2002-10-12 11:37:38 +00:00
{
if ((wd == NULL) || wd->error || (mem == NULL) || memlen < 1) {
return;
}
if (UNLIKELY(wd->error)) {
return;
}
/* memory based save */
if (wd->use_memfile) {
BLO_memfile_chunk_add(&wd->mem, mem, memlen);
}
else {
if (wd->ww->write(wd->ww, mem, memlen) != memlen) {
wd->error = true;
}
}
2002-10-12 11:37:38 +00:00
}
static void writedata_free(WriteData *wd)
2002-10-12 11:37:38 +00:00
{
if (wd->buf) {
MEM_freeN(wd->buf);
}
MEM_freeN(wd);
2002-10-12 11:37:38 +00:00
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Local Writing API 'mywrite'
* \{ */
2002-10-12 11:37:38 +00:00
/**
* Flush helps the de-duplicating memory for undo-save by logically segmenting data,
* so differences in one part of memory won't cause unrelated data to be duplicated.
*/
static void mywrite_flush(WriteData *wd)
{
if (wd->buf_used_len) {
writedata_do_write(wd, wd->buf, wd->buf_used_len);
wd->buf_used_len = 0;
}
}
2002-10-12 11:37:38 +00:00
/**
* Low level WRITE(2) wrapper that buffers data
* \param adr: Pointer to new chunk of data
* \param len: Length of new chunk of data
2002-10-12 11:37:38 +00:00
*/
static void mywrite(WriteData *wd, const void *adr, int len)
2002-10-12 11:37:38 +00:00
{
if (UNLIKELY(wd->error)) {
return;
}
2002-10-12 11:37:38 +00:00
if (UNLIKELY(adr == NULL)) {
BLI_assert(0);
return;
}
2002-10-12 11:37:38 +00:00
#ifdef USE_WRITE_DATA_LEN
wd->write_len += len;
#endif
if (wd->buf == NULL) {
writedata_do_write(wd, adr, len);
}
else {
/* if we have a single big chunk, write existing data in
* buffer and write out big chunk in smaller pieces */
if (len > MYWRITE_MAX_CHUNK) {
if (wd->buf_used_len) {
writedata_do_write(wd, wd->buf, wd->buf_used_len);
wd->buf_used_len = 0;
}
do {
int writelen = MIN2(len, MYWRITE_MAX_CHUNK);
writedata_do_write(wd, adr, writelen);
adr = (const char *)adr + writelen;
len -= writelen;
} while (len > 0);
return;
}
/* if data would overflow buffer, write out the buffer */
if (len + wd->buf_used_len > MYWRITE_BUFFER_SIZE - 1) {
writedata_do_write(wd, wd->buf, wd->buf_used_len);
wd->buf_used_len = 0;
}
/* append data at end of buffer */
memcpy(&wd->buf[wd->buf_used_len], adr, len);
wd->buf_used_len += len;
}
2002-10-12 11:37:38 +00:00
}
/**
* BeGiN initializer for mywrite
* \param ww: File write wrapper.
* \param compare: Previous memory file (can be NULL).
* \param current: The current memory file (can be NULL).
* \warning Talks to other functions with global parameters
2002-10-12 11:37:38 +00:00
*/
static WriteData *mywrite_begin(WriteWrap *ww, MemFile *compare, MemFile *current)
2002-10-12 11:37:38 +00:00
{
WriteData *wd = writedata_new(ww);
if (current != NULL) {
BLO_memfile_write_init(&wd->mem, current, compare);
wd->use_memfile = true;
}
return wd;
2002-10-12 11:37:38 +00:00
}
/**
* END the mywrite wrapper
* \return 1 if write failed
* \return unknown global variable otherwise
* \warning Talks to other functions with global parameters
2002-10-12 11:37:38 +00:00
*/
static bool mywrite_end(WriteData *wd)
2002-10-12 11:37:38 +00:00
{
if (wd->buf_used_len) {
writedata_do_write(wd, wd->buf, wd->buf_used_len);
wd->buf_used_len = 0;
}
if (wd->use_memfile) {
BLO_memfile_write_finalize(&wd->mem);
}
const bool err = wd->error;
writedata_free(wd);
return err;
2002-10-12 11:37:38 +00:00
}
/**
* Start writing of data related to a single ID.
*
* Only does something when storing an undo step.
*/
static void mywrite_id_begin(WriteData *wd, ID *id)
{
if (wd->use_memfile) {
wd->mem.current_id_session_uuid = id->session_uuid;
/* If current next memchunk does not match the ID we are about to write, try to find the
* correct memchunk in the mapping using ID's session_uuid. */
if (wd->mem.id_session_uuid_mapping != NULL &&
(wd->mem.reference_current_chunk == NULL ||
wd->mem.reference_current_chunk->id_session_uuid != id->session_uuid)) {
void *ref = BLI_ghash_lookup(wd->mem.id_session_uuid_mapping,
POINTER_FROM_UINT(id->session_uuid));
if (ref != NULL) {
wd->mem.reference_current_chunk = ref;
}
/* Else, no existing memchunk found, i.e. this is supposed to be a new ID. */
}
/* Otherwise, we try with the current memchunk in any case, whether it is matching current
* ID's session_uuid or not. */
}
}
/**
* Start writing of data related to a single ID.
*
* Only does something when storing an undo step.
*/
2020-06-04 01:18:14 +10:00
static void mywrite_id_end(WriteData *wd, ID *UNUSED(id))
{
if (wd->use_memfile) {
/* Very important to do it after every ID write now, otherwise we cannot know whether a
* specific ID changed or not. */
mywrite_flush(wd);
wd->mem.current_id_session_uuid = MAIN_ID_SESSION_UUID_UNSET;
}
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Generic DNA File Writing
* \{ */
2002-10-12 11:37:38 +00:00
static void writestruct_at_address_nr(
WriteData *wd, int filecode, const int struct_nr, int nr, const void *adr, const void *data)
2002-10-12 11:37:38 +00:00
{
BHead bh;
const short *sp;
BLI_assert(struct_nr > 0 && struct_nr < SDNA_TYPE_MAX);
if (adr == NULL || data == NULL || nr == 0) {
return;
}
/* init BHead */
bh.code = filecode;
bh.old = adr;
bh.nr = nr;
bh.SDNAnr = struct_nr;
sp = wd->sdna->structs[bh.SDNAnr];
bh.len = nr * wd->sdna->types_size[sp[0]];
if (bh.len == 0) {
return;
}
mywrite(wd, &bh, sizeof(BHead));
mywrite(wd, data, bh.len);
}
static void writestruct_nr(
WriteData *wd, int filecode, const int struct_nr, int nr, const void *adr)
{
writestruct_at_address_nr(wd, filecode, struct_nr, nr, adr, adr);
}
/* do not use for structs */
static void writedata(WriteData *wd, int filecode, int len, const void *adr)
2002-10-12 11:37:38 +00:00
{
BHead bh;
if (adr == NULL || len == 0) {
return;
}
/* align to 4 (writes uninitialized bytes in some cases) */
len = (len + 3) & ~3;
/* init BHead */
bh.code = filecode;
bh.old = adr;
bh.nr = 1;
bh.SDNAnr = 0;
bh.len = len;
mywrite(wd, &bh, sizeof(BHead));
mywrite(wd, adr, len);
2002-10-12 11:37:38 +00:00
}
/* use this to force writing of lists in same order as reading (using link_list) */
static void writelist_nr(WriteData *wd, int filecode, const int struct_nr, const ListBase *lb)
{
const Link *link = lb->first;
while (link) {
writestruct_nr(wd, filecode, struct_nr, 1, link);
link = link->next;
}
}
#if 0
static void writelist_id(WriteData *wd, int filecode, const char *structname, const ListBase *lb)
{
const Link *link = lb->first;
if (link) {
const int struct_nr = DNA_struct_find_nr(wd->sdna, structname);
if (struct_nr == -1) {
printf("error: can't find SDNA code <%s>\n", structname);
return;
}
while (link) {
writestruct_nr(wd, filecode, struct_nr, 1, link);
link = link->next;
}
}
}
#endif
#define writestruct_at_address(wd, filecode, struct_id, nr, adr, data) \
writestruct_at_address_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), nr, adr, data)
#define writestruct(wd, filecode, struct_id, nr, adr) \
writestruct_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), nr, adr)
#define writelist(wd, filecode, struct_id, lb) \
writelist_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), lb)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Typed DNA File Writing
*
* These functions are used by blender's .blend system for file saving/loading.
* \{ */
void IDP_WriteProperty_OnlyData(const IDProperty *prop, BlendWriter *writer);
void IDP_WriteProperty(const IDProperty *prop, BlendWriter *writer);
static void IDP_WriteArray(const IDProperty *prop, BlendWriter *writer)
{
/*REMEMBER to set totalen to len in the linking code!!*/
if (prop->data.pointer) {
BLO_write_raw(writer, MEM_allocN_len(prop->data.pointer), prop->data.pointer);
if (prop->subtype == IDP_GROUP) {
IDProperty **array = prop->data.pointer;
int a;
for (a = 0; a < prop->len; a++) {
IDP_WriteProperty(array[a], writer);
}
}
}
}
static void IDP_WriteIDPArray(const IDProperty *prop, BlendWriter *writer)
{
/*REMEMBER to set totalen to len in the linking code!!*/
if (prop->data.pointer) {
const IDProperty *array = prop->data.pointer;
int a;
BLO_write_struct_array(writer, IDProperty, prop->len, array);
for (a = 0; a < prop->len; a++) {
IDP_WriteProperty_OnlyData(&array[a], writer);
}
}
}
static void IDP_WriteString(const IDProperty *prop, BlendWriter *writer)
{
/*REMEMBER to set totalen to len in the linking code!!*/
BLO_write_raw(writer, prop->len, prop->data.pointer);
}
static void IDP_WriteGroup(const IDProperty *prop, BlendWriter *writer)
{
IDProperty *loop;
for (loop = prop->data.group.first; loop; loop = loop->next) {
IDP_WriteProperty(loop, writer);
}
}
/* Functions to read/write ID Properties */
void IDP_WriteProperty_OnlyData(const IDProperty *prop, BlendWriter *writer)
{
switch (prop->type) {
case IDP_GROUP:
IDP_WriteGroup(prop, writer);
break;
case IDP_STRING:
IDP_WriteString(prop, writer);
break;
case IDP_ARRAY:
IDP_WriteArray(prop, writer);
break;
case IDP_IDPARRAY:
IDP_WriteIDPArray(prop, writer);
break;
}
}
void IDP_WriteProperty(const IDProperty *prop, BlendWriter *writer)
{
BLO_write_struct(writer, IDProperty, prop);
IDP_WriteProperty_OnlyData(prop, writer);
}
2020-06-05 14:45:32 +02:00
static void write_iddata(BlendWriter *writer, ID *id)
{
/* ID_WM's id->properties are considered runtime only, and never written in .blend file. */
if (id->properties && !ELEM(GS(id->name), ID_WM)) {
IDP_WriteProperty(id->properties, writer);
}
if (id->override_library) {
2020-06-05 14:45:32 +02:00
BLO_write_struct(writer, IDOverrideLibrary, id->override_library);
2020-06-05 14:45:32 +02:00
BLO_write_struct_list(writer, IDOverrideLibraryProperty, &id->override_library->properties);
LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &id->override_library->properties) {
2020-06-05 14:45:32 +02:00
BLO_write_string(writer, op->rna_path);
2020-06-05 14:45:32 +02:00
BLO_write_struct_list(writer, IDOverrideLibraryPropertyOperation, &op->operations);
LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
if (opop->subitem_reference_name) {
2020-06-05 14:45:32 +02:00
BLO_write_string(writer, opop->subitem_reference_name);
}
if (opop->subitem_local_name) {
2020-06-05 14:45:32 +02:00
BLO_write_string(writer, opop->subitem_local_name);
}
}
}
}
}
static void write_previews(BlendWriter *writer, const PreviewImage *prv_orig)
{
/* Note we write previews also for undo steps. It takes up some memory,
* but not doing so would causes all previews to be re-rendered after
* undo which is too expensive. */
if (prv_orig) {
PreviewImage prv = *prv_orig;
/* don't write out large previews if not requested */
if (!(U.flag & USER_SAVE_PREVIEWS)) {
prv.w[1] = 0;
prv.h[1] = 0;
prv.rect[1] = NULL;
}
BLO_write_struct_at_address(writer, PreviewImage, prv_orig, &prv);
if (prv.rect[0]) {
BLO_write_uint32_array(writer, prv.w[0] * prv.h[0], prv.rect[0]);
}
if (prv.rect[1]) {
BLO_write_uint32_array(writer, prv.w[1] * prv.h[1], prv.rect[1]);
}
}
}
static void write_fmodifiers(BlendWriter *writer, ListBase *fmodifiers)
{
FModifier *fcm;
/* Write all modifiers first (for faster reloading) */
BLO_write_struct_list(writer, FModifier, fmodifiers);
/* Modifiers */
for (fcm = fmodifiers->first; fcm; fcm = fcm->next) {
const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm);
/* Write the specific data */
if (fmi && fcm->data) {
/* firstly, just write the plain fmi->data struct */
BLO_write_struct_by_name(writer, fmi->structName, fcm->data);
/* do any modifier specific stuff */
switch (fcm->type) {
case FMODIFIER_TYPE_GENERATOR: {
FMod_Generator *data = fcm->data;
/* write coefficients array */
if (data->coefficients) {
BLO_write_float_array(writer, data->arraysize, data->coefficients);
}
break;
}
case FMODIFIER_TYPE_ENVELOPE: {
FMod_Envelope *data = fcm->data;
/* write envelope data */
if (data->data) {
BLO_write_struct_array(writer, FCM_EnvelopeData, data->totvert, data->data);
}
break;
}
case FMODIFIER_TYPE_PYTHON: {
FMod_Python *data = fcm->data;
/* Write ID Properties -- and copy this comment EXACTLY for easy finding
* of library blocks that implement this.*/
IDP_WriteProperty(data->prop, writer);
break;
}
}
}
}
}
static void write_fcurves(BlendWriter *writer, ListBase *fcurves)
{
FCurve *fcu;
BLO_write_struct_list(writer, FCurve, fcurves);
for (fcu = fcurves->first; fcu; fcu = fcu->next) {
/* curve data */
if (fcu->bezt) {
BLO_write_struct_array(writer, BezTriple, fcu->totvert, fcu->bezt);
}
if (fcu->fpt) {
BLO_write_struct_array(writer, FPoint, fcu->totvert, fcu->fpt);
}
if (fcu->rna_path) {
BLO_write_string(writer, fcu->rna_path);
}
/* driver data */
if (fcu->driver) {
ChannelDriver *driver = fcu->driver;
DriverVar *dvar;
BLO_write_struct(writer, ChannelDriver, driver);
/* variables */
BLO_write_struct_list(writer, DriverVar, &driver->variables);
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
if (dtar->rna_path) {
BLO_write_string(writer, dtar->rna_path);
}
}
DRIVER_TARGETS_LOOPER_END;
}
}
/* write F-Modifiers */
write_fmodifiers(writer, &fcu->modifiers);
}
}
static void write_action(BlendWriter *writer, bAction *act, const void *id_address)
{
if (act->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, bAction, id_address, &act->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &act->id);
write_fcurves(writer, &act->curves);
LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) {
BLO_write_struct(writer, bActionGroup, grp);
}
LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) {
BLO_write_struct(writer, TimeMarker, marker);
}
}
}
static void write_keyingsets(BlendWriter *writer, ListBase *list)
{
KeyingSet *ks;
KS_Path *ksp;
for (ks = list->first; ks; ks = ks->next) {
/* KeyingSet */
BLO_write_struct(writer, KeyingSet, ks);
/* Paths */
for (ksp = ks->paths.first; ksp; ksp = ksp->next) {
/* Path */
BLO_write_struct(writer, KS_Path, ksp);
if (ksp->rna_path) {
BLO_write_string(writer, ksp->rna_path);
}
}
}
}
static void write_nlastrips(BlendWriter *writer, ListBase *strips)
{
NlaStrip *strip;
BLO_write_struct_list(writer, NlaStrip, strips);
for (strip = strips->first; strip; strip = strip->next) {
/* write the strip's F-Curves and modifiers */
write_fcurves(writer, &strip->fcurves);
write_fmodifiers(writer, &strip->modifiers);
/* write the strip's children */
write_nlastrips(writer, &strip->strips);
}
}
static void write_nladata(BlendWriter *writer, ListBase *nlabase)
{
NlaTrack *nlt;
/* write all the tracks */
for (nlt = nlabase->first; nlt; nlt = nlt->next) {
/* write the track first */
BLO_write_struct(writer, NlaTrack, nlt);
/* write the track's strips */
write_nlastrips(writer, &nlt->strips);
}
}
static void write_animdata(BlendWriter *writer, AnimData *adt)
{
AnimOverride *aor;
/* firstly, just write the AnimData block */
BLO_write_struct(writer, AnimData, adt);
/* write drivers */
write_fcurves(writer, &adt->drivers);
/* write overrides */
// FIXME: are these needed?
for (aor = adt->overrides.first; aor; aor = aor->next) {
/* overrides consist of base data + rna_path */
BLO_write_struct(writer, AnimOverride, aor);
BLO_write_string(writer, aor->rna_path);
}
// TODO write the remaps (if they are needed)
/* write NLA data */
write_nladata(writer, &adt->nla_tracks);
}
static void write_curvemapping_curves(BlendWriter *writer, CurveMapping *cumap)
Orange: - New UI element: the "Curve Button". For mapping ranges (like 0 - 1) to another range, the curve button can be used for proportional falloff, bone influences, painting density, etc. Most evident use is of course to map RGB color with curves. To be able to use it, you have to allocate a CurveMapping struct and pass this on to the button. The CurveMapping API is in the new C file blenkernel/intern/colortools.c It's as simple as calling: curvemap= curvemapping_add(3, 0, 0, 1, 1) Which will create 3 curves, and sets a default 0-1 range. The current code only supports up to 4 curves maximum per mapping struct. The CurveMap button in Blender than handles allmost all editing. Evaluating a single channel: float newvalue= curvemapping_evaluateF(curvemap, 0, oldval); Where the second argument is the channel index, here 0-1-2 are possible. Or mapping a vector: curvemapping_evaluate3F(curvemap, newvec, oldvec); Optimized versions for byte or short mapping is possible too, not done yet. In butspace.c I've added a template wrapper for buttons around the curve, to reveil settings or show tools; check this screenie: http://www.blender.org/bf/curves.jpg - Buttons R, G, B: select channel - icons + and -: zoom in, out - icon 'wrench': menu with tools, like clear curve, set handle type - icon 'clipping': menu with clip values, and to dis/enable clipping - icon 'x': delete selection In the curve button itself, only LMB clicks are handled (like all UI elements in Blender). - click on point: select - shift+click on point: swap select - click on point + drag: select point (if not selected) and move it - click outside point + drag: translate view - CTRL+click: add new point - hold SHIFT while dragging to snap to grid (Yes I know... either one of these can be Blender compliant, not both!) - if you drag a point exactly on top of another, it merges them Other fixes: - Icons now draw using "Safe RasterPos", so they align with pixel boundary. the old code made ints from the raster pos coordinate, which doesn't work well for zoom in/out situations - bug in Node editing: buttons could not get freed, causing in memory error prints at end of a Blender session. That one was a very simple, but nasty error causing me all evening last night to find! (Hint; check diff of editnode.c, where uiDoButtons is called) Last note: this adds 3 new files in our tree, I did scons, but not MSVC!
2006-01-08 11:41:06 +00:00
{
for (int a = 0; a < CM_TOT; a++) {
BLO_write_struct_array(writer, CurveMapPoint, cumap->cm[a].totpoint, cumap->cm[a].curve);
}
Orange: - New UI element: the "Curve Button". For mapping ranges (like 0 - 1) to another range, the curve button can be used for proportional falloff, bone influences, painting density, etc. Most evident use is of course to map RGB color with curves. To be able to use it, you have to allocate a CurveMapping struct and pass this on to the button. The CurveMapping API is in the new C file blenkernel/intern/colortools.c It's as simple as calling: curvemap= curvemapping_add(3, 0, 0, 1, 1) Which will create 3 curves, and sets a default 0-1 range. The current code only supports up to 4 curves maximum per mapping struct. The CurveMap button in Blender than handles allmost all editing. Evaluating a single channel: float newvalue= curvemapping_evaluateF(curvemap, 0, oldval); Where the second argument is the channel index, here 0-1-2 are possible. Or mapping a vector: curvemapping_evaluate3F(curvemap, newvec, oldvec); Optimized versions for byte or short mapping is possible too, not done yet. In butspace.c I've added a template wrapper for buttons around the curve, to reveil settings or show tools; check this screenie: http://www.blender.org/bf/curves.jpg - Buttons R, G, B: select channel - icons + and -: zoom in, out - icon 'wrench': menu with tools, like clear curve, set handle type - icon 'clipping': menu with clip values, and to dis/enable clipping - icon 'x': delete selection In the curve button itself, only LMB clicks are handled (like all UI elements in Blender). - click on point: select - shift+click on point: swap select - click on point + drag: select point (if not selected) and move it - click outside point + drag: translate view - CTRL+click: add new point - hold SHIFT while dragging to snap to grid (Yes I know... either one of these can be Blender compliant, not both!) - if you drag a point exactly on top of another, it merges them Other fixes: - Icons now draw using "Safe RasterPos", so they align with pixel boundary. the old code made ints from the raster pos coordinate, which doesn't work well for zoom in/out situations - bug in Node editing: buttons could not get freed, causing in memory error prints at end of a Blender session. That one was a very simple, but nasty error causing me all evening last night to find! (Hint; check diff of editnode.c, where uiDoButtons is called) Last note: this adds 3 new files in our tree, I did scons, but not MSVC!
2006-01-08 11:41:06 +00:00
}
static void write_curvemapping(BlendWriter *writer, CurveMapping *cumap)
{
BLO_write_struct(writer, CurveMapping, cumap);
write_curvemapping_curves(writer, cumap);
}
static void write_CurveProfile(BlendWriter *writer, CurveProfile *profile)
{
BLO_write_struct(writer, CurveProfile, profile);
BLO_write_struct_array(writer, CurveProfilePoint, profile->path_len, profile->path);
}
static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *sock)
{
if (sock->default_value == NULL) {
return;
}
switch ((eNodeSocketDatatype)sock->type) {
case SOCK_FLOAT:
BLO_write_struct(writer, bNodeSocketValueFloat, sock->default_value);
break;
case SOCK_VECTOR:
BLO_write_struct(writer, bNodeSocketValueVector, sock->default_value);
break;
case SOCK_RGBA:
BLO_write_struct(writer, bNodeSocketValueRGBA, sock->default_value);
break;
case SOCK_BOOLEAN:
BLO_write_struct(writer, bNodeSocketValueBoolean, sock->default_value);
break;
case SOCK_INT:
BLO_write_struct(writer, bNodeSocketValueInt, sock->default_value);
break;
case SOCK_STRING:
BLO_write_struct(writer, bNodeSocketValueString, sock->default_value);
break;
case SOCK_OBJECT:
BLO_write_struct(writer, bNodeSocketValueObject, sock->default_value);
break;
case SOCK_IMAGE:
BLO_write_struct(writer, bNodeSocketValueImage, sock->default_value);
break;
case __SOCK_MESH:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_EMITTERS:
case SOCK_EVENTS:
case SOCK_FORCES:
case SOCK_CONTROL_FLOW:
BLI_assert(false);
break;
}
}
static void write_node_socket(BlendWriter *writer, bNodeSocket *sock)
{
/* actual socket writing */
BLO_write_struct(writer, bNodeSocket, sock);
Merge of the PyNodes branch (aka "custom nodes") into trunk. PyNodes opens up the node system in Blender to scripters and adds a number of UI-level improvements. === Dynamic node type registration === Node types can now be added at runtime, using the RNA registration mechanism from python. This enables addons such as render engines to create a complete user interface with nodes. Examples of how such nodes can be defined can be found in my personal wiki docs atm [1] and as a script template in release/scripts/templates_py/custom_nodes.py [2]. === Node group improvements === Each node editor now has a tree history of edited node groups, which allows opening and editing nested node groups. The node editor also supports pinning now, so that different spaces can be used to edit different node groups simultaneously. For more ramblings and rationale see (really old) blog post on code.blender.org [3]. The interface of node groups has been overhauled. Sockets of a node group are no longer displayed in columns on either side, but instead special input/output nodes are used to mirror group sockets inside a node tree. This solves the problem of long node lines in groups and allows more adaptable node layout. Internal sockets can be exposed from a group by either connecting to the extension sockets in input/output nodes (shown as empty circle) or by adding sockets from the node property bar in the "Interface" panel. Further details such as the socket name can also be changed there. [1] http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes [2] http://projects.blender.org/scm/viewvc.php/trunk/blender/release/scripts/templates_py/custom_nodes.py?view=markup&root=bf-blender [3] http://code.blender.org/index.php/2012/01/improving-node-group-interface-editing/
2013-03-18 16:34:57 +00:00
if (sock->prop) {
IDP_WriteProperty(sock->prop, writer);
}
write_node_socket_default_value(writer, sock);
}
static void write_node_socket_interface(BlendWriter *writer, bNodeSocket *sock)
Merge of the PyNodes branch (aka "custom nodes") into trunk. PyNodes opens up the node system in Blender to scripters and adds a number of UI-level improvements. === Dynamic node type registration === Node types can now be added at runtime, using the RNA registration mechanism from python. This enables addons such as render engines to create a complete user interface with nodes. Examples of how such nodes can be defined can be found in my personal wiki docs atm [1] and as a script template in release/scripts/templates_py/custom_nodes.py [2]. === Node group improvements === Each node editor now has a tree history of edited node groups, which allows opening and editing nested node groups. The node editor also supports pinning now, so that different spaces can be used to edit different node groups simultaneously. For more ramblings and rationale see (really old) blog post on code.blender.org [3]. The interface of node groups has been overhauled. Sockets of a node group are no longer displayed in columns on either side, but instead special input/output nodes are used to mirror group sockets inside a node tree. This solves the problem of long node lines in groups and allows more adaptable node layout. Internal sockets can be exposed from a group by either connecting to the extension sockets in input/output nodes (shown as empty circle) or by adding sockets from the node property bar in the "Interface" panel. Further details such as the socket name can also be changed there. [1] http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes [2] http://projects.blender.org/scm/viewvc.php/trunk/blender/release/scripts/templates_py/custom_nodes.py?view=markup&root=bf-blender [3] http://code.blender.org/index.php/2012/01/improving-node-group-interface-editing/
2013-03-18 16:34:57 +00:00
{
/* actual socket writing */
BLO_write_struct(writer, bNodeSocket, sock);
if (sock->prop) {
IDP_WriteProperty(sock->prop, writer);
}
write_node_socket_default_value(writer, sock);
Merge of the PyNodes branch (aka "custom nodes") into trunk. PyNodes opens up the node system in Blender to scripters and adds a number of UI-level improvements. === Dynamic node type registration === Node types can now be added at runtime, using the RNA registration mechanism from python. This enables addons such as render engines to create a complete user interface with nodes. Examples of how such nodes can be defined can be found in my personal wiki docs atm [1] and as a script template in release/scripts/templates_py/custom_nodes.py [2]. === Node group improvements === Each node editor now has a tree history of edited node groups, which allows opening and editing nested node groups. The node editor also supports pinning now, so that different spaces can be used to edit different node groups simultaneously. For more ramblings and rationale see (really old) blog post on code.blender.org [3]. The interface of node groups has been overhauled. Sockets of a node group are no longer displayed in columns on either side, but instead special input/output nodes are used to mirror group sockets inside a node tree. This solves the problem of long node lines in groups and allows more adaptable node layout. Internal sockets can be exposed from a group by either connecting to the extension sockets in input/output nodes (shown as empty circle) or by adding sockets from the node property bar in the "Interface" panel. Further details such as the socket name can also be changed there. [1] http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes [2] http://projects.blender.org/scm/viewvc.php/trunk/blender/release/scripts/templates_py/custom_nodes.py?view=markup&root=bf-blender [3] http://code.blender.org/index.php/2012/01/improving-node-group-interface-editing/
2013-03-18 16:34:57 +00:00
}
Orange: more noodle updates! **** NEW: Group Nodes Node trees usually become messy and confusing quickly, so we need not only a way to collapse Nodes into single 'groups', but also a way to re-use that data to create libraries of effects. This has been done by making a new Library data type, the NodeTree. Everything that has been grouped is stored here, and available for re-use, appending or linking. These NodeTrees are fully generic, i.e. can store shader trees, composit trees, and so on. The 'type' value as stored in the NodeTree will keep track of internal type definitions and execute/drawing callbacks. Needless to say, re-using shader trees in a composit tree is a bit useless, and will be prevented in the browsing code. :) So; any NodeTree can become a "Goup Node" inside in a NodeTree. This Group Node then works just like any Node. To prevent the current code to become too complex, I've disabled the possibility to insert Groups inside of Groups. That might be enabled later, but is a real nasty piece of code to get OK. Since Group Nodes are a dynamic Node type, a lot of work has been done to ensure Node definitions can be dynamic too, but still allow to be stored in files, and allow to be verified for type-definition changes on reloading. This system needs a little bit maturing still, so the Python gurus should better wait a little bit! (Also for me to write the definite API docs for it). What works now: - Press CTRL+G to create a new Group. The grouping code checks for impossible selections (like an unselected node between selected nodes). Everthing that's selected then gets removed from the current tree, and inserted in a new NodeTree library data block. A Group Node then is added which links to this new NodeTree. - Press ALT+G to ungroup. This will not delete the NodeTree library data, but just duplicate the Group into the current tree. - Press TAB, or click on the NodeTree icon to edit Groups. Note that NodeTrees are instances, so editing one Group will also change the other users. This also means that when removing nodes in a Group (or hiding sockets or changing internal links) this is immediately corrected for all users of this Group, also in other Materials. - While editing Groups, only the internal Nodes can be edited. A single click outside of the Group boundary will close this 'edit mode'. What needs to be done: - SHIFT+A menu in toolbox style, also including a list of Groups - Enable the single-user button in the Group Node - Displaying all (visible) internal group UI elements in the Node Panel - Enable Library linking and prevent editing of Groups then. **** NEW: Socket Visibility control Node types will be generated with a lot of possible inputs or outputs, and drawing all sockets all the time isn't very useful then. A new option in the Node header ('plus' icon) allows to either hide all unused sockets (first keypress) or to reveil them (when there are hidden sockets, the icon displays black, otherwise it's blended). Hidden sockets in Nodes also are not exported to a Group, so this way you can control what options (in/outputs) exactly are available. To be done: - a way to hide individual sockets, like with a RMB click on it. **** NEW: Nodes now render! This is still quite primitive, more on a level to replace the (now obsolete and disabled) Material Layers. What needs to be done: - make the "Geometry" node work properly, also for AA textures - make the Texture Node work (does very little at the moment) - give Material Nodes all inputs as needed (like Map-to Panel) - find a way to export more data from a Material Node, like the shadow value, or light intensity only, etc Very important also to separate from the Material Buttons the "global" options, like "Ztransp" or "Wire" or "Halo". These can not be set for each Material-Node individually. Also note that the Preview Render (Buttons window) now renders a bit differently. This was a horrid piece of antique code, using a totally incompatible way of rendering. Target is to fully re-use internal render code for previews. OK... that's it mostly. Now test!
2006-01-02 13:06:05 +00:00
/* this is only direct data, tree itself should have been written */
static void write_nodetree_nolib(BlendWriter *writer, bNodeTree *ntree)
Christmas coding work! ********* Node editor work: - To enable Nodes for Materials, you have to set the "Use Nodes" button, in the new Material buttons "Nodes" Panel or in header of the Node editor. Doing this will disable Material-Layers. - Nodes now execute materials ("shaders"), but still only using the previewrender code. - Nodes have (optional) previews for rendered images. - Node headers allow to hide buttons and/or preview image - Nodes can be dragged larger/smaller (right-bottom corner) - Nodes can be hidden (minimized) with hotkey H - CTRL+click on an Input Socket gives a popup with default values. - Changing Material/Texture or Mix node will adjust Node title. - Click-drag outside of a Node changes cursor to "Knife' and allows to draw a rect where to cut Links. - Added new node types RGBtoBW, Texture, In/Output, ColorRamp - Material Nodes have options to ouput diffuse or specular, or to use a negative normal. The input socket 'Normal' will force the material to use that normal, otherwise it uses the normal from the Material that has the node tree. - When drawing a link between two not-matching sockets, Blender inserts a converting node (now only for value/rgb combos) - When drawing a link to an input socket that's already in use, the old link will either disappear or flip to another unused socket. - A click on a Material Node will activate it, and show all its settings in the Material Buttons. Active Material Nodes draw the material icon in red. - A click on any node will show its options in the Node Panel in the Material buttons. - Multiple Output Nodes can be used, to sample contents of a tree, but only one Output is the real one, which is indicated in a different color and red material icon. - Added ThemeColors for node types - ALT+C will convert existing Material-Layers to Node... this currently only adds the material/mix nodes and connects them. Dunno if this is worth a lot of coding work to make perfect? - Press C to call another "Solve order", which will show all possible cyclic conflicts (if there are). - Technical: nodes now use "Type" structs which define the structure of nodes and in/output sockets. The Type structs store all fixed info, callbacks, and allow to reconstruct saved Nodes to match what is required by Blender. - Defining (new) nodes now is as simple as filling in a fixed Type struct, plus code some callbacks. A doc will be made! - Node preview images are by default float ********* Icon drawing: - Cleanup of how old icons were implemented in new system, making them 16x16 too, correctly centered *and* scaled. - Made drawing Icons use float coordinates - Moved BIF_calcpreview_image() into interface_icons.c, renamed it icon_from_image(). Removed a lot of unneeded Imbuf magic here! :) - Skipped scaling and imbuf copying when icons are OK size ********* Preview render: - Huge cleanup of code.... - renaming BIF_xxx calls that only were used internally - BIF_previewrender() now accepts an argument for rendering method, so it supports icons, buttonwindow previewrender and node editor - Only a single BIF_preview_changed() call now exists, supporting all signals as needed for buttos and node editor ********* More stuff: - glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format argument for GL_FLOAT rects - Made the ColorBand become a built-in button for interface.c Was a load of cleanup work in buttons_shading.c... - removed a load of unneeded glBlendFunc() calls - Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
{
bNode *node;
bNodeSocket *sock;
bNodeLink *link;
/* for link_list() speed, we write per list */
if (ntree->adt) {
write_animdata(writer, ntree->adt);
}
for (node = ntree->nodes.first; node; node = node->next) {
BLO_write_struct(writer, bNode, node);
if (node->prop) {
IDP_WriteProperty(node->prop, writer);
}
for (sock = node->inputs.first; sock; sock = sock->next) {
write_node_socket(writer, sock);
}
for (sock = node->outputs.first; sock; sock = sock->next) {
write_node_socket(writer, sock);
}
for (link = node->internal_links.first; link; link = link->next) {
BLO_write_struct(writer, bNodeLink, link);
}
if (node->storage) {
/* could be handlerized at some point, now only 1 exception still */
if ((ntree->type == NTREE_SHADER) &&
ELEM(node->type, SH_NODE_CURVE_VEC, SH_NODE_CURVE_RGB)) {
write_curvemapping(writer, node->storage);
}
else if (ntree->type == NTREE_SHADER && (node->type == SH_NODE_SCRIPT)) {
NodeShaderScript *nss = (NodeShaderScript *)node->storage;
if (nss->bytecode) {
BLO_write_string(writer, nss->bytecode);
}
BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage);
}
else if ((ntree->type == NTREE_COMPOSIT) && ELEM(node->type,
CMP_NODE_TIME,
CMP_NODE_CURVE_VEC,
CMP_NODE_CURVE_RGB,
CMP_NODE_HUECORRECT)) {
write_curvemapping(writer, node->storage);
}
else if ((ntree->type == NTREE_TEXTURE) &&
(node->type == TEX_NODE_CURVE_RGB || node->type == TEX_NODE_CURVE_TIME)) {
write_curvemapping(writer, node->storage);
}
else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_MOVIEDISTORTION)) {
/* pass */
}
else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_GLARE)) {
2019-06-16 13:37:21 +10:00
/* Simple forward compatibility for fix for T50736.
* Not ideal (there is no ideal solution here), but should do for now. */
NodeGlare *ndg = node->storage;
/* Not in undo case. */
if (!BLO_write_is_undo(writer)) {
switch (ndg->type) {
case 2: /* Grrrr! magic numbers :( */
ndg->angle = ndg->streaks;
break;
case 0:
ndg->angle = ndg->star_45;
break;
default:
break;
}
}
BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage);
}
else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_CRYPTOMATTE)) {
NodeCryptomatte *nc = (NodeCryptomatte *)node->storage;
if (nc->matte_id) {
BLO_write_string(writer, nc->matte_id);
}
BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage);
}
else {
BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage);
}
}
if (node->type == CMP_NODE_OUTPUT_FILE) {
/* inputs have own storage data */
for (sock = node->inputs.first; sock; sock = sock->next) {
BLO_write_struct(writer, NodeImageMultiFileSocket, sock->storage);
}
}
if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) {
/* write extra socket info */
for (sock = node->outputs.first; sock; sock = sock->next) {
BLO_write_struct(writer, NodeImageLayer, sock->storage);
}
}
}
for (link = ntree->links.first; link; link = link->next) {
BLO_write_struct(writer, bNodeLink, link);
}
for (sock = ntree->inputs.first; sock; sock = sock->next) {
write_node_socket_interface(writer, sock);
}
for (sock = ntree->outputs.first; sock; sock = sock->next) {
write_node_socket_interface(writer, sock);
}
Christmas coding work! ********* Node editor work: - To enable Nodes for Materials, you have to set the "Use Nodes" button, in the new Material buttons "Nodes" Panel or in header of the Node editor. Doing this will disable Material-Layers. - Nodes now execute materials ("shaders"), but still only using the previewrender code. - Nodes have (optional) previews for rendered images. - Node headers allow to hide buttons and/or preview image - Nodes can be dragged larger/smaller (right-bottom corner) - Nodes can be hidden (minimized) with hotkey H - CTRL+click on an Input Socket gives a popup with default values. - Changing Material/Texture or Mix node will adjust Node title. - Click-drag outside of a Node changes cursor to "Knife' and allows to draw a rect where to cut Links. - Added new node types RGBtoBW, Texture, In/Output, ColorRamp - Material Nodes have options to ouput diffuse or specular, or to use a negative normal. The input socket 'Normal' will force the material to use that normal, otherwise it uses the normal from the Material that has the node tree. - When drawing a link between two not-matching sockets, Blender inserts a converting node (now only for value/rgb combos) - When drawing a link to an input socket that's already in use, the old link will either disappear or flip to another unused socket. - A click on a Material Node will activate it, and show all its settings in the Material Buttons. Active Material Nodes draw the material icon in red. - A click on any node will show its options in the Node Panel in the Material buttons. - Multiple Output Nodes can be used, to sample contents of a tree, but only one Output is the real one, which is indicated in a different color and red material icon. - Added ThemeColors for node types - ALT+C will convert existing Material-Layers to Node... this currently only adds the material/mix nodes and connects them. Dunno if this is worth a lot of coding work to make perfect? - Press C to call another "Solve order", which will show all possible cyclic conflicts (if there are). - Technical: nodes now use "Type" structs which define the structure of nodes and in/output sockets. The Type structs store all fixed info, callbacks, and allow to reconstruct saved Nodes to match what is required by Blender. - Defining (new) nodes now is as simple as filling in a fixed Type struct, plus code some callbacks. A doc will be made! - Node preview images are by default float ********* Icon drawing: - Cleanup of how old icons were implemented in new system, making them 16x16 too, correctly centered *and* scaled. - Made drawing Icons use float coordinates - Moved BIF_calcpreview_image() into interface_icons.c, renamed it icon_from_image(). Removed a lot of unneeded Imbuf magic here! :) - Skipped scaling and imbuf copying when icons are OK size ********* Preview render: - Huge cleanup of code.... - renaming BIF_xxx calls that only were used internally - BIF_previewrender() now accepts an argument for rendering method, so it supports icons, buttonwindow previewrender and node editor - Only a single BIF_preview_changed() call now exists, supporting all signals as needed for buttos and node editor ********* More stuff: - glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format argument for GL_FLOAT rects - Made the ColorBand become a built-in button for interface.c Was a load of cleanup work in buttons_shading.c... - removed a load of unneeded glBlendFunc() calls - Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
}
/**
* Take care using 'use_active_win', since we wont want the currently active window
* to change which scene renders (currently only used for undo).
*/
static void current_screen_compat(Main *mainvar,
bool use_active_win,
bScreen **r_screen,
Scene **r_scene,
ViewLayer **r_view_layer)
2002-10-12 11:37:38 +00:00
{
wmWindowManager *wm;
wmWindow *window = NULL;
/* find a global current screen in the first open window, to have
* a reasonable default for reading in older versions */
wm = mainvar->wm.first;
if (wm) {
if (use_active_win) {
/* write the active window into the file, needed for multi-window undo T43424 */
for (window = wm->windows.first; window; window = window->next) {
if (window->active) {
break;
}
}
/* fallback */
if (window == NULL) {
window = wm->windows.first;
}
}
else {
window = wm->windows.first;
}
}
*r_screen = (window) ? BKE_workspace_active_screen_get(window->workspace_hook) : NULL;
*r_scene = (window) ? window->scene : NULL;
*r_view_layer = (window && *r_scene) ? BKE_view_layer_find(*r_scene, window->view_layer_name) :
NULL;
}
typedef struct RenderInfo {
int sfra;
int efra;
char scene_name[MAX_ID_NAME - 2];
} RenderInfo;
2019-08-17 00:54:22 +10:00
/**
* This was originally added for the historic render-daemon feature,
* now write because it can be easily extracted without reading the whole blend file.
*
* See: `release/scripts/modules/blend_render_info.py`
*/
static void write_renderinfo(WriteData *wd, Main *mainvar)
{
bScreen *curscreen;
Scene *sce, *curscene = NULL;
ViewLayer *view_layer;
RenderInfo data;
/* XXX in future, handle multiple windows with multiple screens? */
current_screen_compat(mainvar, false, &curscreen, &curscene, &view_layer);
for (sce = mainvar->scenes.first; sce; sce = sce->id.next) {
if (sce->id.lib == NULL && (sce == curscene || (sce->r.scemode & R_BG_RENDER))) {
data.sfra = sce->r.sfra;
data.efra = sce->r.efra;
memset(data.scene_name, 0, sizeof(data.scene_name));
BLI_strncpy(data.scene_name, sce->id.name + 2, sizeof(data.scene_name));
writedata(wd, REND, sizeof(data), &data);
}
}
2002-10-12 11:37:38 +00:00
}
2020-06-05 21:19:03 +02:00
static void write_keymapitem(BlendWriter *writer, const wmKeyMapItem *kmi)
{
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, wmKeyMapItem, kmi);
if (kmi->properties) {
IDP_WriteProperty(kmi->properties, writer);
}
}
2020-06-05 21:19:03 +02:00
static void write_userdef(BlendWriter *writer, const UserDef *userdef)
2002-10-12 11:37:38 +00:00
{
2020-06-05 21:19:03 +02:00
writestruct(writer->wd, USER, UserDef, 1, userdef);
LISTBASE_FOREACH (const bTheme *, btheme, &userdef->themes) {
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, bTheme, btheme);
}
LISTBASE_FOREACH (const wmKeyMap *, keymap, &userdef->user_keymaps) {
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, wmKeyMap, keymap);
LISTBASE_FOREACH (const wmKeyMapDiffItem *, kmdi, &keymap->diff_items) {
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, wmKeyMapDiffItem, kmdi);
if (kmdi->remove_item) {
2020-06-05 21:19:03 +02:00
write_keymapitem(writer, kmdi->remove_item);
}
if (kmdi->add_item) {
2020-06-05 21:19:03 +02:00
write_keymapitem(writer, kmdi->add_item);
}
}
LISTBASE_FOREACH (const wmKeyMapItem *, kmi, &keymap->items) {
2020-06-05 21:19:03 +02:00
write_keymapitem(writer, kmi);
}
}
LISTBASE_FOREACH (const wmKeyConfigPref *, kpt, &userdef->user_keyconfig_prefs) {
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, wmKeyConfigPref, kpt);
if (kpt->prop) {
IDP_WriteProperty(kpt->prop, writer);
}
}
LISTBASE_FOREACH (const bUserMenu *, um, &userdef->user_menus) {
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, bUserMenu, um);
LISTBASE_FOREACH (const bUserMenuItem *, umi, &um->items) {
if (umi->type == USER_MENU_TYPE_OPERATOR) {
const bUserMenuItem_Op *umi_op = (const bUserMenuItem_Op *)umi;
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, bUserMenuItem_Op, umi_op);
if (umi_op->prop) {
IDP_WriteProperty(umi_op->prop, writer);
}
}
else if (umi->type == USER_MENU_TYPE_MENU) {
const bUserMenuItem_Menu *umi_mt = (const bUserMenuItem_Menu *)umi;
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, bUserMenuItem_Menu, umi_mt);
}
else if (umi->type == USER_MENU_TYPE_PROP) {
const bUserMenuItem_Prop *umi_pr = (const bUserMenuItem_Prop *)umi;
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, bUserMenuItem_Prop, umi_pr);
}
else {
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, bUserMenuItem, umi);
}
}
}
LISTBASE_FOREACH (const bAddon *, bext, &userdef->addons) {
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, bAddon, bext);
if (bext->prop) {
IDP_WriteProperty(bext->prop, writer);
}
}
LISTBASE_FOREACH (const bPathCompare *, path_cmp, &userdef->autoexec_paths) {
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, bPathCompare, path_cmp);
}
LISTBASE_FOREACH (const uiStyle *, style, &userdef->uistyles) {
2020-06-05 21:19:03 +02:00
BLO_write_struct(writer, uiStyle, style);
}
2002-10-12 11:37:38 +00:00
}
static void write_boid_state(BlendWriter *writer, BoidState *state)
{
BoidRule *rule = state->rules.first;
BLO_write_struct(writer, BoidState, state);
for (; rule; rule = rule->next) {
switch (rule->type) {
case eBoidRuleType_Goal:
case eBoidRuleType_Avoid:
BLO_write_struct(writer, BoidRuleGoalAvoid, rule);
break;
case eBoidRuleType_AvoidCollision:
BLO_write_struct(writer, BoidRuleAvoidCollision, rule);
break;
case eBoidRuleType_FollowLeader:
BLO_write_struct(writer, BoidRuleFollowLeader, rule);
break;
case eBoidRuleType_AverageSpeed:
BLO_write_struct(writer, BoidRuleAverageSpeed, rule);
break;
case eBoidRuleType_Fight:
BLO_write_struct(writer, BoidRuleFight, rule);
break;
default:
BLO_write_struct(writer, BoidRule, rule);
break;
}
}
#if 0
BoidCondition *cond = state->conditions.first;
for (; cond; cond = cond->next) {
BLO_write_struct(writer, BoidCondition, cond);
}
#endif
}
/* update this also to readfile.c */
static const char *ptcache_data_struct[] = {
"", // BPHYS_DATA_INDEX
"", // BPHYS_DATA_LOCATION
"", // BPHYS_DATA_VELOCITY
"", // BPHYS_DATA_ROTATION
"", // BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST */
"", // BPHYS_DATA_SIZE:
"", // BPHYS_DATA_TIMES:
"BoidData", // case BPHYS_DATA_BOIDS:
};
static const char *ptcache_extra_struct[] = {
"",
"ParticleSpring",
};
static void write_pointcaches(BlendWriter *writer, ListBase *ptcaches)
{
PointCache *cache = ptcaches->first;
int i;
for (; cache; cache = cache->next) {
BLO_write_struct(writer, PointCache, cache);
if ((cache->flag & PTCACHE_DISK_CACHE) == 0) {
PTCacheMem *pm = cache->mem_cache.first;
for (; pm; pm = pm->next) {
PTCacheExtra *extra = pm->extradata.first;
BLO_write_struct(writer, PTCacheMem, pm);
for (i = 0; i < BPHYS_TOT_DATA; i++) {
if (pm->data[i] && pm->data_types & (1 << i)) {
if (ptcache_data_struct[i][0] == '\0') {
BLO_write_raw(writer, MEM_allocN_len(pm->data[i]), pm->data[i]);
}
else {
BLO_write_struct_array_by_name(
writer, ptcache_data_struct[i], pm->totpoint, pm->data[i]);
}
}
}
for (; extra; extra = extra->next) {
if (ptcache_extra_struct[extra->type][0] == '\0') {
continue;
}
BLO_write_struct(writer, PTCacheExtra, extra);
BLO_write_struct_array_by_name(
writer, ptcache_extra_struct[extra->type], extra->totdata, extra->data);
}
}
}
}
}
static void write_particlesettings(BlendWriter *writer,
ParticleSettings *part,
const void *id_address)
{
if (part->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, ParticleSettings, id_address, &part->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &part->id);
if (part->adt) {
write_animdata(writer, part->adt);
}
BLO_write_struct(writer, PartDeflect, part->pd);
BLO_write_struct(writer, PartDeflect, part->pd2);
BLO_write_struct(writer, EffectorWeights, part->effector_weights);
if (part->clumpcurve) {
write_curvemapping(writer, part->clumpcurve);
}
if (part->roughcurve) {
write_curvemapping(writer, part->roughcurve);
}
if (part->twistcurve) {
write_curvemapping(writer, part->twistcurve);
}
LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) {
/* update indices, but only if dw->ob is set (can be NULL after loading e.g.) */
if (dw->ob != NULL) {
dw->index = 0;
if (part->instance_collection) { /* can be NULL if lining fails or set to None */
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (part->instance_collection, object) {
if (object == dw->ob) {
break;
}
dw->index++;
}
FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
}
}
BLO_write_struct(writer, ParticleDupliWeight, dw);
}
if (part->boids && part->phystype == PART_PHYS_BOIDS) {
BLO_write_struct(writer, BoidSettings, part->boids);
LISTBASE_FOREACH (BoidState *, state, &part->boids->states) {
write_boid_state(writer, state);
}
}
if (part->fluid && part->phystype == PART_PHYS_FLUID) {
BLO_write_struct(writer, SPHFluidSettings, part->fluid);
}
for (int a = 0; a < MAX_MTEX; a++) {
if (part->mtex[a]) {
BLO_write_struct(writer, MTex, part->mtex[a]);
}
}
}
}
static void write_particlesystems(BlendWriter *writer, ListBase *particles)
{
ParticleSystem *psys = particles->first;
ParticleTarget *pt;
int a;
for (; psys; psys = psys->next) {
BLO_write_struct(writer, ParticleSystem, psys);
if (psys->particles) {
BLO_write_struct_array(writer, ParticleData, psys->totpart, psys->particles);
if (psys->particles->hair) {
ParticleData *pa = psys->particles;
for (a = 0; a < psys->totpart; a++, pa++) {
BLO_write_struct_array(writer, HairKey, pa->totkey, pa->hair);
}
}
if (psys->particles->boid && (psys->part->phystype == PART_PHYS_BOIDS)) {
BLO_write_struct_array(writer, BoidParticle, psys->totpart, psys->particles->boid);
}
if (psys->part->fluid && (psys->part->phystype == PART_PHYS_FLUID) &&
(psys->part->fluid->flag & SPH_VISCOELASTIC_SPRINGS)) {
BLO_write_struct_array(
writer, ParticleSpring, psys->tot_fluidsprings, psys->fluid_springs);
}
}
pt = psys->targets.first;
for (; pt; pt = pt->next) {
BLO_write_struct(writer, ParticleTarget, pt);
}
if (psys->child) {
BLO_write_struct_array(writer, ChildParticle, psys->totchild, psys->child);
}
if (psys->clmd) {
BLO_write_struct(writer, ClothModifierData, psys->clmd);
BLO_write_struct(writer, ClothSimSettings, psys->clmd->sim_parms);
BLO_write_struct(writer, ClothCollSettings, psys->clmd->coll_parms);
}
write_pointcaches(writer, &psys->ptcaches);
}
}
static void write_motionpath(BlendWriter *writer, bMotionPath *mpath)
{
/* sanity checks */
if (mpath == NULL) {
return;
}
/* firstly, just write the motionpath struct */
BLO_write_struct(writer, bMotionPath, mpath);
/* now write the array of data */
BLO_write_struct_array(writer, bMotionPathVert, mpath->length, mpath->points);
}
static void write_constraints(BlendWriter *writer, ListBase *conlist)
2002-10-12 11:37:38 +00:00
{
bConstraint *con;
for (con = conlist->first; con; con = con->next) {
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
/* Write the specific data */
if (cti && con->data) {
/* firstly, just write the plain con->data struct */
BLO_write_struct_by_name(writer, cti->structName, con->data);
/* do any constraint specific stuff */
switch (con->type) {
case CONSTRAINT_TYPE_PYTHON: {
bPythonConstraint *data = con->data;
bConstraintTarget *ct;
/* write targets */
for (ct = data->targets.first; ct; ct = ct->next) {
BLO_write_struct(writer, bConstraintTarget, ct);
}
/* Write ID Properties -- and copy this comment EXACTLY for easy finding
* of library blocks that implement this.*/
IDP_WriteProperty(data->prop, writer);
break;
}
case CONSTRAINT_TYPE_ARMATURE: {
bArmatureConstraint *data = con->data;
bConstraintTarget *ct;
/* write targets */
for (ct = data->targets.first; ct; ct = ct->next) {
BLO_write_struct(writer, bConstraintTarget, ct);
}
break;
}
case CONSTRAINT_TYPE_SPLINEIK: {
bSplineIKConstraint *data = con->data;
/* write points array */
BLO_write_float_array(writer, data->numpoints, data->points);
break;
}
}
}
/* Write the constraint */
BLO_write_struct(writer, bConstraint, con);
}
2002-10-12 11:37:38 +00:00
}
static void write_pose(BlendWriter *writer, bPose *pose)
2002-10-12 11:37:38 +00:00
{
bPoseChannel *chan;
bActionGroup *grp;
/* Write each channel */
if (pose == NULL) {
return;
}
/* Write channels */
for (chan = pose->chanbase.first; chan; chan = chan->next) {
/* Write ID Properties -- and copy this comment EXACTLY for easy finding
* of library blocks that implement this.*/
if (chan->prop) {
IDP_WriteProperty(chan->prop, writer);
}
write_constraints(writer, &chan->constraints);
write_motionpath(writer, chan->mpath);
/* prevent crashes with autosave,
* when a bone duplicated in editmode has not yet been assigned to its posechannel */
if (chan->bone) {
/* gets restored on read, for library armatures */
chan->selectflag = chan->bone->flag & BONE_SELECTED;
}
BLO_write_struct(writer, bPoseChannel, chan);
}
/* Write groups */
for (grp = pose->agroups.first; grp; grp = grp->next) {
BLO_write_struct(writer, bActionGroup, grp);
}
/* write IK param */
if (pose->ikparam) {
const char *structname = BKE_pose_ikparam_get_name(pose);
if (structname) {
BLO_write_struct_by_name(writer, structname, pose->ikparam);
}
}
/* Write this pose */
BLO_write_struct(writer, bPose, pose);
2002-10-12 11:37:38 +00:00
}
static void write_defgroups(BlendWriter *writer, ListBase *defbase)
2002-10-12 11:37:38 +00:00
{
LISTBASE_FOREACH (bDeformGroup *, defgroup, defbase) {
BLO_write_struct(writer, bDeformGroup, defgroup);
}
2002-10-12 11:37:38 +00:00
}
static void write_fmaps(BlendWriter *writer, ListBase *fbase)
{
LISTBASE_FOREACH (bFaceMap *, fmap, fbase) {
BLO_write_struct(writer, bFaceMap, fmap);
}
}
static void write_modifiers(BlendWriter *writer, ListBase *modbase)
{
ModifierData *md;
if (modbase == NULL) {
return;
}
for (md = modbase->first; md; md = md->next) {
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
if (mti == NULL) {
return;
}
BLO_write_struct_by_name(writer, mti->structName, md);
if (md->type == eModifierType_Hook) {
HookModifierData *hmd = (HookModifierData *)md;
if (hmd->curfalloff) {
write_curvemapping(writer, hmd->curfalloff);
}
BLO_write_int32_array(writer, hmd->totindex, hmd->indexar);
}
else if (md->type == eModifierType_Cloth) {
ClothModifierData *clmd = (ClothModifierData *)md;
BLO_write_struct(writer, ClothSimSettings, clmd->sim_parms);
BLO_write_struct(writer, ClothCollSettings, clmd->coll_parms);
BLO_write_struct(writer, EffectorWeights, clmd->sim_parms->effector_weights);
write_pointcaches(writer, &clmd->ptcaches);
}
else if (md->type == eModifierType_Fluid) {
FluidModifierData *mmd = (FluidModifierData *)md;
if (mmd->type & MOD_FLUID_TYPE_DOMAIN) {
BLO_write_struct(writer, FluidDomainSettings, mmd->domain);
if (mmd->domain) {
write_pointcaches(writer, &(mmd->domain->ptcaches[0]));
/* create fake pointcache so that old blender versions can read it */
mmd->domain->point_cache[1] = BKE_ptcache_add(&mmd->domain->ptcaches[1]);
mmd->domain->point_cache[1]->flag |= PTCACHE_DISK_CACHE | PTCACHE_FAKE_SMOKE;
mmd->domain->point_cache[1]->step = 1;
write_pointcaches(writer, &(mmd->domain->ptcaches[1]));
if (mmd->domain->coba) {
BLO_write_struct(writer, ColorBand, mmd->domain->coba);
}
/* cleanup the fake pointcache */
BKE_ptcache_free_list(&mmd->domain->ptcaches[1]);
mmd->domain->point_cache[1] = NULL;
BLO_write_struct(writer, EffectorWeights, mmd->domain->effector_weights);
}
}
else if (mmd->type & MOD_FLUID_TYPE_FLOW) {
BLO_write_struct(writer, FluidFlowSettings, mmd->flow);
}
else if (mmd->type & MOD_FLUID_TYPE_EFFEC) {
BLO_write_struct(writer, FluidEffectorSettings, mmd->effector);
}
}
else if (md->type == eModifierType_Fluidsim) {
FluidsimModifierData *fluidmd = (FluidsimModifierData *)md;
BLO_write_struct(writer, FluidsimSettings, fluidmd->fss);
}
else if (md->type == eModifierType_DynamicPaint) {
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
if (pmd->canvas) {
DynamicPaintSurface *surface;
BLO_write_struct(writer, DynamicPaintCanvasSettings, pmd->canvas);
/* write surfaces */
for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) {
BLO_write_struct(writer, DynamicPaintSurface, surface);
}
/* write caches and effector weights */
for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) {
write_pointcaches(writer, &(surface->ptcaches));
BLO_write_struct(writer, EffectorWeights, surface->effector_weights);
}
}
if (pmd->brush) {
BLO_write_struct(writer, DynamicPaintBrushSettings, pmd->brush);
BLO_write_struct(writer, ColorBand, pmd->brush->paint_ramp);
BLO_write_struct(writer, ColorBand, pmd->brush->vel_ramp);
}
}
else if (md->type == eModifierType_Collision) {
2012-06-30 22:49:33 +00:00
#if 0
CollisionModifierData *collmd = (CollisionModifierData *)md;
// TODO: CollisionModifier should use pointcache
// + have proper reset events before enabling this
writestruct(wd, DATA, MVert, collmd->numverts, collmd->x);
writestruct(wd, DATA, MVert, collmd->numverts, collmd->xnew);
writestruct(wd, DATA, MFace, collmd->numfaces, collmd->mfaces);
2012-06-30 22:49:33 +00:00
#endif
}
else if (md->type == eModifierType_MeshDeform) {
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
int size = mmd->dyngridsize;
BLO_write_struct_array(writer, MDefInfluence, mmd->totinfluence, mmd->bindinfluences);
BLO_write_int32_array(writer, mmd->totvert + 1, mmd->bindoffsets);
BLO_write_float3_array(writer, mmd->totcagevert, mmd->bindcagecos);
BLO_write_struct_array(writer, MDefCell, size * size * size, mmd->dyngrid);
BLO_write_struct_array(writer, MDefInfluence, mmd->totinfluence, mmd->dyninfluences);
BLO_write_int32_array(writer, mmd->totvert, mmd->dynverts);
}
else if (md->type == eModifierType_Warp) {
WarpModifierData *tmd = (WarpModifierData *)md;
if (tmd->curfalloff) {
write_curvemapping(writer, tmd->curfalloff);
}
}
else if (md->type == eModifierType_WeightVGEdit) {
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *)md;
if (wmd->cmap_curve) {
write_curvemapping(writer, wmd->cmap_curve);
}
}
else if (md->type == eModifierType_LaplacianDeform) {
LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md;
BLO_write_float3_array(writer, lmd->total_verts, lmd->vertexco);
}
else if (md->type == eModifierType_CorrectiveSmooth) {
CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md;
if (csmd->bind_coords) {
BLO_write_float3_array(writer, csmd->bind_coords_num, (float *)csmd->bind_coords);
}
}
else if (md->type == eModifierType_SurfaceDeform) {
SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
BLO_write_struct_array(writer, SDefVert, smd->numverts, smd->verts);
if (smd->verts) {
for (int i = 0; i < smd->numverts; i++) {
BLO_write_struct_array(writer, SDefBind, smd->verts[i].numbinds, smd->verts[i].binds);
if (smd->verts[i].binds) {
for (int j = 0; j < smd->verts[i].numbinds; j++) {
BLO_write_uint32_array(
writer, smd->verts[i].binds[j].numverts, smd->verts[i].binds[j].vert_inds);
if (smd->verts[i].binds[j].mode == MOD_SDEF_MODE_CENTROID ||
smd->verts[i].binds[j].mode == MOD_SDEF_MODE_LOOPTRI) {
BLO_write_float3_array(writer, 1, smd->verts[i].binds[j].vert_weights);
}
else {
BLO_write_float_array(
writer, smd->verts[i].binds[j].numverts, smd->verts[i].binds[j].vert_weights);
}
}
}
}
}
}
else if (md->type == eModifierType_Bevel) {
BevelModifierData *bmd = (BevelModifierData *)md;
if (bmd->custom_profile) {
write_CurveProfile(writer, bmd->custom_profile);
}
}
}
}
static void write_gpencil_modifiers(BlendWriter *writer, ListBase *modbase)
{
GpencilModifierData *md;
if (modbase == NULL) {
return;
}
for (md = modbase->first; md; md = md->next) {
const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type);
if (mti == NULL) {
return;
}
BLO_write_struct_by_name(writer, mti->struct_name, md);
if (md->type == eGpencilModifierType_Thick) {
ThickGpencilModifierData *gpmd = (ThickGpencilModifierData *)md;
if (gpmd->curve_thickness) {
write_curvemapping(writer, gpmd->curve_thickness);
}
}
else if (md->type == eGpencilModifierType_Noise) {
NoiseGpencilModifierData *gpmd = (NoiseGpencilModifierData *)md;
if (gpmd->curve_intensity) {
write_curvemapping(writer, gpmd->curve_intensity);
}
}
else if (md->type == eGpencilModifierType_Hook) {
HookGpencilModifierData *gpmd = (HookGpencilModifierData *)md;
if (gpmd->curfalloff) {
write_curvemapping(writer, gpmd->curfalloff);
}
}
else if (md->type == eGpencilModifierType_Tint) {
TintGpencilModifierData *gpmd = (TintGpencilModifierData *)md;
if (gpmd->colorband) {
BLO_write_struct(writer, ColorBand, gpmd->colorband);
}
if (gpmd->curve_intensity) {
write_curvemapping(writer, gpmd->curve_intensity);
}
}
else if (md->type == eGpencilModifierType_Smooth) {
SmoothGpencilModifierData *gpmd = (SmoothGpencilModifierData *)md;
if (gpmd->curve_intensity) {
write_curvemapping(writer, gpmd->curve_intensity);
}
}
else if (md->type == eGpencilModifierType_Color) {
ColorGpencilModifierData *gpmd = (ColorGpencilModifierData *)md;
if (gpmd->curve_intensity) {
write_curvemapping(writer, gpmd->curve_intensity);
}
}
else if (md->type == eGpencilModifierType_Opacity) {
OpacityGpencilModifierData *gpmd = (OpacityGpencilModifierData *)md;
if (gpmd->curve_intensity) {
write_curvemapping(writer, gpmd->curve_intensity);
}
}
}
}
static void write_shaderfxs(BlendWriter *writer, ListBase *fxbase)
{
ShaderFxData *fx;
if (fxbase == NULL) {
return;
}
for (fx = fxbase->first; fx; fx = fx->next) {
const ShaderFxTypeInfo *fxi = BKE_shaderfx_get_info(fx->type);
if (fxi == NULL) {
return;
}
BLO_write_struct_by_name(writer, fxi->struct_name, fx);
}
}
static void write_object(BlendWriter *writer, Object *ob, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (ob->id.us > 0 || BLO_write_is_undo(writer)) {
2020-04-01 10:04:08 +02:00
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
BKE_object_runtime_reset(ob);
/* write LibData */
BLO_write_id_struct(writer, Object, id_address, &ob->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &ob->id);
if (ob->adt) {
write_animdata(writer, ob->adt);
}
/* direct data */
BLO_write_pointer_array(writer, ob->totcol, ob->mat);
BLO_write_raw(writer, sizeof(char) * ob->totcol, ob->matbits);
if (ob->type == OB_ARMATURE) {
bArmature *arm = ob->data;
if (arm && ob->pose && arm->act_bone) {
BLI_strncpy(
ob->pose->proxy_act_bone, arm->act_bone->name, sizeof(ob->pose->proxy_act_bone));
}
}
write_pose(writer, ob->pose);
write_defgroups(writer, &ob->defbase);
write_fmaps(writer, &ob->fmaps);
write_constraints(writer, &ob->constraints);
write_motionpath(writer, ob->mpath);
BLO_write_struct(writer, PartDeflect, ob->pd);
if (ob->soft) {
/* Set deprecated pointers to prevent crashes of older Blenders */
ob->soft->pointcache = ob->soft->shared->pointcache;
ob->soft->ptcaches = ob->soft->shared->ptcaches;
BLO_write_struct(writer, SoftBody, ob->soft);
BLO_write_struct(writer, SoftBody_Shared, ob->soft->shared);
write_pointcaches(writer, &(ob->soft->shared->ptcaches));
BLO_write_struct(writer, EffectorWeights, ob->soft->effector_weights);
}
if (ob->rigidbody_object) {
/* TODO: if any extra data is added to handle duplis, will need separate function then */
BLO_write_struct(writer, RigidBodyOb, ob->rigidbody_object);
}
if (ob->rigidbody_constraint) {
BLO_write_struct(writer, RigidBodyCon, ob->rigidbody_constraint);
}
if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
BLO_write_struct(writer, ImageUser, ob->iuser);
}
write_particlesystems(writer, &ob->particlesystem);
write_modifiers(writer, &ob->modifiers);
write_gpencil_modifiers(writer, &ob->greasepencil_modifiers);
write_shaderfxs(writer, &ob->shader_fx);
BLO_write_struct_list(writer, LinkData, &ob->pc_ids);
BLO_write_struct_list(writer, LodLevel, &ob->lodlevels);
write_previews(writer, ob->preview);
}
2002-10-12 11:37:38 +00:00
}
static void write_vfont(BlendWriter *writer, VFont *vf, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (vf->id.us > 0 || BLO_write_is_undo(writer)) {
2020-04-01 10:18:39 +02:00
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
vf->data = NULL;
vf->temp_pf = NULL;
/* write LibData */
BLO_write_id_struct(writer, VFont, id_address, &vf->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &vf->id);
/* direct data */
if (vf->packedfile) {
PackedFile *pf = vf->packedfile;
BLO_write_struct(writer, PackedFile, pf);
BLO_write_raw(writer, pf->size, pf->data);
}
}
2002-10-12 11:37:38 +00:00
}
static void write_key(BlendWriter *writer, Key *key, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (key->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Key, id_address, &key->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &key->id);
if (key->adt) {
write_animdata(writer, key->adt);
}
/* direct data */
LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
BLO_write_struct(writer, KeyBlock, kb);
if (kb->data) {
BLO_write_raw(writer, kb->totelem * key->elemsize, kb->data);
}
}
}
2002-10-12 11:37:38 +00:00
}
static void write_camera(BlendWriter *writer, Camera *cam, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (cam->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Camera, id_address, &cam->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &cam->id);
if (cam->adt) {
write_animdata(writer, cam->adt);
}
LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
BLO_write_struct(writer, CameraBGImage, bgpic);
}
}
2002-10-12 11:37:38 +00:00
}
static void write_mball(BlendWriter *writer, MetaBall *mb, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (mb->id.us > 0 || BLO_write_is_undo(writer)) {
2020-04-01 10:12:19 +02:00
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&mb->disp);
mb->editelems = NULL;
/* Must always be cleared (meta's don't have their own edit-data). */
mb->needs_flush_to_id = 0;
mb->lastelem = NULL;
mb->batch_cache = NULL;
/* write LibData */
BLO_write_id_struct(writer, MetaBall, id_address, &mb->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &mb->id);
/* direct data */
BLO_write_pointer_array(writer, mb->totcol, mb->mat);
if (mb->adt) {
write_animdata(writer, mb->adt);
}
LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
BLO_write_struct(writer, MetaElem, ml);
}
}
2002-10-12 11:37:38 +00:00
}
static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (cu->id.us > 0 || BLO_write_is_undo(writer)) {
2020-04-01 10:04:08 +02:00
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
2020-04-01 09:56:29 +02:00
cu->editnurb = NULL;
cu->editfont = NULL;
cu->batch_cache = NULL;
/* write LibData */
BLO_write_id_struct(writer, Curve, id_address, &cu->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &cu->id);
/* direct data */
BLO_write_pointer_array(writer, cu->totcol, cu->mat);
if (cu->adt) {
write_animdata(writer, cu->adt);
}
if (cu->vfont) {
BLO_write_raw(writer, cu->len + 1, cu->str);
BLO_write_struct_array(writer, CharInfo, cu->len_wchar + 1, cu->strinfo);
BLO_write_struct_array(writer, TextBox, cu->totbox, cu->tb);
}
else {
/* is also the order of reading */
LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
BLO_write_struct(writer, Nurb, nu);
}
LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
if (nu->type == CU_BEZIER) {
BLO_write_struct_array(writer, BezTriple, nu->pntsu, nu->bezt);
}
else {
BLO_write_struct_array(writer, BPoint, nu->pntsu * nu->pntsv, nu->bp);
if (nu->knotsu) {
BLO_write_float_array(writer, KNOTSU(nu), nu->knotsu);
}
if (nu->knotsv) {
BLO_write_float_array(writer, KNOTSV(nu), nu->knotsv);
}
}
}
}
}
2002-10-12 11:37:38 +00:00
}
static void write_dverts(BlendWriter *writer, int count, MDeformVert *dvlist)
2002-10-12 11:37:38 +00:00
{
if (dvlist) {
/* Write the dvert list */
BLO_write_struct_array(writer, MDeformVert, count, dvlist);
/* Write deformation data for each dvert */
for (int i = 0; i < count; i++) {
if (dvlist[i].dw) {
BLO_write_struct_array(writer, MDeformWeight, dvlist[i].totweight, dvlist[i].dw);
}
}
}
2002-10-12 11:37:38 +00:00
}
static void write_mdisps(BlendWriter *writer, int count, MDisps *mdlist, int external)
{
if (mdlist) {
int i;
BLO_write_struct_array(writer, MDisps, count, mdlist);
for (i = 0; i < count; i++) {
MDisps *md = &mdlist[i];
if (md->disps) {
if (!external) {
2020-06-06 00:05:33 +10:00
BLO_write_float3_array(writer, md->totdisp, &md->disps[0][0]);
}
}
if (md->hidden) {
BLO_write_raw(writer, BLI_BITMAP_SIZE(md->totdisp), md->hidden);
}
}
}
}
static void write_grid_paint_mask(BlendWriter *writer, int count, GridPaintMask *grid_paint_mask)
{
if (grid_paint_mask) {
int i;
BLO_write_struct_array(writer, GridPaintMask, count, grid_paint_mask);
for (i = 0; i < count; i++) {
GridPaintMask *gpm = &grid_paint_mask[i];
if (gpm->data) {
const int gridsize = BKE_ccg_gridsize(gpm->level);
BLO_write_raw(writer, sizeof(*gpm->data) * gridsize * gridsize, gpm->data);
}
}
}
}
static void write_customdata(BlendWriter *writer,
ID *id,
int count,
CustomData *data,
CustomDataLayer *layers,
CustomDataMask cddata_mask)
Added custom vertex/edge/face data for meshes: All data layers, including MVert/MEdge/MFace, are now managed as custom data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are still used of course, but allocating, copying or freeing these arrays should be done through the CustomData API. Work in progress documentation on this is here: http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData Replaced TFace by MTFace: This is the same struct, except that it does not contain color, that now always stays separated in MCol. This was not a good design decision to begin with, and it is needed for adding multiple color layers later. Note that this does mean older Blender versions will not be able to read UV coordinates from the next release, due to an SDNA limitation. Removed DispListMesh: This now fully replaced by DerivedMesh. To provide access to arrays of vertices, edges and faces, like DispListMesh does. The semantics of the DerivedMesh.getVertArray() and similar functions were changed to return a pointer to an array if one exists, or otherwise allocate a temporary one. On releasing the DerivedMesh, this temporary array will be removed automatically. Removed ssDM and meshDM DerivedMesh backends: The ssDM backend was for DispListMesh, so that became obsolete automatically. The meshDM backend was replaced by the custom data backend, that now figures out which layers need to be modified, and only duplicates those. This changes code in many places, and overall removes 2514 lines of code. So, there's a good chance this might break some stuff, although I've been testing it for a few days now. The good news is, adding multiple color and uv layers should now become easy.
2006-11-20 04:28:02 +00:00
{
int i;
/* write external customdata (not for undo) */
if (data->external && !BLO_write_is_undo(writer)) {
CustomData_external_write(data, id, cddata_mask, count, 0);
}
BLO_write_struct_array_at_address(writer, CustomDataLayer, data->totlayer, data->layers, layers);
for (i = 0; i < data->totlayer; i++) {
CustomDataLayer *layer = &layers[i];
const char *structname;
int structnum, datasize;
if (layer->type == CD_MDEFORMVERT) {
/* layer types that allocate own memory need special handling */
write_dverts(writer, count, layer->data);
}
else if (layer->type == CD_MDISPS) {
write_mdisps(writer, count, layer->data, layer->flag & CD_FLAG_EXTERNAL);
}
else if (layer->type == CD_PAINT_MASK) {
const float *layer_data = layer->data;
BLO_write_raw(writer, sizeof(*layer_data) * count, layer_data);
}
2020-03-05 14:53:23 +01:00
else if (layer->type == CD_SCULPT_FACE_SETS) {
const float *layer_data = layer->data;
BLO_write_raw(writer, sizeof(*layer_data) * count, layer_data);
2020-03-05 14:53:23 +01:00
}
else if (layer->type == CD_GRID_PAINT_MASK) {
write_grid_paint_mask(writer, count, layer->data);
}
else if (layer->type == CD_FACEMAP) {
const int *layer_data = layer->data;
BLO_write_raw(writer, sizeof(*layer_data) * count, layer_data);
}
else {
CustomData_file_write_info(layer->type, &structname, &structnum);
if (structnum) {
datasize = structnum * count;
BLO_write_struct_array_by_name(writer, structname, datasize, layer->data);
}
else if (!BLO_write_is_undo(writer)) { /* Do not warn on undo. */
printf("%s error: layer '%s':%d - can't be written to file\n",
__func__,
structname,
layer->type);
}
}
}
if (data->external) {
BLO_write_struct(writer, CustomDataExternal, data->external);
}
Added custom vertex/edge/face data for meshes: All data layers, including MVert/MEdge/MFace, are now managed as custom data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are still used of course, but allocating, copying or freeing these arrays should be done through the CustomData API. Work in progress documentation on this is here: http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData Replaced TFace by MTFace: This is the same struct, except that it does not contain color, that now always stays separated in MCol. This was not a good design decision to begin with, and it is needed for adding multiple color layers later. Note that this does mean older Blender versions will not be able to read UV coordinates from the next release, due to an SDNA limitation. Removed DispListMesh: This now fully replaced by DerivedMesh. To provide access to arrays of vertices, edges and faces, like DispListMesh does. The semantics of the DerivedMesh.getVertArray() and similar functions were changed to return a pointer to an array if one exists, or otherwise allocate a temporary one. On releasing the DerivedMesh, this temporary array will be removed automatically. Removed ssDM and meshDM DerivedMesh backends: The ssDM backend was for DispListMesh, so that became obsolete automatically. The meshDM backend was replaced by the custom data backend, that now figures out which layers need to be modified, and only duplicates those. This changes code in many places, and overall removes 2514 lines of code. So, there's a good chance this might break some stuff, although I've been testing it for a few days now. The good news is, adding multiple color and uv layers should now become easy.
2006-11-20 04:28:02 +00:00
}
static void write_mesh(BlendWriter *writer, Mesh *mesh, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (mesh->id.us > 0 || BLO_write_is_undo(writer)) {
/* cache only - don't write */
mesh->mface = NULL;
mesh->totface = 0;
memset(&mesh->fdata, 0, sizeof(mesh->fdata));
memset(&mesh->runtime, 0, sizeof(mesh->runtime));
/* Reduce xdata layers, fill xlayers with layers to be written.
* This makes xdata invalid for Blender, which is why we made a
* temporary local copy. */
CustomDataLayer *vlayers = NULL, vlayers_buff[CD_TEMP_CHUNK_SIZE];
CustomDataLayer *elayers = NULL, elayers_buff[CD_TEMP_CHUNK_SIZE];
CustomDataLayer *flayers = NULL, flayers_buff[CD_TEMP_CHUNK_SIZE];
CustomDataLayer *llayers = NULL, llayers_buff[CD_TEMP_CHUNK_SIZE];
CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
CustomData_file_write_prepare(&mesh->vdata, &vlayers, vlayers_buff, ARRAY_SIZE(vlayers_buff));
CustomData_file_write_prepare(&mesh->edata, &elayers, elayers_buff, ARRAY_SIZE(elayers_buff));
flayers = flayers_buff;
CustomData_file_write_prepare(&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff));
CustomData_file_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
BLO_write_id_struct(writer, Mesh, id_address, &mesh->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &mesh->id);
/* direct data */
if (mesh->adt) {
write_animdata(writer, mesh->adt);
}
BLO_write_pointer_array(writer, mesh->totcol, mesh->mat);
BLO_write_raw(writer, sizeof(MSelect) * mesh->totselect, mesh->mselect);
write_customdata(writer, &mesh->id, mesh->totvert, &mesh->vdata, vlayers, CD_MASK_MESH.vmask);
write_customdata(writer, &mesh->id, mesh->totedge, &mesh->edata, elayers, CD_MASK_MESH.emask);
/* fdata is really a dummy - written so slots align */
write_customdata(writer, &mesh->id, mesh->totface, &mesh->fdata, flayers, CD_MASK_MESH.fmask);
write_customdata(writer, &mesh->id, mesh->totloop, &mesh->ldata, llayers, CD_MASK_MESH.lmask);
write_customdata(writer, &mesh->id, mesh->totpoly, &mesh->pdata, players, CD_MASK_MESH.pmask);
/* free temporary data */
if (vlayers && vlayers != vlayers_buff) {
MEM_freeN(vlayers);
}
if (elayers && elayers != elayers_buff) {
MEM_freeN(elayers);
}
if (flayers && flayers != flayers_buff) {
MEM_freeN(flayers);
}
if (llayers && llayers != llayers_buff) {
MEM_freeN(llayers);
}
if (players && players != players_buff) {
MEM_freeN(players);
}
}
2002-10-12 11:37:38 +00:00
}
static void write_lattice(BlendWriter *writer, Lattice *lt, const void *id_address)
{
if (lt->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
lt->editlatt = NULL;
lt->batch_cache = NULL;
/* write LibData */
BLO_write_id_struct(writer, Lattice, id_address, &lt->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &lt->id);
/* write animdata */
if (lt->adt) {
write_animdata(writer, lt->adt);
}
/* direct data */
BLO_write_struct_array(writer, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def);
write_dverts(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
}
}
static void write_image(BlendWriter *writer, Image *ima, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (ima->id.us > 0 || BLO_write_is_undo(writer)) {
ImagePackedFile *imapf;
/* Some trickery to keep forward compatibility of packed images. */
BLI_assert(ima->packedfile == NULL);
if (ima->packedfiles.first != NULL) {
imapf = ima->packedfiles.first;
ima->packedfile = imapf->packedfile;
}
/* write LibData */
BLO_write_id_struct(writer, Image, id_address, &ima->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &ima->id);
for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
BLO_write_struct(writer, ImagePackedFile, imapf);
if (imapf->packedfile) {
PackedFile *pf = imapf->packedfile;
BLO_write_struct(writer, PackedFile, pf);
BLO_write_raw(writer, pf->size, pf->data);
}
}
write_previews(writer, ima->preview);
LISTBASE_FOREACH (ImageView *, iv, &ima->views) {
BLO_write_struct(writer, ImageView, iv);
}
BLO_write_struct(writer, Stereo3dFormat, ima->stereo3d_format);
BLO_write_struct_list(writer, ImageTile, &ima->tiles);
Add support for tiled images and the UDIM naming scheme This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender. With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser. Therefore, code that is not yet aware of tiles will just access the default tile as usual. The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9. Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator. The following features are supported so far: - Automatic detection and loading of all tiles when opening the first tile (1001) - Saving all tiles - Adding and removing tiles - Filling tiles with generated images - Drawing all tiles in the Image Editor - Viewing a tiled grid even if no image is selected - Rendering tiled images in Eevee - Rendering tiled images in Cycles (in SVM mode) - Automatically skipping loading of unused tiles in Cycles - 2D texture painting (also across tiles) - 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders) - Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID) - Different resolutions between tiles There still are some missing features that will be added later (see T72390): - Workbench engine support - Packing/Unpacking support - Baking support - Cycles OSL support - many other Blender features that rely on images Thanks to Brecht for the review and to all who tested the intermediate versions! Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
ima->packedfile = NULL;
BLO_write_struct_list(writer, RenderSlot, &ima->renderslots);
}
2002-10-12 11:37:38 +00:00
}
static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Tex, id_address, &tex->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &tex->id);
if (tex->adt) {
write_animdata(writer, tex->adt);
}
/* direct data */
if (tex->coba) {
BLO_write_struct(writer, ColorBand, tex->coba);
}
/* nodetree is integral part of texture, no libdata */
if (tex->nodetree) {
BLO_write_struct(writer, bNodeTree, tex->nodetree);
write_nodetree_nolib(writer, tex->nodetree);
}
write_previews(writer, tex->preview);
}
2002-10-12 11:37:38 +00:00
}
static void write_material(BlendWriter *writer, Material *ma, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (ma->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
ma->texpaintslot = NULL;
BLI_listbase_clear(&ma->gpumaterial);
/* write LibData */
BLO_write_id_struct(writer, Material, id_address, &ma->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &ma->id);
if (ma->adt) {
write_animdata(writer, ma->adt);
}
/* nodetree is integral part of material, no libdata */
if (ma->nodetree) {
BLO_write_struct(writer, bNodeTree, ma->nodetree);
write_nodetree_nolib(writer, ma->nodetree);
}
write_previews(writer, ma->preview);
/* grease pencil settings */
if (ma->gp_style) {
BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style);
}
}
2002-10-12 11:37:38 +00:00
}
static void write_world(BlendWriter *writer, World *wrld, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (wrld->id.us > 0 || BLO_write_is_undo(writer)) {
2020-04-01 11:30:30 +02:00
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&wrld->gpumaterial);
/* write LibData */
BLO_write_id_struct(writer, World, id_address, &wrld->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &wrld->id);
if (wrld->adt) {
write_animdata(writer, wrld->adt);
}
/* nodetree is integral part of world, no libdata */
if (wrld->nodetree) {
BLO_write_struct(writer, bNodeTree, wrld->nodetree);
write_nodetree_nolib(writer, wrld->nodetree);
}
write_previews(writer, wrld->preview);
}
2002-10-12 11:37:38 +00:00
}
static void write_light(BlendWriter *writer, Light *la, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (la->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Light, id_address, &la->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &la->id);
if (la->adt) {
write_animdata(writer, la->adt);
}
if (la->curfalloff) {
write_curvemapping(writer, la->curfalloff);
}
/* Node-tree is integral part of lights, no libdata. */
if (la->nodetree) {
BLO_write_struct(writer, bNodeTree, la->nodetree);
write_nodetree_nolib(writer, la->nodetree);
}
write_previews(writer, la->preview);
}
2002-10-12 11:37:38 +00:00
}
static void write_collection_nolib(BlendWriter *writer, Collection *collection)
Collections and groups unification OVERVIEW * In 2.7 terminology, all layers and groups are now collection datablocks. * These collections are nestable, linkable, instanceable, overrideable, .. which opens up new ways to set up scenes and link + override data. * Viewport/render visibility and selectability are now a part of the collection and shared across all view layers and linkable. * View layers define which subset of the scene collection hierarchy is excluded for each. For many workflows one view layer can be used, these are more of an advanced feature now. OUTLINER * The outliner now has a "View Layer" display mode instead of "Collections", which can display the collections and/or objects in the view layer. * In this display mode, collections can be excluded with the right click menu. These will then be greyed out and their objects will be excluded. * To view collections not linked to any scene, the "Blender File" display mode can be used, with the new filtering option to just see Colleciton datablocks. * The outliner right click menus for collections and objects were reorganized. * Drag and drop still needs to be improved. Like before, dragging the icon or text gives different results, we'll unify this later. LINKING AND OVERRIDES * Collections can now be linked into the scene without creating an instance, with the link/append operator or from the collections view in the outliner. * Collections can get static overrides with the right click menu in the outliner, but this is rather unreliable and not clearly communicated at the moment. * We still need to improve the make override operator to turn collection instances into collections with overrides directly in the scene. PERFORMANCE * We tried to make performance not worse than before and improve it in some cases. The main thing that's still a bit slower is multiple scenes, we have to change the layer syncing to only updated affected scenes. * Collections keep a list of their parent collections for faster incremental updates in syncing and caching. * View layer bases are now in a object -> base hash to avoid quadratic time lookups internally and in API functions like visible_get(). VERSIONING * Compatibility with 2.7 files should be improved due to the new visibility controls. Of course users may not want to set up their scenes differently now to avoid having separate layers and groups. * Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero files. There's a few things which are know to be not quite compatible, like nested layer collections inside groups. * The versioning code for 2.8 files is quite complicated, and isolated behind #ifdef so it can be removed at the end of the release cycle. KNOWN ISSUES * The G-key group operators in the 3D viewport were left mostly as is, they need to be modified still to fit better. * Same for the groups panel in the object properties. This needs to be updated still, or perhaps replaced by something better. * Collections must all have a unique name. Less restrictive namespacing is to be done later, we'll have to see how important this is as all objects within the collections must also have a unique name anyway. * Full scene copy and delete scene are exactly doing the right thing yet. Differential Revision: https://developer.blender.org/D3383 https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
{
2019-06-12 09:04:10 +10:00
/* Shared function for collection data-blocks and scene master collection. */
write_previews(writer, collection->preview);
Collections and groups unification OVERVIEW * In 2.7 terminology, all layers and groups are now collection datablocks. * These collections are nestable, linkable, instanceable, overrideable, .. which opens up new ways to set up scenes and link + override data. * Viewport/render visibility and selectability are now a part of the collection and shared across all view layers and linkable. * View layers define which subset of the scene collection hierarchy is excluded for each. For many workflows one view layer can be used, these are more of an advanced feature now. OUTLINER * The outliner now has a "View Layer" display mode instead of "Collections", which can display the collections and/or objects in the view layer. * In this display mode, collections can be excluded with the right click menu. These will then be greyed out and their objects will be excluded. * To view collections not linked to any scene, the "Blender File" display mode can be used, with the new filtering option to just see Colleciton datablocks. * The outliner right click menus for collections and objects were reorganized. * Drag and drop still needs to be improved. Like before, dragging the icon or text gives different results, we'll unify this later. LINKING AND OVERRIDES * Collections can now be linked into the scene without creating an instance, with the link/append operator or from the collections view in the outliner. * Collections can get static overrides with the right click menu in the outliner, but this is rather unreliable and not clearly communicated at the moment. * We still need to improve the make override operator to turn collection instances into collections with overrides directly in the scene. PERFORMANCE * We tried to make performance not worse than before and improve it in some cases. The main thing that's still a bit slower is multiple scenes, we have to change the layer syncing to only updated affected scenes. * Collections keep a list of their parent collections for faster incremental updates in syncing and caching. * View layer bases are now in a object -> base hash to avoid quadratic time lookups internally and in API functions like visible_get(). VERSIONING * Compatibility with 2.7 files should be improved due to the new visibility controls. Of course users may not want to set up their scenes differently now to avoid having separate layers and groups. * Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero files. There's a few things which are know to be not quite compatible, like nested layer collections inside groups. * The versioning code for 2.8 files is quite complicated, and isolated behind #ifdef so it can be removed at the end of the release cycle. KNOWN ISSUES * The G-key group operators in the 3D viewport were left mostly as is, they need to be modified still to fit better. * Same for the groups panel in the object properties. This needs to be updated still, or perhaps replaced by something better. * Collections must all have a unique name. Less restrictive namespacing is to be done later, we'll have to see how important this is as all objects within the collections must also have a unique name anyway. * Full scene copy and delete scene are exactly doing the right thing yet. Differential Revision: https://developer.blender.org/D3383 https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
BLO_write_struct(writer, CollectionObject, cob);
}
Collections and groups unification OVERVIEW * In 2.7 terminology, all layers and groups are now collection datablocks. * These collections are nestable, linkable, instanceable, overrideable, .. which opens up new ways to set up scenes and link + override data. * Viewport/render visibility and selectability are now a part of the collection and shared across all view layers and linkable. * View layers define which subset of the scene collection hierarchy is excluded for each. For many workflows one view layer can be used, these are more of an advanced feature now. OUTLINER * The outliner now has a "View Layer" display mode instead of "Collections", which can display the collections and/or objects in the view layer. * In this display mode, collections can be excluded with the right click menu. These will then be greyed out and their objects will be excluded. * To view collections not linked to any scene, the "Blender File" display mode can be used, with the new filtering option to just see Colleciton datablocks. * The outliner right click menus for collections and objects were reorganized. * Drag and drop still needs to be improved. Like before, dragging the icon or text gives different results, we'll unify this later. LINKING AND OVERRIDES * Collections can now be linked into the scene without creating an instance, with the link/append operator or from the collections view in the outliner. * Collections can get static overrides with the right click menu in the outliner, but this is rather unreliable and not clearly communicated at the moment. * We still need to improve the make override operator to turn collection instances into collections with overrides directly in the scene. PERFORMANCE * We tried to make performance not worse than before and improve it in some cases. The main thing that's still a bit slower is multiple scenes, we have to change the layer syncing to only updated affected scenes. * Collections keep a list of their parent collections for faster incremental updates in syncing and caching. * View layer bases are now in a object -> base hash to avoid quadratic time lookups internally and in API functions like visible_get(). VERSIONING * Compatibility with 2.7 files should be improved due to the new visibility controls. Of course users may not want to set up their scenes differently now to avoid having separate layers and groups. * Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero files. There's a few things which are know to be not quite compatible, like nested layer collections inside groups. * The versioning code for 2.8 files is quite complicated, and isolated behind #ifdef so it can be removed at the end of the release cycle. KNOWN ISSUES * The G-key group operators in the 3D viewport were left mostly as is, they need to be modified still to fit better. * Same for the groups panel in the object properties. This needs to be updated still, or perhaps replaced by something better. * Collections must all have a unique name. Less restrictive namespacing is to be done later, we'll have to see how important this is as all objects within the collections must also have a unique name anyway. * Full scene copy and delete scene are exactly doing the right thing yet. Differential Revision: https://developer.blender.org/D3383 https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
BLO_write_struct(writer, CollectionChild, child);
}
Collections and groups unification OVERVIEW * In 2.7 terminology, all layers and groups are now collection datablocks. * These collections are nestable, linkable, instanceable, overrideable, .. which opens up new ways to set up scenes and link + override data. * Viewport/render visibility and selectability are now a part of the collection and shared across all view layers and linkable. * View layers define which subset of the scene collection hierarchy is excluded for each. For many workflows one view layer can be used, these are more of an advanced feature now. OUTLINER * The outliner now has a "View Layer" display mode instead of "Collections", which can display the collections and/or objects in the view layer. * In this display mode, collections can be excluded with the right click menu. These will then be greyed out and their objects will be excluded. * To view collections not linked to any scene, the "Blender File" display mode can be used, with the new filtering option to just see Colleciton datablocks. * The outliner right click menus for collections and objects were reorganized. * Drag and drop still needs to be improved. Like before, dragging the icon or text gives different results, we'll unify this later. LINKING AND OVERRIDES * Collections can now be linked into the scene without creating an instance, with the link/append operator or from the collections view in the outliner. * Collections can get static overrides with the right click menu in the outliner, but this is rather unreliable and not clearly communicated at the moment. * We still need to improve the make override operator to turn collection instances into collections with overrides directly in the scene. PERFORMANCE * We tried to make performance not worse than before and improve it in some cases. The main thing that's still a bit slower is multiple scenes, we have to change the layer syncing to only updated affected scenes. * Collections keep a list of their parent collections for faster incremental updates in syncing and caching. * View layer bases are now in a object -> base hash to avoid quadratic time lookups internally and in API functions like visible_get(). VERSIONING * Compatibility with 2.7 files should be improved due to the new visibility controls. Of course users may not want to set up their scenes differently now to avoid having separate layers and groups. * Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero files. There's a few things which are know to be not quite compatible, like nested layer collections inside groups. * The versioning code for 2.8 files is quite complicated, and isolated behind #ifdef so it can be removed at the end of the release cycle. KNOWN ISSUES * The G-key group operators in the 3D viewport were left mostly as is, they need to be modified still to fit better. * Same for the groups panel in the object properties. This needs to be updated still, or perhaps replaced by something better. * Collections must all have a unique name. Less restrictive namespacing is to be done later, we'll have to see how important this is as all objects within the collections must also have a unique name anyway. * Full scene copy and delete scene are exactly doing the right thing yet. Differential Revision: https://developer.blender.org/D3383 https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
}
static void write_collection(BlendWriter *writer, Collection *collection, const void *id_address)
Collections and groups unification OVERVIEW * In 2.7 terminology, all layers and groups are now collection datablocks. * These collections are nestable, linkable, instanceable, overrideable, .. which opens up new ways to set up scenes and link + override data. * Viewport/render visibility and selectability are now a part of the collection and shared across all view layers and linkable. * View layers define which subset of the scene collection hierarchy is excluded for each. For many workflows one view layer can be used, these are more of an advanced feature now. OUTLINER * The outliner now has a "View Layer" display mode instead of "Collections", which can display the collections and/or objects in the view layer. * In this display mode, collections can be excluded with the right click menu. These will then be greyed out and their objects will be excluded. * To view collections not linked to any scene, the "Blender File" display mode can be used, with the new filtering option to just see Colleciton datablocks. * The outliner right click menus for collections and objects were reorganized. * Drag and drop still needs to be improved. Like before, dragging the icon or text gives different results, we'll unify this later. LINKING AND OVERRIDES * Collections can now be linked into the scene without creating an instance, with the link/append operator or from the collections view in the outliner. * Collections can get static overrides with the right click menu in the outliner, but this is rather unreliable and not clearly communicated at the moment. * We still need to improve the make override operator to turn collection instances into collections with overrides directly in the scene. PERFORMANCE * We tried to make performance not worse than before and improve it in some cases. The main thing that's still a bit slower is multiple scenes, we have to change the layer syncing to only updated affected scenes. * Collections keep a list of their parent collections for faster incremental updates in syncing and caching. * View layer bases are now in a object -> base hash to avoid quadratic time lookups internally and in API functions like visible_get(). VERSIONING * Compatibility with 2.7 files should be improved due to the new visibility controls. Of course users may not want to set up their scenes differently now to avoid having separate layers and groups. * Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero files. There's a few things which are know to be not quite compatible, like nested layer collections inside groups. * The versioning code for 2.8 files is quite complicated, and isolated behind #ifdef so it can be removed at the end of the release cycle. KNOWN ISSUES * The G-key group operators in the 3D viewport were left mostly as is, they need to be modified still to fit better. * Same for the groups panel in the object properties. This needs to be updated still, or perhaps replaced by something better. * Collections must all have a unique name. Less restrictive namespacing is to be done later, we'll have to see how important this is as all objects within the collections must also have a unique name anyway. * Full scene copy and delete scene are exactly doing the right thing yet. Differential Revision: https://developer.blender.org/D3383 https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
{
if (collection->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
collection->tag = 0;
BLI_listbase_clear(&collection->object_cache);
BLI_listbase_clear(&collection->parents);
/* write LibData */
BLO_write_id_struct(writer, Collection, id_address, &collection->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &collection->id);
Collections and groups unification OVERVIEW * In 2.7 terminology, all layers and groups are now collection datablocks. * These collections are nestable, linkable, instanceable, overrideable, .. which opens up new ways to set up scenes and link + override data. * Viewport/render visibility and selectability are now a part of the collection and shared across all view layers and linkable. * View layers define which subset of the scene collection hierarchy is excluded for each. For many workflows one view layer can be used, these are more of an advanced feature now. OUTLINER * The outliner now has a "View Layer" display mode instead of "Collections", which can display the collections and/or objects in the view layer. * In this display mode, collections can be excluded with the right click menu. These will then be greyed out and their objects will be excluded. * To view collections not linked to any scene, the "Blender File" display mode can be used, with the new filtering option to just see Colleciton datablocks. * The outliner right click menus for collections and objects were reorganized. * Drag and drop still needs to be improved. Like before, dragging the icon or text gives different results, we'll unify this later. LINKING AND OVERRIDES * Collections can now be linked into the scene without creating an instance, with the link/append operator or from the collections view in the outliner. * Collections can get static overrides with the right click menu in the outliner, but this is rather unreliable and not clearly communicated at the moment. * We still need to improve the make override operator to turn collection instances into collections with overrides directly in the scene. PERFORMANCE * We tried to make performance not worse than before and improve it in some cases. The main thing that's still a bit slower is multiple scenes, we have to change the layer syncing to only updated affected scenes. * Collections keep a list of their parent collections for faster incremental updates in syncing and caching. * View layer bases are now in a object -> base hash to avoid quadratic time lookups internally and in API functions like visible_get(). VERSIONING * Compatibility with 2.7 files should be improved due to the new visibility controls. Of course users may not want to set up their scenes differently now to avoid having separate layers and groups. * Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero files. There's a few things which are know to be not quite compatible, like nested layer collections inside groups. * The versioning code for 2.8 files is quite complicated, and isolated behind #ifdef so it can be removed at the end of the release cycle. KNOWN ISSUES * The G-key group operators in the 3D viewport were left mostly as is, they need to be modified still to fit better. * Same for the groups panel in the object properties. This needs to be updated still, or perhaps replaced by something better. * Collections must all have a unique name. Less restrictive namespacing is to be done later, we'll have to see how important this is as all objects within the collections must also have a unique name anyway. * Full scene copy and delete scene are exactly doing the right thing yet. Differential Revision: https://developer.blender.org/D3383 https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
write_collection_nolib(writer, collection);
}
Collections and groups unification OVERVIEW * In 2.7 terminology, all layers and groups are now collection datablocks. * These collections are nestable, linkable, instanceable, overrideable, .. which opens up new ways to set up scenes and link + override data. * Viewport/render visibility and selectability are now a part of the collection and shared across all view layers and linkable. * View layers define which subset of the scene collection hierarchy is excluded for each. For many workflows one view layer can be used, these are more of an advanced feature now. OUTLINER * The outliner now has a "View Layer" display mode instead of "Collections", which can display the collections and/or objects in the view layer. * In this display mode, collections can be excluded with the right click menu. These will then be greyed out and their objects will be excluded. * To view collections not linked to any scene, the "Blender File" display mode can be used, with the new filtering option to just see Colleciton datablocks. * The outliner right click menus for collections and objects were reorganized. * Drag and drop still needs to be improved. Like before, dragging the icon or text gives different results, we'll unify this later. LINKING AND OVERRIDES * Collections can now be linked into the scene without creating an instance, with the link/append operator or from the collections view in the outliner. * Collections can get static overrides with the right click menu in the outliner, but this is rather unreliable and not clearly communicated at the moment. * We still need to improve the make override operator to turn collection instances into collections with overrides directly in the scene. PERFORMANCE * We tried to make performance not worse than before and improve it in some cases. The main thing that's still a bit slower is multiple scenes, we have to change the layer syncing to only updated affected scenes. * Collections keep a list of their parent collections for faster incremental updates in syncing and caching. * View layer bases are now in a object -> base hash to avoid quadratic time lookups internally and in API functions like visible_get(). VERSIONING * Compatibility with 2.7 files should be improved due to the new visibility controls. Of course users may not want to set up their scenes differently now to avoid having separate layers and groups. * Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero files. There's a few things which are know to be not quite compatible, like nested layer collections inside groups. * The versioning code for 2.8 files is quite complicated, and isolated behind #ifdef so it can be removed at the end of the release cycle. KNOWN ISSUES * The G-key group operators in the 3D viewport were left mostly as is, they need to be modified still to fit better. * Same for the groups panel in the object properties. This needs to be updated still, or perhaps replaced by something better. * Collections must all have a unique name. Less restrictive namespacing is to be done later, we'll have to see how important this is as all objects within the collections must also have a unique name anyway. * Full scene copy and delete scene are exactly doing the right thing yet. Differential Revision: https://developer.blender.org/D3383 https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
}
static void write_sequence_modifiers(BlendWriter *writer, ListBase *modbase)
{
SequenceModifierData *smd;
for (smd = modbase->first; smd; smd = smd->next) {
const SequenceModifierTypeInfo *smti = BKE_sequence_modifier_type_info_get(smd->type);
if (smti) {
BLO_write_struct_by_name(writer, smti->struct_name, smd);
if (smd->type == seqModifierType_Curves) {
CurvesModifierData *cmd = (CurvesModifierData *)smd;
write_curvemapping(writer, &cmd->curve_mapping);
}
else if (smd->type == seqModifierType_HueCorrect) {
HueCorrectModifierData *hcmd = (HueCorrectModifierData *)smd;
write_curvemapping(writer, &hcmd->curve_mapping);
}
}
else {
BLO_write_struct(writer, SequenceModifierData, smd);
}
}
}
2002-10-12 11:37:38 +00:00
static void write_view_settings(BlendWriter *writer, ColorManagedViewSettings *view_settings)
Color Management, Stage 2: Switch color pipeline to use OpenColorIO Replace old color pipeline which was supporting linear/sRGB color spaces only with OpenColorIO-based pipeline. This introduces two configurable color spaces: - Input color space for images and movie clips. This space is used to convert images/movies from color space in which file is saved to Blender's linear space (for float images, byte images are not internally converted, only input space is stored for such images and used later). This setting could be found in image/clip data block settings. - Display color space which defines space in which particular display is working. This settings could be found in scene's Color Management panel. When render result is being displayed on the screen, apart from converting image to display space, some additional conversions could happen. This conversions are: - View, which defines tone curve applying before display transformation. These are different ways to view the image on the same display device. For example it could be used to emulate film view on sRGB display. - Exposure affects on image exposure before tone map is applied. - Gamma is post-display gamma correction, could be used to match particular display gamma. - RGB curves are user-defined curves which are applying before display transformation, could be used for different purposes. All this settings by default are only applying on render result and does not affect on other images. If some particular image needs to be affected by this transformation, "View as Render" setting of image data block should be set to truth. Movie clips are always affected by all display transformations. This commit also introduces configurable color space in which sequencer is working. This setting could be found in scene's Color Management panel and it should be used if such stuff as grading needs to be done in color space different from sRGB (i.e. when Film view on sRGB display is use, using VD16 space as sequencer's internal space would make grading working in space which is close to the space using for display). Some technical notes: - Image buffer's float buffer is now always in linear space, even if it was created from 16bit byte images. - Space of byte buffer is stored in image buffer's rect_colorspace property. - Profile of image buffer was removed since it's not longer meaningful. - OpenGL and GLSL is supposed to always work in sRGB space. It is possible to support other spaces, but it's quite large project which isn't so much important. - Legacy Color Management option disabled is emulated by using None display. It could have some regressions, but there's no clear way to avoid them. - If OpenColorIO is disabled on build time, it should make blender behaving in the same way as previous release with color management enabled. More details could be found at this page (more details would be added soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management -- Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO integration and to Brecht van Lommel for some further development and code/ usecase review!
2012-09-15 10:05:07 +00:00
{
if (view_settings->curve_mapping) {
write_curvemapping(writer, view_settings->curve_mapping);
}
Color Management, Stage 2: Switch color pipeline to use OpenColorIO Replace old color pipeline which was supporting linear/sRGB color spaces only with OpenColorIO-based pipeline. This introduces two configurable color spaces: - Input color space for images and movie clips. This space is used to convert images/movies from color space in which file is saved to Blender's linear space (for float images, byte images are not internally converted, only input space is stored for such images and used later). This setting could be found in image/clip data block settings. - Display color space which defines space in which particular display is working. This settings could be found in scene's Color Management panel. When render result is being displayed on the screen, apart from converting image to display space, some additional conversions could happen. This conversions are: - View, which defines tone curve applying before display transformation. These are different ways to view the image on the same display device. For example it could be used to emulate film view on sRGB display. - Exposure affects on image exposure before tone map is applied. - Gamma is post-display gamma correction, could be used to match particular display gamma. - RGB curves are user-defined curves which are applying before display transformation, could be used for different purposes. All this settings by default are only applying on render result and does not affect on other images. If some particular image needs to be affected by this transformation, "View as Render" setting of image data block should be set to truth. Movie clips are always affected by all display transformations. This commit also introduces configurable color space in which sequencer is working. This setting could be found in scene's Color Management panel and it should be used if such stuff as grading needs to be done in color space different from sRGB (i.e. when Film view on sRGB display is use, using VD16 space as sequencer's internal space would make grading working in space which is close to the space using for display). Some technical notes: - Image buffer's float buffer is now always in linear space, even if it was created from 16bit byte images. - Space of byte buffer is stored in image buffer's rect_colorspace property. - Profile of image buffer was removed since it's not longer meaningful. - OpenGL and GLSL is supposed to always work in sRGB space. It is possible to support other spaces, but it's quite large project which isn't so much important. - Legacy Color Management option disabled is emulated by using None display. It could have some regressions, but there's no clear way to avoid them. - If OpenColorIO is disabled on build time, it should make blender behaving in the same way as previous release with color management enabled. More details could be found at this page (more details would be added soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management -- Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO integration and to Brecht van Lommel for some further development and code/ usecase review!
2012-09-15 10:05:07 +00:00
}
static void write_view3dshading(BlendWriter *writer, View3DShading *shading)
{
if (shading->prop) {
IDP_WriteProperty(shading->prop, writer);
}
}
static void write_paint(BlendWriter *writer, Paint *p)
{
if (p->cavity_curve) {
write_curvemapping(writer, p->cavity_curve);
}
BLO_write_struct_array(writer, PaintToolSlot, p->tool_slots_len, p->tool_slots);
}
static void write_layer_collections(BlendWriter *writer, ListBase *lb)
Render Layers and Collections (merge from render-layers) Design Documents ---------------- * https://wiki.blender.org/index.php/Dev:2.8/Source/Layers * https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised User Commit Log --------------- * New Layer and Collection system to replace render layers and viewport layers. * A layer is a set of collections of objects (and their drawing options) required for specific tasks. * A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers. * All Scenes have a master collection that all other collections are children of. * New collection "context" tab (in Properties Editor) * New temporary viewport "collections" panel to control per-collection visibility Missing User Features --------------------- * Collection "Filter" Option to add objects based on their names * Collection Manager operators The existing buttons are placeholders * Collection Manager drawing The editor main region is empty * Collection Override * Per-Collection engine settings This will come as a separate commit, as part of the clay-engine branch Dev Commit Log -------------- * New DNA file (DNA_layer_types.h) with the new structs We are replacing Base by a new extended Base while keeping it backward compatible with some legacy settings (i.e., lay, flag_legacy). Renamed all Base to BaseLegacy to make it clear the areas of code that still need to be converted Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp * Unittesting for main syncronization requirements - read, write, add/copy/remove objects, copy scene, collection link/unlinking, context) * New Editor: Collection Manager Based on patch by Julian Eisel This is extracted from the layer-manager branch. With the following changes: - Renamed references of layer manager to collections manager - I doesn't include the editors/space_collections/ draw and util files - The drawing code itself will be implemented separately by Julian * Base / Object: A little note about them. Original Blender code would try to keep them in sync through the code, juggling flags back and forth. This will now be handled by Depsgraph, keeping Object and Bases more separated throughout the non-rendering code. Scene.base is being cleared in doversion, and the old viewport drawing code was poorly converted to use the new bases while the new viewport code doesn't get merged and replace the old one. Python API Changes ------------------ ``` - scene.layers + # no longer exists - scene.objects + scene.scene_layers.active.objects - scene.objects.active + scene.render_layers.active.objects.active - bpy.context.scene.objects.link() + bpy.context.scene_collection.objects.link() - bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None) + bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None) - bpy.context.object.select + bpy.context.object.select = True + bpy.context.object.select = False + bpy.context.object.select_get() + bpy.context.object.select_set(action='SELECT') + bpy.context.object.select_set(action='DESELECT') -AddObjectHelper.layers + # no longer exists ```
2017-02-07 10:18:38 +01:00
{
LISTBASE_FOREACH (LayerCollection *, lc, lb) {
BLO_write_struct(writer, LayerCollection, lc);
Render Layers and Collections (merge from render-layers) Design Documents ---------------- * https://wiki.blender.org/index.php/Dev:2.8/Source/Layers * https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised User Commit Log --------------- * New Layer and Collection system to replace render layers and viewport layers. * A layer is a set of collections of objects (and their drawing options) required for specific tasks. * A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers. * All Scenes have a master collection that all other collections are children of. * New collection "context" tab (in Properties Editor) * New temporary viewport "collections" panel to control per-collection visibility Missing User Features --------------------- * Collection "Filter" Option to add objects based on their names * Collection Manager operators The existing buttons are placeholders * Collection Manager drawing The editor main region is empty * Collection Override * Per-Collection engine settings This will come as a separate commit, as part of the clay-engine branch Dev Commit Log -------------- * New DNA file (DNA_layer_types.h) with the new structs We are replacing Base by a new extended Base while keeping it backward compatible with some legacy settings (i.e., lay, flag_legacy). Renamed all Base to BaseLegacy to make it clear the areas of code that still need to be converted Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp * Unittesting for main syncronization requirements - read, write, add/copy/remove objects, copy scene, collection link/unlinking, context) * New Editor: Collection Manager Based on patch by Julian Eisel This is extracted from the layer-manager branch. With the following changes: - Renamed references of layer manager to collections manager - I doesn't include the editors/space_collections/ draw and util files - The drawing code itself will be implemented separately by Julian * Base / Object: A little note about them. Original Blender code would try to keep them in sync through the code, juggling flags back and forth. This will now be handled by Depsgraph, keeping Object and Bases more separated throughout the non-rendering code. Scene.base is being cleared in doversion, and the old viewport drawing code was poorly converted to use the new bases while the new viewport code doesn't get merged and replace the old one. Python API Changes ------------------ ``` - scene.layers + # no longer exists - scene.objects + scene.scene_layers.active.objects - scene.objects.active + scene.render_layers.active.objects.active - bpy.context.scene.objects.link() + bpy.context.scene_collection.objects.link() - bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None) + bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None) - bpy.context.object.select + bpy.context.object.select = True + bpy.context.object.select = False + bpy.context.object.select_get() + bpy.context.object.select_set(action='SELECT') + bpy.context.object.select_set(action='DESELECT') -AddObjectHelper.layers + # no longer exists ```
2017-02-07 10:18:38 +01:00
write_layer_collections(writer, &lc->layer_collections);
}
Render Layers and Collections (merge from render-layers) Design Documents ---------------- * https://wiki.blender.org/index.php/Dev:2.8/Source/Layers * https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised User Commit Log --------------- * New Layer and Collection system to replace render layers and viewport layers. * A layer is a set of collections of objects (and their drawing options) required for specific tasks. * A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers. * All Scenes have a master collection that all other collections are children of. * New collection "context" tab (in Properties Editor) * New temporary viewport "collections" panel to control per-collection visibility Missing User Features --------------------- * Collection "Filter" Option to add objects based on their names * Collection Manager operators The existing buttons are placeholders * Collection Manager drawing The editor main region is empty * Collection Override * Per-Collection engine settings This will come as a separate commit, as part of the clay-engine branch Dev Commit Log -------------- * New DNA file (DNA_layer_types.h) with the new structs We are replacing Base by a new extended Base while keeping it backward compatible with some legacy settings (i.e., lay, flag_legacy). Renamed all Base to BaseLegacy to make it clear the areas of code that still need to be converted Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp * Unittesting for main syncronization requirements - read, write, add/copy/remove objects, copy scene, collection link/unlinking, context) * New Editor: Collection Manager Based on patch by Julian Eisel This is extracted from the layer-manager branch. With the following changes: - Renamed references of layer manager to collections manager - I doesn't include the editors/space_collections/ draw and util files - The drawing code itself will be implemented separately by Julian * Base / Object: A little note about them. Original Blender code would try to keep them in sync through the code, juggling flags back and forth. This will now be handled by Depsgraph, keeping Object and Bases more separated throughout the non-rendering code. Scene.base is being cleared in doversion, and the old viewport drawing code was poorly converted to use the new bases while the new viewport code doesn't get merged and replace the old one. Python API Changes ------------------ ``` - scene.layers + # no longer exists - scene.objects + scene.scene_layers.active.objects - scene.objects.active + scene.render_layers.active.objects.active - bpy.context.scene.objects.link() + bpy.context.scene_collection.objects.link() - bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None) + bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None) - bpy.context.object.select + bpy.context.object.select = True + bpy.context.object.select = False + bpy.context.object.select_get() + bpy.context.object.select_set(action='SELECT') + bpy.context.object.select_set(action='DESELECT') -AddObjectHelper.layers + # no longer exists ```
2017-02-07 10:18:38 +01:00
}
static void write_view_layer(BlendWriter *writer, ViewLayer *view_layer)
{
BLO_write_struct(writer, ViewLayer, view_layer);
BLO_write_struct_list(writer, Base, &view_layer->object_bases);
if (view_layer->id_properties) {
IDP_WriteProperty(view_layer->id_properties, writer);
}
LISTBASE_FOREACH (FreestyleModuleConfig *, fmc, &view_layer->freestyle_config.modules) {
BLO_write_struct(writer, FreestyleModuleConfig, fmc);
}
LISTBASE_FOREACH (FreestyleLineSet *, fls, &view_layer->freestyle_config.linesets) {
BLO_write_struct(writer, FreestyleLineSet, fls);
}
write_layer_collections(writer, &view_layer->layer_collections);
}
static void write_lightcache_texture(BlendWriter *writer, LightCacheTexture *tex)
{
if (tex->data) {
size_t data_size = tex->components * tex->tex_size[0] * tex->tex_size[1] * tex->tex_size[2];
if (tex->data_type == LIGHTCACHETEX_FLOAT) {
data_size *= sizeof(float);
}
else if (tex->data_type == LIGHTCACHETEX_UINT) {
data_size *= sizeof(uint);
}
BLO_write_raw(writer, data_size, tex->data);
}
}
static void write_lightcache(BlendWriter *writer, LightCache *cache)
{
write_lightcache_texture(writer, &cache->grid_tx);
write_lightcache_texture(writer, &cache->cube_tx);
if (cache->cube_mips) {
BLO_write_struct_array(writer, LightCacheTexture, cache->mips_len, cache->cube_mips);
for (int i = 0; i < cache->mips_len; i++) {
write_lightcache_texture(writer, &cache->cube_mips[i]);
}
}
BLO_write_struct_array(writer, LightGridCache, cache->grid_len, cache->grid_data);
BLO_write_struct_array(writer, LightProbeCache, cache->cube_len, cache->cube_data);
}
2020-06-05 13:55:33 +02:00
static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address)
2002-10-12 11:37:38 +00:00
{
2020-06-05 13:55:33 +02:00
if (BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
/* XXX This UI data should not be stored in Scene at all... */
memset(&sce->cursor, 0, sizeof(sce->cursor));
}
/* write LibData */
2020-06-05 13:55:33 +02:00
BLO_write_id_struct(writer, Scene, id_address, &sce->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &sce->id);
if (sce->adt) {
write_animdata(writer, sce->adt);
}
write_keyingsets(writer, &sce->keyingsets);
/* direct data */
ToolSettings *tos = sce->toolsettings;
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, ToolSettings, tos);
if (tos->vpaint) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, VPaint, tos->vpaint);
write_paint(writer, &tos->vpaint->paint);
}
if (tos->wpaint) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, VPaint, tos->wpaint);
write_paint(writer, &tos->wpaint->paint);
}
if (tos->sculpt) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, Sculpt, tos->sculpt);
write_paint(writer, &tos->sculpt->paint);
}
if (tos->uvsculpt) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, UvSculpt, tos->uvsculpt);
write_paint(writer, &tos->uvsculpt->paint);
}
if (tos->gp_paint) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, GpPaint, tos->gp_paint);
write_paint(writer, &tos->gp_paint->paint);
}
if (tos->gp_vertexpaint) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, GpVertexPaint, tos->gp_vertexpaint);
write_paint(writer, &tos->gp_vertexpaint->paint);
}
if (tos->gp_sculptpaint) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, GpSculptPaint, tos->gp_sculptpaint);
write_paint(writer, &tos->gp_sculptpaint->paint);
}
if (tos->gp_weightpaint) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, GpWeightPaint, tos->gp_weightpaint);
write_paint(writer, &tos->gp_weightpaint->paint);
}
/* write grease-pencil custom ipo curve to file */
if (tos->gp_interpolate.custom_ipo) {
write_curvemapping(writer, tos->gp_interpolate.custom_ipo);
}
/* write grease-pencil multiframe falloff curve to file */
if (tos->gp_sculpt.cur_falloff) {
write_curvemapping(writer, tos->gp_sculpt.cur_falloff);
}
/* write grease-pencil primitive curve to file */
if (tos->gp_sculpt.cur_primitive) {
write_curvemapping(writer, tos->gp_sculpt.cur_primitive);
}
/* Write the curve profile to the file. */
if (tos->custom_bevel_profile_preset) {
write_CurveProfile(writer, tos->custom_bevel_profile_preset);
}
write_paint(writer, &tos->imapaint.paint);
Editing *ed = sce->ed;
if (ed) {
Sequence *seq;
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, Editing, ed);
/* reset write flags too */
SEQ_BEGIN (ed, seq) {
if (seq->strip) {
seq->strip->done = false;
}
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, Sequence, seq);
}
SEQ_END;
SEQ_BEGIN (ed, seq) {
if (seq->strip && seq->strip->done == 0) {
/* write strip with 'done' at 0 because readfile */
if (seq->effectdata) {
switch (seq->type) {
case SEQ_TYPE_COLOR:
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, SolidColorVars, seq->effectdata);
break;
case SEQ_TYPE_SPEED:
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, SpeedControlVars, seq->effectdata);
break;
case SEQ_TYPE_WIPE:
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, WipeVars, seq->effectdata);
break;
case SEQ_TYPE_GLOW:
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, GlowVars, seq->effectdata);
break;
case SEQ_TYPE_TRANSFORM:
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, TransformVars, seq->effectdata);
break;
case SEQ_TYPE_GAUSSIAN_BLUR:
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, GaussianBlurVars, seq->effectdata);
break;
case SEQ_TYPE_TEXT:
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, TextVars, seq->effectdata);
break;
case SEQ_TYPE_COLORMIX:
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, ColorMixVars, seq->effectdata);
break;
}
}
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, Stereo3dFormat, seq->stereo3d_format);
Strip *strip = seq->strip;
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, Strip, strip);
if (strip->crop) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, StripCrop, strip->crop);
}
if (strip->transform) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, StripTransform, strip->transform);
}
if (strip->proxy) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, StripProxy, strip->proxy);
}
if (seq->type == SEQ_TYPE_IMAGE) {
2020-06-05 13:55:33 +02:00
BLO_write_struct_array(writer,
StripElem,
MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem),
strip->stripdata);
}
else if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, StripElem, strip->stripdata);
}
strip->done = true;
}
if (seq->prop) {
IDP_WriteProperty(seq->prop, writer);
}
write_sequence_modifiers(writer, &seq->modifiers);
}
SEQ_END;
/* new; meta stack too, even when its nasty restore code */
LISTBASE_FOREACH (MetaStack *, ms, &ed->metastack) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, MetaStack, ms);
}
}
if (sce->r.avicodecdata) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, AviCodecData, sce->r.avicodecdata);
if (sce->r.avicodecdata->lpFormat) {
2020-06-05 13:55:33 +02:00
BLO_write_raw(writer, sce->r.avicodecdata->cbFormat, sce->r.avicodecdata->lpFormat);
}
if (sce->r.avicodecdata->lpParms) {
2020-06-05 13:55:33 +02:00
BLO_write_raw(writer, sce->r.avicodecdata->cbParms, sce->r.avicodecdata->lpParms);
}
}
if (sce->r.ffcodecdata.properties) {
IDP_WriteProperty(sce->r.ffcodecdata.properties, writer);
}
/* writing dynamic list of TimeMarkers to the blend file */
LISTBASE_FOREACH (TimeMarker *, marker, &sce->markers) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, TimeMarker, marker);
}
/* writing dynamic list of TransformOrientations to the blend file */
LISTBASE_FOREACH (TransformOrientation *, ts, &sce->transform_spaces) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, TransformOrientation, ts);
}
/* writing MultiView to the blend file */
LISTBASE_FOREACH (SceneRenderView *, srv, &sce->r.views) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, SceneRenderView, srv);
}
if (sce->nodetree) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, bNodeTree, sce->nodetree);
write_nodetree_nolib(writer, sce->nodetree);
}
write_view_settings(writer, &sce->view_settings);
/* writing RigidBodyWorld data to the blend file */
if (sce->rigidbody_world) {
/* Set deprecated pointers to prevent crashes of older Blenders */
sce->rigidbody_world->pointcache = sce->rigidbody_world->shared->pointcache;
sce->rigidbody_world->ptcaches = sce->rigidbody_world->shared->ptcaches;
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, RigidBodyWorld, sce->rigidbody_world);
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, RigidBodyWorld_Shared, sce->rigidbody_world->shared);
BLO_write_struct(writer, EffectorWeights, sce->rigidbody_world->effector_weights);
write_pointcaches(writer, &(sce->rigidbody_world->shared->ptcaches));
}
write_previews(writer, sce->preview);
write_curvemapping_curves(writer, &sce->r.mblur_shutter_curve);
LISTBASE_FOREACH (ViewLayer *, view_layer, &sce->view_layers) {
write_view_layer(writer, view_layer);
}
if (sce->master_collection) {
2020-06-05 13:55:33 +02:00
BLO_write_struct(writer, Collection, sce->master_collection);
write_collection_nolib(writer, sce->master_collection);
}
/* Eevee Lightcache */
2020-06-05 13:55:33 +02:00
if (sce->eevee.light_cache_data && !BLO_write_is_undo(writer)) {
BLO_write_struct(writer, LightCache, sce->eevee.light_cache_data);
write_lightcache(writer, sce->eevee.light_cache_data);
}
write_view3dshading(writer, &sce->display.shading);
/* Freed on doversion. */
BLI_assert(sce->layer_properties == NULL);
2002-10-12 11:37:38 +00:00
}
static void write_gpencil(BlendWriter *writer, bGPdata *gpd, const void *id_address)
{
if (gpd->id.us > 0 || BLO_write_is_undo(writer)) {
2020-04-03 12:38:04 +11:00
/* Clean up, important in undo case to reduce false detection of changed data-blocks. */
/* XXX not sure why the whole run-time data is not cleared in reading code,
* for now mimicking it here. */
gpd->runtime.sbuffer = NULL;
gpd->runtime.sbuffer_used = 0;
gpd->runtime.sbuffer_size = 0;
gpd->runtime.tot_cp_points = 0;
/* write gpd data block to file */
BLO_write_id_struct(writer, bGPdata, id_address, &gpd->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &gpd->id);
if (gpd->adt) {
write_animdata(writer, gpd->adt);
}
BLO_write_pointer_array(writer, gpd->totcol, gpd->mat);
/* write grease-pencil layers to file */
BLO_write_struct_list(writer, bGPDlayer, &gpd->layers);
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
/* Write mask list. */
BLO_write_struct_list(writer, bGPDlayer_Mask, &gpl->mask_layers);
/* write this layer's frames to file */
BLO_write_struct_list(writer, bGPDframe, &gpl->frames);
LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
/* write strokes */
BLO_write_struct_list(writer, bGPDstroke, &gpf->strokes);
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
BLO_write_struct_array(writer, bGPDspoint, gps->totpoints, gps->points);
BLO_write_struct_array(writer, bGPDtriangle, gps->tot_triangles, gps->triangles);
write_dverts(writer, gps->totpoints, gps->dvert);
}
}
}
}
}
static void write_wm_xr_data(BlendWriter *writer, wmXrData *xr_data)
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection NOTE: While most of the milestone 1 goals are there, a few smaller features and improvements are still to be done. Big picture of this milestone: Initial, OpenXR-based virtual reality support for users and foundation for advanced use cases. Maniphest Task: https://developer.blender.org/T71347 The tasks contains more information about this milestone. To be clear: This is not a feature rich VR implementation, it's focused on the initial scene inspection use case. We intentionally focused on that, further features like controller support are part of the next milestone. - How to use? Instructions on how to use this are here: https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test These will be updated and moved to a more official place (likely the manual) soon. Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC headsets don't support the OpenXR standard yet and hence, do not work with this implementation. --------------- This is the C-side implementation of the features added for initial VR support as per milestone 1. A "VR Scene Inspection" Add-on will be committed separately, to expose the VR functionality in the UI. It also adds some further features for milestone 1, namely a landmarking system (stored view locations in the VR space) Main additions/features: * Support for rendering viewports to an HMD, with good performance. * Option to sync the VR view perspective with a fully interactive, regular 3D View (VR-Mirror). * Option to disable positional tracking. Keeps the current position (calculated based on the VR eye center pose) when enabled while a VR session is running. * Some regular viewport settings for the VR view * RNA/Python-API to query and set VR session state information. * WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data * wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU context) * DNA/RNA for management of VR session settings * `--debug-xr` and `--debug-xr-time` commandline options * Utility batch & config file for using the Oculus runtime on Windows. * Most VR data is runtime only. The exception is user settings which are saved to files (`XrSessionSettings`). * VR support can be disabled through the `WITH_XR_OPENXR` compiler flag. For architecture and code documentation, see https://wiki.blender.org/wiki/Source/Interface/XR. --------------- A few thank you's: * A huge shoutout to Ray Molenkamp for his help during the project - it would have not been that successful without him! * Sebastian Koenig and Simeon Conzendorf for testing and feedback! * The reviewers, especially Brecht Van Lommel! * Dalai Felinto for pushing and managing me to get this done ;) * The OpenXR working group for providing an open standard. I think we're the first bigger application to adopt OpenXR. Congratulations to them and ourselves :) This project started as a Google Summer of Code 2019 project - "Core Support of Virtual Reality Headsets through OpenXR" (see https://wiki.blender.org/wiki/User:Severin/GSoC-2019/). Some further information, including ideas for further improvements can be found in the final GSoC report: https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report Differential Revisions: D6193, D7098 Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
{
write_view3dshading(writer, &xr_data->session_settings.shading);
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection NOTE: While most of the milestone 1 goals are there, a few smaller features and improvements are still to be done. Big picture of this milestone: Initial, OpenXR-based virtual reality support for users and foundation for advanced use cases. Maniphest Task: https://developer.blender.org/T71347 The tasks contains more information about this milestone. To be clear: This is not a feature rich VR implementation, it's focused on the initial scene inspection use case. We intentionally focused on that, further features like controller support are part of the next milestone. - How to use? Instructions on how to use this are here: https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test These will be updated and moved to a more official place (likely the manual) soon. Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC headsets don't support the OpenXR standard yet and hence, do not work with this implementation. --------------- This is the C-side implementation of the features added for initial VR support as per milestone 1. A "VR Scene Inspection" Add-on will be committed separately, to expose the VR functionality in the UI. It also adds some further features for milestone 1, namely a landmarking system (stored view locations in the VR space) Main additions/features: * Support for rendering viewports to an HMD, with good performance. * Option to sync the VR view perspective with a fully interactive, regular 3D View (VR-Mirror). * Option to disable positional tracking. Keeps the current position (calculated based on the VR eye center pose) when enabled while a VR session is running. * Some regular viewport settings for the VR view * RNA/Python-API to query and set VR session state information. * WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data * wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU context) * DNA/RNA for management of VR session settings * `--debug-xr` and `--debug-xr-time` commandline options * Utility batch & config file for using the Oculus runtime on Windows. * Most VR data is runtime only. The exception is user settings which are saved to files (`XrSessionSettings`). * VR support can be disabled through the `WITH_XR_OPENXR` compiler flag. For architecture and code documentation, see https://wiki.blender.org/wiki/Source/Interface/XR. --------------- A few thank you's: * A huge shoutout to Ray Molenkamp for his help during the project - it would have not been that successful without him! * Sebastian Koenig and Simeon Conzendorf for testing and feedback! * The reviewers, especially Brecht Van Lommel! * Dalai Felinto for pushing and managing me to get this done ;) * The OpenXR working group for providing an open standard. I think we're the first bigger application to adopt OpenXR. Congratulations to them and ourselves :) This project started as a Google Summer of Code 2019 project - "Core Support of Virtual Reality Headsets through OpenXR" (see https://wiki.blender.org/wiki/User:Severin/GSoC-2019/). Some further information, including ideas for further improvements can be found in the final GSoC report: https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report Differential Revisions: D6193, D7098 Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
}
static void write_region(BlendWriter *writer, ARegion *region, int spacetype)
{
BLO_write_struct(writer, ARegion, region);
if (region->regiondata) {
if (region->flag & RGN_FLAG_TEMP_REGIONDATA) {
return;
}
switch (spacetype) {
case SPACE_VIEW3D:
if (region->regiontype == RGN_TYPE_WINDOW) {
RegionView3D *rv3d = region->regiondata;
BLO_write_struct(writer, RegionView3D, rv3d);
if (rv3d->localvd) {
BLO_write_struct(writer, RegionView3D, rv3d->localvd);
}
if (rv3d->clipbb) {
BLO_write_struct(writer, BoundBox, rv3d->clipbb);
}
}
else {
printf("regiondata write missing!\n");
}
break;
default:
printf("regiondata write missing!\n");
}
}
}
static void write_uilist(BlendWriter *writer, uiList *ui_list)
{
BLO_write_struct(writer, uiList, ui_list);
if (ui_list->properties) {
IDP_WriteProperty(ui_list->properties, writer);
}
}
static void write_soops(BlendWriter *writer, SpaceOutliner *so)
{
BLI_mempool *ts = so->treestore;
if (ts) {
SpaceOutliner so_flat = *so;
int elems = BLI_mempool_len(ts);
/* linearize mempool to array */
TreeStoreElem *data = elems ? BLI_mempool_as_arrayN(ts, "TreeStoreElem") : NULL;
if (data) {
/* In this block we use the memory location of the treestore
* but _not_ its data, the addresses in this case are UUID's,
* since we can't rely on malloc giving us different values each time.
*/
TreeStore ts_flat = {0};
/* we know the treestore is at least as big as a pointer,
* so offsetting works to give us a UUID. */
void *data_addr = (void *)POINTER_OFFSET(ts, sizeof(void *));
ts_flat.usedelem = elems;
ts_flat.totelem = elems;
ts_flat.data = data_addr;
BLO_write_struct(writer, SpaceOutliner, so);
BLO_write_struct_at_address(writer, TreeStore, ts, &ts_flat);
BLO_write_struct_array_at_address(writer, TreeStoreElem, elems, data_addr, data);
MEM_freeN(data);
}
else {
so_flat.treestore = NULL;
BLO_write_struct_at_address(writer, SpaceOutliner, so, &so_flat);
}
}
else {
BLO_write_struct(writer, SpaceOutliner, so);
}
}
static void write_panel_list(BlendWriter *writer, ListBase *lb)
{
LISTBASE_FOREACH (Panel *, panel, lb) {
BLO_write_struct(writer, Panel, panel);
write_panel_list(writer, &panel->children);
}
}
static void write_area_regions(BlendWriter *writer, ScrArea *area)
2002-10-12 11:37:38 +00:00
{
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
write_region(writer, region, area->spacetype);
write_panel_list(writer, &region->panels);
LISTBASE_FOREACH (PanelCategoryStack *, pc_act, &region->panels_category_active) {
BLO_write_struct(writer, PanelCategoryStack, pc_act);
}
LISTBASE_FOREACH (uiList *, ui_list, &region->ui_lists) {
write_uilist(writer, ui_list);
}
LISTBASE_FOREACH (uiPreview *, ui_preview, &region->ui_previews) {
BLO_write_struct(writer, uiPreview, ui_preview);
}
}
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
LISTBASE_FOREACH (ARegion *, region, &sl->regionbase) {
write_region(writer, region, sl->spacetype);
}
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
BLO_write_struct(writer, View3D, v3d);
if (v3d->localvd) {
BLO_write_struct(writer, View3D, v3d->localvd);
}
write_view3dshading(writer, &v3d->shading);
}
else if (sl->spacetype == SPACE_GRAPH) {
SpaceGraph *sipo = (SpaceGraph *)sl;
ListBase tmpGhosts = sipo->runtime.ghost_curves;
/* temporarily disable ghost curves when saving */
BLI_listbase_clear(&sipo->runtime.ghost_curves);
BLO_write_struct(writer, SpaceGraph, sl);
if (sipo->ads) {
BLO_write_struct(writer, bDopeSheet, sipo->ads);
}
/* reenable ghost curves */
sipo->runtime.ghost_curves = tmpGhosts;
}
else if (sl->spacetype == SPACE_PROPERTIES) {
BLO_write_struct(writer, SpaceProperties, sl);
}
else if (sl->spacetype == SPACE_FILE) {
SpaceFile *sfile = (SpaceFile *)sl;
BLO_write_struct(writer, SpaceFile, sl);
if (sfile->params) {
BLO_write_struct(writer, FileSelectParams, sfile->params);
}
}
else if (sl->spacetype == SPACE_SEQ) {
BLO_write_struct(writer, SpaceSeq, sl);
}
else if (sl->spacetype == SPACE_OUTLINER) {
SpaceOutliner *so = (SpaceOutliner *)sl;
write_soops(writer, so);
}
else if (sl->spacetype == SPACE_IMAGE) {
BLO_write_struct(writer, SpaceImage, sl);
}
else if (sl->spacetype == SPACE_TEXT) {
BLO_write_struct(writer, SpaceText, sl);
}
else if (sl->spacetype == SPACE_SCRIPT) {
SpaceScript *scr = (SpaceScript *)sl;
scr->but_refs = NULL;
BLO_write_struct(writer, SpaceScript, sl);
}
else if (sl->spacetype == SPACE_ACTION) {
BLO_write_struct(writer, SpaceAction, sl);
}
else if (sl->spacetype == SPACE_NLA) {
SpaceNla *snla = (SpaceNla *)sl;
BLO_write_struct(writer, SpaceNla, snla);
if (snla->ads) {
BLO_write_struct(writer, bDopeSheet, snla->ads);
}
}
else if (sl->spacetype == SPACE_NODE) {
SpaceNode *snode = (SpaceNode *)sl;
bNodeTreePath *path;
BLO_write_struct(writer, SpaceNode, snode);
for (path = snode->treepath.first; path; path = path->next) {
BLO_write_struct(writer, bNodeTreePath, path);
}
}
else if (sl->spacetype == SPACE_CONSOLE) {
SpaceConsole *con = (SpaceConsole *)sl;
ConsoleLine *cl;
for (cl = con->history.first; cl; cl = cl->next) {
/* 'len_alloc' is invalid on write, set from 'len' on read */
BLO_write_struct(writer, ConsoleLine, cl);
BLO_write_raw(writer, cl->len + 1, cl->line);
}
BLO_write_struct(writer, SpaceConsole, sl);
}
#ifdef WITH_GLOBAL_AREA_WRITING
else if (sl->spacetype == SPACE_TOPBAR) {
BLO_write_struct(writer, SpaceTopBar, sl);
}
else if (sl->spacetype == SPACE_STATUSBAR) {
BLO_write_struct(writer, SpaceStatusBar, sl);
}
UI: New Global Top-Bar (WIP) == Main Features/Changes for Users * Add horizontal bar at top of all non-temp windows, consisting out of two horizontal sub-bars. * Upper sub-bar contains global menus (File, Render, etc.), tabs for workspaces and scene selector. * Lower sub-bar contains object mode selector, screen-layout and render-layer selector. Later operator and/or tool settings will be placed here. * Individual sections of the topbar are individually scrollable. * Workspace tabs can be double- or ctrl-clicked for renaming and contain 'x' icon for deleting. * Top-bar should scale nicely with DPI. * The lower half of the top-bar can be hided by dragging the lower top-bar edge up. Better hiding options are planned (e.g. hide in fullscreen modes). * Info editors at the top of the window and using the full window width with be replaced by the top-bar. * In fullscreen modes, no more info editor is added on top, the top-bar replaces it. == Technical Features/Changes * Adds initial support for global areas A global area is part of the window, not part of the regular screen-layout. I've added a macro iterator to iterate over both, global and screen-layout level areas. When iterating over areas, from now on developers should always consider if they have to include global areas. * Adds a TOPBAR editor type The editor type is hidden in the UI editor type menu. * Adds a variation of the ID template to display IDs as tab buttons (template_ID_tabs in BPY) * Does various changes to RNA button creation code to improve their appearance in the horizontal top-bar. * Adds support for dynamically sized regions. That is, regions that scale automatically to the layout bounds. The code for this is currently a big hack (it's based on drawing the UI multiple times). This should definitely be improved. * Adds a template for displaying operator properties optimized for the top-bar. This will probably change a lot still and is in fact disabled in code. Since the final top-bar design depends a lot on other 2.8 designs (mainly tool-system and workspaces), we decided to not show the operator or tool settings in the top-bar for now. That means most of the lower sub-bar is empty for the time being. NOTE: Top-bar or global area data is not written to files or SDNA. They are simply added to the window when opening Blender or reading a file. This allows us doing changes to the top-bar without having to care for compatibility. == ToDo's It's a bit hard to predict all the ToDo's here are the known main ones: * Add options for the new active-tool system and for operator redo to the topbar. * Automatically hide the top-bar in fullscreen modes. * General visual polish. * Top-bar drag & drop support (WIP in temp-tab_drag_drop). * Improve dynamic regions (should also fix some layout glitches). * Make internal terminology consistent. * Enable topbar file writing once design is more advanced. * Address TODO's and XXX's in code :) Thanks @brecht for the review! And @sergey for the complaining ;) Differential Revision: D2758
2018-04-20 17:14:03 +02:00
#endif
else if (sl->spacetype == SPACE_USERPREF) {
BLO_write_struct(writer, SpaceUserPref, sl);
}
else if (sl->spacetype == SPACE_CLIP) {
BLO_write_struct(writer, SpaceClip, sl);
}
else if (sl->spacetype == SPACE_INFO) {
BLO_write_struct(writer, SpaceInfo, sl);
}
}
UI: New Global Top-Bar (WIP) == Main Features/Changes for Users * Add horizontal bar at top of all non-temp windows, consisting out of two horizontal sub-bars. * Upper sub-bar contains global menus (File, Render, etc.), tabs for workspaces and scene selector. * Lower sub-bar contains object mode selector, screen-layout and render-layer selector. Later operator and/or tool settings will be placed here. * Individual sections of the topbar are individually scrollable. * Workspace tabs can be double- or ctrl-clicked for renaming and contain 'x' icon for deleting. * Top-bar should scale nicely with DPI. * The lower half of the top-bar can be hided by dragging the lower top-bar edge up. Better hiding options are planned (e.g. hide in fullscreen modes). * Info editors at the top of the window and using the full window width with be replaced by the top-bar. * In fullscreen modes, no more info editor is added on top, the top-bar replaces it. == Technical Features/Changes * Adds initial support for global areas A global area is part of the window, not part of the regular screen-layout. I've added a macro iterator to iterate over both, global and screen-layout level areas. When iterating over areas, from now on developers should always consider if they have to include global areas. * Adds a TOPBAR editor type The editor type is hidden in the UI editor type menu. * Adds a variation of the ID template to display IDs as tab buttons (template_ID_tabs in BPY) * Does various changes to RNA button creation code to improve their appearance in the horizontal top-bar. * Adds support for dynamically sized regions. That is, regions that scale automatically to the layout bounds. The code for this is currently a big hack (it's based on drawing the UI multiple times). This should definitely be improved. * Adds a template for displaying operator properties optimized for the top-bar. This will probably change a lot still and is in fact disabled in code. Since the final top-bar design depends a lot on other 2.8 designs (mainly tool-system and workspaces), we decided to not show the operator or tool settings in the top-bar for now. That means most of the lower sub-bar is empty for the time being. NOTE: Top-bar or global area data is not written to files or SDNA. They are simply added to the window when opening Blender or reading a file. This allows us doing changes to the top-bar without having to care for compatibility. == ToDo's It's a bit hard to predict all the ToDo's here are the known main ones: * Add options for the new active-tool system and for operator redo to the topbar. * Automatically hide the top-bar in fullscreen modes. * General visual polish. * Top-bar drag & drop support (WIP in temp-tab_drag_drop). * Improve dynamic regions (should also fix some layout glitches). * Make internal terminology consistent. * Enable topbar file writing once design is more advanced. * Address TODO's and XXX's in code :) Thanks @brecht for the review! And @sergey for the complaining ;) Differential Revision: D2758
2018-04-20 17:14:03 +02:00
}
static void write_area_map(BlendWriter *writer, ScrAreaMap *area_map)
UI: New Global Top-Bar (WIP) == Main Features/Changes for Users * Add horizontal bar at top of all non-temp windows, consisting out of two horizontal sub-bars. * Upper sub-bar contains global menus (File, Render, etc.), tabs for workspaces and scene selector. * Lower sub-bar contains object mode selector, screen-layout and render-layer selector. Later operator and/or tool settings will be placed here. * Individual sections of the topbar are individually scrollable. * Workspace tabs can be double- or ctrl-clicked for renaming and contain 'x' icon for deleting. * Top-bar should scale nicely with DPI. * The lower half of the top-bar can be hided by dragging the lower top-bar edge up. Better hiding options are planned (e.g. hide in fullscreen modes). * Info editors at the top of the window and using the full window width with be replaced by the top-bar. * In fullscreen modes, no more info editor is added on top, the top-bar replaces it. == Technical Features/Changes * Adds initial support for global areas A global area is part of the window, not part of the regular screen-layout. I've added a macro iterator to iterate over both, global and screen-layout level areas. When iterating over areas, from now on developers should always consider if they have to include global areas. * Adds a TOPBAR editor type The editor type is hidden in the UI editor type menu. * Adds a variation of the ID template to display IDs as tab buttons (template_ID_tabs in BPY) * Does various changes to RNA button creation code to improve their appearance in the horizontal top-bar. * Adds support for dynamically sized regions. That is, regions that scale automatically to the layout bounds. The code for this is currently a big hack (it's based on drawing the UI multiple times). This should definitely be improved. * Adds a template for displaying operator properties optimized for the top-bar. This will probably change a lot still and is in fact disabled in code. Since the final top-bar design depends a lot on other 2.8 designs (mainly tool-system and workspaces), we decided to not show the operator or tool settings in the top-bar for now. That means most of the lower sub-bar is empty for the time being. NOTE: Top-bar or global area data is not written to files or SDNA. They are simply added to the window when opening Blender or reading a file. This allows us doing changes to the top-bar without having to care for compatibility. == ToDo's It's a bit hard to predict all the ToDo's here are the known main ones: * Add options for the new active-tool system and for operator redo to the topbar. * Automatically hide the top-bar in fullscreen modes. * General visual polish. * Top-bar drag & drop support (WIP in temp-tab_drag_drop). * Improve dynamic regions (should also fix some layout glitches). * Make internal terminology consistent. * Enable topbar file writing once design is more advanced. * Address TODO's and XXX's in code :) Thanks @brecht for the review! And @sergey for the complaining ;) Differential Revision: D2758
2018-04-20 17:14:03 +02:00
{
BLO_write_struct_list(writer, ScrVert, &area_map->vertbase);
BLO_write_struct_list(writer, ScrEdge, &area_map->edgebase);
LISTBASE_FOREACH (ScrArea *, area, &area_map->areabase) {
area->butspacetype = area->spacetype; /* Just for compatibility, will be reset below. */
BLO_write_struct(writer, ScrArea, area);
UI: New Global Top-Bar (WIP) == Main Features/Changes for Users * Add horizontal bar at top of all non-temp windows, consisting out of two horizontal sub-bars. * Upper sub-bar contains global menus (File, Render, etc.), tabs for workspaces and scene selector. * Lower sub-bar contains object mode selector, screen-layout and render-layer selector. Later operator and/or tool settings will be placed here. * Individual sections of the topbar are individually scrollable. * Workspace tabs can be double- or ctrl-clicked for renaming and contain 'x' icon for deleting. * Top-bar should scale nicely with DPI. * The lower half of the top-bar can be hided by dragging the lower top-bar edge up. Better hiding options are planned (e.g. hide in fullscreen modes). * Info editors at the top of the window and using the full window width with be replaced by the top-bar. * In fullscreen modes, no more info editor is added on top, the top-bar replaces it. == Technical Features/Changes * Adds initial support for global areas A global area is part of the window, not part of the regular screen-layout. I've added a macro iterator to iterate over both, global and screen-layout level areas. When iterating over areas, from now on developers should always consider if they have to include global areas. * Adds a TOPBAR editor type The editor type is hidden in the UI editor type menu. * Adds a variation of the ID template to display IDs as tab buttons (template_ID_tabs in BPY) * Does various changes to RNA button creation code to improve their appearance in the horizontal top-bar. * Adds support for dynamically sized regions. That is, regions that scale automatically to the layout bounds. The code for this is currently a big hack (it's based on drawing the UI multiple times). This should definitely be improved. * Adds a template for displaying operator properties optimized for the top-bar. This will probably change a lot still and is in fact disabled in code. Since the final top-bar design depends a lot on other 2.8 designs (mainly tool-system and workspaces), we decided to not show the operator or tool settings in the top-bar for now. That means most of the lower sub-bar is empty for the time being. NOTE: Top-bar or global area data is not written to files or SDNA. They are simply added to the window when opening Blender or reading a file. This allows us doing changes to the top-bar without having to care for compatibility. == ToDo's It's a bit hard to predict all the ToDo's here are the known main ones: * Add options for the new active-tool system and for operator redo to the topbar. * Automatically hide the top-bar in fullscreen modes. * General visual polish. * Top-bar drag & drop support (WIP in temp-tab_drag_drop). * Improve dynamic regions (should also fix some layout glitches). * Make internal terminology consistent. * Enable topbar file writing once design is more advanced. * Address TODO's and XXX's in code :) Thanks @brecht for the review! And @sergey for the complaining ;) Differential Revision: D2758
2018-04-20 17:14:03 +02:00
#ifdef WITH_GLOBAL_AREA_WRITING
BLO_write_struct(writer, ScrGlobalAreaData, area->global);
UI: New Global Top-Bar (WIP) == Main Features/Changes for Users * Add horizontal bar at top of all non-temp windows, consisting out of two horizontal sub-bars. * Upper sub-bar contains global menus (File, Render, etc.), tabs for workspaces and scene selector. * Lower sub-bar contains object mode selector, screen-layout and render-layer selector. Later operator and/or tool settings will be placed here. * Individual sections of the topbar are individually scrollable. * Workspace tabs can be double- or ctrl-clicked for renaming and contain 'x' icon for deleting. * Top-bar should scale nicely with DPI. * The lower half of the top-bar can be hided by dragging the lower top-bar edge up. Better hiding options are planned (e.g. hide in fullscreen modes). * Info editors at the top of the window and using the full window width with be replaced by the top-bar. * In fullscreen modes, no more info editor is added on top, the top-bar replaces it. == Technical Features/Changes * Adds initial support for global areas A global area is part of the window, not part of the regular screen-layout. I've added a macro iterator to iterate over both, global and screen-layout level areas. When iterating over areas, from now on developers should always consider if they have to include global areas. * Adds a TOPBAR editor type The editor type is hidden in the UI editor type menu. * Adds a variation of the ID template to display IDs as tab buttons (template_ID_tabs in BPY) * Does various changes to RNA button creation code to improve their appearance in the horizontal top-bar. * Adds support for dynamically sized regions. That is, regions that scale automatically to the layout bounds. The code for this is currently a big hack (it's based on drawing the UI multiple times). This should definitely be improved. * Adds a template for displaying operator properties optimized for the top-bar. This will probably change a lot still and is in fact disabled in code. Since the final top-bar design depends a lot on other 2.8 designs (mainly tool-system and workspaces), we decided to not show the operator or tool settings in the top-bar for now. That means most of the lower sub-bar is empty for the time being. NOTE: Top-bar or global area data is not written to files or SDNA. They are simply added to the window when opening Blender or reading a file. This allows us doing changes to the top-bar without having to care for compatibility. == ToDo's It's a bit hard to predict all the ToDo's here are the known main ones: * Add options for the new active-tool system and for operator redo to the topbar. * Automatically hide the top-bar in fullscreen modes. * General visual polish. * Top-bar drag & drop support (WIP in temp-tab_drag_drop). * Improve dynamic regions (should also fix some layout glitches). * Make internal terminology consistent. * Enable topbar file writing once design is more advanced. * Address TODO's and XXX's in code :) Thanks @brecht for the review! And @sergey for the complaining ;) Differential Revision: D2758
2018-04-20 17:14:03 +02:00
#endif
write_area_regions(writer, area);
area->butspacetype = SPACE_EMPTY; /* Unset again, was changed above. */
}
}
static void write_windowmanager(BlendWriter *writer, wmWindowManager *wm, const void *id_address)
{
BLO_write_id_struct(writer, wmWindowManager, id_address, &wm->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &wm->id);
write_wm_xr_data(writer, &wm->xr);
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
#ifndef WITH_GLOBAL_AREA_WRITING
/* Don't write global areas yet, while we make changes to them. */
ScrAreaMap global_areas = win->global_areas;
memset(&win->global_areas, 0, sizeof(win->global_areas));
UI: New Global Top-Bar (WIP) == Main Features/Changes for Users * Add horizontal bar at top of all non-temp windows, consisting out of two horizontal sub-bars. * Upper sub-bar contains global menus (File, Render, etc.), tabs for workspaces and scene selector. * Lower sub-bar contains object mode selector, screen-layout and render-layer selector. Later operator and/or tool settings will be placed here. * Individual sections of the topbar are individually scrollable. * Workspace tabs can be double- or ctrl-clicked for renaming and contain 'x' icon for deleting. * Top-bar should scale nicely with DPI. * The lower half of the top-bar can be hided by dragging the lower top-bar edge up. Better hiding options are planned (e.g. hide in fullscreen modes). * Info editors at the top of the window and using the full window width with be replaced by the top-bar. * In fullscreen modes, no more info editor is added on top, the top-bar replaces it. == Technical Features/Changes * Adds initial support for global areas A global area is part of the window, not part of the regular screen-layout. I've added a macro iterator to iterate over both, global and screen-layout level areas. When iterating over areas, from now on developers should always consider if they have to include global areas. * Adds a TOPBAR editor type The editor type is hidden in the UI editor type menu. * Adds a variation of the ID template to display IDs as tab buttons (template_ID_tabs in BPY) * Does various changes to RNA button creation code to improve their appearance in the horizontal top-bar. * Adds support for dynamically sized regions. That is, regions that scale automatically to the layout bounds. The code for this is currently a big hack (it's based on drawing the UI multiple times). This should definitely be improved. * Adds a template for displaying operator properties optimized for the top-bar. This will probably change a lot still and is in fact disabled in code. Since the final top-bar design depends a lot on other 2.8 designs (mainly tool-system and workspaces), we decided to not show the operator or tool settings in the top-bar for now. That means most of the lower sub-bar is empty for the time being. NOTE: Top-bar or global area data is not written to files or SDNA. They are simply added to the window when opening Blender or reading a file. This allows us doing changes to the top-bar without having to care for compatibility. == ToDo's It's a bit hard to predict all the ToDo's here are the known main ones: * Add options for the new active-tool system and for operator redo to the topbar. * Automatically hide the top-bar in fullscreen modes. * General visual polish. * Top-bar drag & drop support (WIP in temp-tab_drag_drop). * Improve dynamic regions (should also fix some layout glitches). * Make internal terminology consistent. * Enable topbar file writing once design is more advanced. * Address TODO's and XXX's in code :) Thanks @brecht for the review! And @sergey for the complaining ;) Differential Revision: D2758
2018-04-20 17:14:03 +02:00
#endif
/* update deprecated screen member (for so loading in 2.7x uses the correct screen) */
win->screen = BKE_workspace_active_screen_get(win->workspace_hook);
BLO_write_struct(writer, wmWindow, win);
BLO_write_struct(writer, WorkSpaceInstanceHook, win->workspace_hook);
BLO_write_struct(writer, Stereo3dFormat, win->stereo3d_format);
#ifdef WITH_GLOBAL_AREA_WRITING
write_area_map(writer, &win->global_areas);
UI: New Global Top-Bar (WIP) == Main Features/Changes for Users * Add horizontal bar at top of all non-temp windows, consisting out of two horizontal sub-bars. * Upper sub-bar contains global menus (File, Render, etc.), tabs for workspaces and scene selector. * Lower sub-bar contains object mode selector, screen-layout and render-layer selector. Later operator and/or tool settings will be placed here. * Individual sections of the topbar are individually scrollable. * Workspace tabs can be double- or ctrl-clicked for renaming and contain 'x' icon for deleting. * Top-bar should scale nicely with DPI. * The lower half of the top-bar can be hided by dragging the lower top-bar edge up. Better hiding options are planned (e.g. hide in fullscreen modes). * Info editors at the top of the window and using the full window width with be replaced by the top-bar. * In fullscreen modes, no more info editor is added on top, the top-bar replaces it. == Technical Features/Changes * Adds initial support for global areas A global area is part of the window, not part of the regular screen-layout. I've added a macro iterator to iterate over both, global and screen-layout level areas. When iterating over areas, from now on developers should always consider if they have to include global areas. * Adds a TOPBAR editor type The editor type is hidden in the UI editor type menu. * Adds a variation of the ID template to display IDs as tab buttons (template_ID_tabs in BPY) * Does various changes to RNA button creation code to improve their appearance in the horizontal top-bar. * Adds support for dynamically sized regions. That is, regions that scale automatically to the layout bounds. The code for this is currently a big hack (it's based on drawing the UI multiple times). This should definitely be improved. * Adds a template for displaying operator properties optimized for the top-bar. This will probably change a lot still and is in fact disabled in code. Since the final top-bar design depends a lot on other 2.8 designs (mainly tool-system and workspaces), we decided to not show the operator or tool settings in the top-bar for now. That means most of the lower sub-bar is empty for the time being. NOTE: Top-bar or global area data is not written to files or SDNA. They are simply added to the window when opening Blender or reading a file. This allows us doing changes to the top-bar without having to care for compatibility. == ToDo's It's a bit hard to predict all the ToDo's here are the known main ones: * Add options for the new active-tool system and for operator redo to the topbar. * Automatically hide the top-bar in fullscreen modes. * General visual polish. * Top-bar drag & drop support (WIP in temp-tab_drag_drop). * Improve dynamic regions (should also fix some layout glitches). * Make internal terminology consistent. * Enable topbar file writing once design is more advanced. * Address TODO's and XXX's in code :) Thanks @brecht for the review! And @sergey for the complaining ;) Differential Revision: D2758
2018-04-20 17:14:03 +02:00
#else
win->global_areas = global_areas;
UI: New Global Top-Bar (WIP) == Main Features/Changes for Users * Add horizontal bar at top of all non-temp windows, consisting out of two horizontal sub-bars. * Upper sub-bar contains global menus (File, Render, etc.), tabs for workspaces and scene selector. * Lower sub-bar contains object mode selector, screen-layout and render-layer selector. Later operator and/or tool settings will be placed here. * Individual sections of the topbar are individually scrollable. * Workspace tabs can be double- or ctrl-clicked for renaming and contain 'x' icon for deleting. * Top-bar should scale nicely with DPI. * The lower half of the top-bar can be hided by dragging the lower top-bar edge up. Better hiding options are planned (e.g. hide in fullscreen modes). * Info editors at the top of the window and using the full window width with be replaced by the top-bar. * In fullscreen modes, no more info editor is added on top, the top-bar replaces it. == Technical Features/Changes * Adds initial support for global areas A global area is part of the window, not part of the regular screen-layout. I've added a macro iterator to iterate over both, global and screen-layout level areas. When iterating over areas, from now on developers should always consider if they have to include global areas. * Adds a TOPBAR editor type The editor type is hidden in the UI editor type menu. * Adds a variation of the ID template to display IDs as tab buttons (template_ID_tabs in BPY) * Does various changes to RNA button creation code to improve their appearance in the horizontal top-bar. * Adds support for dynamically sized regions. That is, regions that scale automatically to the layout bounds. The code for this is currently a big hack (it's based on drawing the UI multiple times). This should definitely be improved. * Adds a template for displaying operator properties optimized for the top-bar. This will probably change a lot still and is in fact disabled in code. Since the final top-bar design depends a lot on other 2.8 designs (mainly tool-system and workspaces), we decided to not show the operator or tool settings in the top-bar for now. That means most of the lower sub-bar is empty for the time being. NOTE: Top-bar or global area data is not written to files or SDNA. They are simply added to the window when opening Blender or reading a file. This allows us doing changes to the top-bar without having to care for compatibility. == ToDo's It's a bit hard to predict all the ToDo's here are the known main ones: * Add options for the new active-tool system and for operator redo to the topbar. * Automatically hide the top-bar in fullscreen modes. * General visual polish. * Top-bar drag & drop support (WIP in temp-tab_drag_drop). * Improve dynamic regions (should also fix some layout glitches). * Make internal terminology consistent. * Enable topbar file writing once design is more advanced. * Address TODO's and XXX's in code :) Thanks @brecht for the review! And @sergey for the complaining ;) Differential Revision: D2758
2018-04-20 17:14:03 +02:00
#endif
/* data is written, clear deprecated data again */
win->screen = NULL;
}
}
static void write_screen(BlendWriter *writer, bScreen *screen, const void *id_address)
{
/* Screens are reference counted, only saved if used by a workspace. */
if (screen->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
/* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
writestruct_at_address(writer->wd, ID_SCRN, bScreen, 1, id_address, screen);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &screen->id);
write_previews(writer, screen->preview);
/* direct data */
write_area_map(writer, AREAMAP_FROM_SCREEN(screen));
}
2002-10-12 11:37:38 +00:00
}
2020-06-05 20:20:54 +02:00
static void write_bone(BlendWriter *writer, Bone *bone)
2002-10-12 11:37:38 +00:00
{
/* PATCH for upward compatibility after 2.37+ armature recode */
bone->size[0] = bone->size[1] = bone->size[2] = 1.0f;
/* Write this bone */
2020-06-05 20:20:54 +02:00
BLO_write_struct(writer, Bone, bone);
/* Write ID Properties -- and copy this comment EXACTLY for easy finding
* of library blocks that implement this.*/
if (bone->prop) {
IDP_WriteProperty(bone->prop, writer);
}
/* Write Children */
LISTBASE_FOREACH (Bone *, cbone, &bone->childbase) {
2020-06-05 20:20:54 +02:00
write_bone(writer, cbone);
}
2002-10-12 11:37:38 +00:00
}
static void write_armature(BlendWriter *writer, bArmature *arm, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (arm->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
arm->bonehash = NULL;
arm->edbo = NULL;
/* Must always be cleared (armatures don't have their own edit-data). */
arm->needs_flush_to_id = 0;
arm->act_edbone = NULL;
BLO_write_id_struct(writer, bArmature, id_address, &arm->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &arm->id);
if (arm->adt) {
write_animdata(writer, arm->adt);
}
/* Direct data */
LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
2020-06-05 20:20:54 +02:00
write_bone(writer, bone);
}
}
2002-10-12 11:37:38 +00:00
}
static void write_text(BlendWriter *writer, Text *text, const void *id_address)
2002-10-12 11:37:38 +00:00
{
/* Note: we are clearing local temp data here, *not* the flag in the actual 'real' ID. */
if ((text->flags & TXT_ISMEM) && (text->flags & TXT_ISEXT)) {
text->flags &= ~TXT_ISEXT;
}
2020-04-01 10:38:20 +02:00
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
text->compiled = NULL;
/* write LibData */
BLO_write_id_struct(writer, Text, id_address, &text->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &text->id);
if (text->name) {
BLO_write_string(writer, text->name);
}
if (!(text->flags & TXT_ISEXT)) {
/* now write the text data, in two steps for optimization in the readfunction */
LISTBASE_FOREACH (TextLine *, tmp, &text->lines) {
BLO_write_struct(writer, TextLine, tmp);
}
LISTBASE_FOREACH (TextLine *, tmp, &text->lines) {
BLO_write_raw(writer, tmp->len + 1, tmp->line);
}
}
2002-10-12 11:37:38 +00:00
}
static void write_speaker(BlendWriter *writer, Speaker *spk, const void *id_address)
{
if (spk->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Speaker, id_address, &spk->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &spk->id);
if (spk->adt) {
write_animdata(writer, spk->adt);
}
}
}
static void write_sound(BlendWriter *writer, bSound *sound, const void *id_address)
2002-10-12 11:37:38 +00:00
{
if (sound->id.us > 0 || BLO_write_is_undo(writer)) {
2020-04-01 11:43:03 +02:00
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
sound->tags = 0;
sound->handle = NULL;
sound->playback_handle = NULL;
sound->spinlock = NULL;
/* write LibData */
BLO_write_id_struct(writer, bSound, id_address, &sound->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &sound->id);
if (sound->packedfile) {
PackedFile *pf = sound->packedfile;
BLO_write_struct(writer, PackedFile, pf);
BLO_write_raw(writer, pf->size, pf->data);
}
}
2002-10-12 11:37:38 +00:00
}
static void write_probe(BlendWriter *writer, LightProbe *prb, const void *id_address)
{
if (prb->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, LightProbe, id_address, &prb->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &prb->id);
if (prb->adt) {
write_animdata(writer, prb->adt);
}
}
}
static void write_nodetree(BlendWriter *writer, bNodeTree *ntree, const void *id_address)
Orange: more noodle updates! **** NEW: Group Nodes Node trees usually become messy and confusing quickly, so we need not only a way to collapse Nodes into single 'groups', but also a way to re-use that data to create libraries of effects. This has been done by making a new Library data type, the NodeTree. Everything that has been grouped is stored here, and available for re-use, appending or linking. These NodeTrees are fully generic, i.e. can store shader trees, composit trees, and so on. The 'type' value as stored in the NodeTree will keep track of internal type definitions and execute/drawing callbacks. Needless to say, re-using shader trees in a composit tree is a bit useless, and will be prevented in the browsing code. :) So; any NodeTree can become a "Goup Node" inside in a NodeTree. This Group Node then works just like any Node. To prevent the current code to become too complex, I've disabled the possibility to insert Groups inside of Groups. That might be enabled later, but is a real nasty piece of code to get OK. Since Group Nodes are a dynamic Node type, a lot of work has been done to ensure Node definitions can be dynamic too, but still allow to be stored in files, and allow to be verified for type-definition changes on reloading. This system needs a little bit maturing still, so the Python gurus should better wait a little bit! (Also for me to write the definite API docs for it). What works now: - Press CTRL+G to create a new Group. The grouping code checks for impossible selections (like an unselected node between selected nodes). Everthing that's selected then gets removed from the current tree, and inserted in a new NodeTree library data block. A Group Node then is added which links to this new NodeTree. - Press ALT+G to ungroup. This will not delete the NodeTree library data, but just duplicate the Group into the current tree. - Press TAB, or click on the NodeTree icon to edit Groups. Note that NodeTrees are instances, so editing one Group will also change the other users. This also means that when removing nodes in a Group (or hiding sockets or changing internal links) this is immediately corrected for all users of this Group, also in other Materials. - While editing Groups, only the internal Nodes can be edited. A single click outside of the Group boundary will close this 'edit mode'. What needs to be done: - SHIFT+A menu in toolbox style, also including a list of Groups - Enable the single-user button in the Group Node - Displaying all (visible) internal group UI elements in the Node Panel - Enable Library linking and prevent editing of Groups then. **** NEW: Socket Visibility control Node types will be generated with a lot of possible inputs or outputs, and drawing all sockets all the time isn't very useful then. A new option in the Node header ('plus' icon) allows to either hide all unused sockets (first keypress) or to reveil them (when there are hidden sockets, the icon displays black, otherwise it's blended). Hidden sockets in Nodes also are not exported to a Group, so this way you can control what options (in/outputs) exactly are available. To be done: - a way to hide individual sockets, like with a RMB click on it. **** NEW: Nodes now render! This is still quite primitive, more on a level to replace the (now obsolete and disabled) Material Layers. What needs to be done: - make the "Geometry" node work properly, also for AA textures - make the Texture Node work (does very little at the moment) - give Material Nodes all inputs as needed (like Map-to Panel) - find a way to export more data from a Material Node, like the shadow value, or light intensity only, etc Very important also to separate from the Material Buttons the "global" options, like "Ztransp" or "Wire" or "Halo". These can not be set for each Material-Node individually. Also note that the Preview Render (Buttons window) now renders a bit differently. This was a horrid piece of antique code, using a totally incompatible way of rendering. Target is to fully re-use internal render code for previews. OK... that's it mostly. Now test!
2006-01-02 13:06:05 +00:00
{
if (ntree->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
ntree->init = 0; /* to set callbacks and force setting types */
ntree->is_updating = false;
ntree->typeinfo = NULL;
ntree->interface_type = NULL;
ntree->progress = NULL;
ntree->execdata = NULL;
BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id);
/* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot
* be linked, etc., so we write actual id data here only, for 'real' ID trees. */
2020-06-05 14:45:32 +02:00
write_iddata(writer, &ntree->id);
write_nodetree_nolib(writer, ntree);
}
2002-10-12 11:37:38 +00:00
}
static void write_brush(BlendWriter *writer, Brush *brush, const void *id_address)
{
if (brush->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, Brush, id_address, &brush->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &brush->id);
if (brush->curve) {
write_curvemapping(writer, brush->curve);
}
if (brush->gpencil_settings) {
BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings);
if (brush->gpencil_settings->curve_sensitivity) {
write_curvemapping(writer, brush->gpencil_settings->curve_sensitivity);
}
if (brush->gpencil_settings->curve_strength) {
write_curvemapping(writer, brush->gpencil_settings->curve_strength);
}
if (brush->gpencil_settings->curve_jitter) {
write_curvemapping(writer, brush->gpencil_settings->curve_jitter);
}
if (brush->gpencil_settings->curve_rand_pressure) {
write_curvemapping(writer, brush->gpencil_settings->curve_rand_pressure);
}
if (brush->gpencil_settings->curve_rand_strength) {
write_curvemapping(writer, brush->gpencil_settings->curve_rand_strength);
}
if (brush->gpencil_settings->curve_rand_uv) {
write_curvemapping(writer, brush->gpencil_settings->curve_rand_uv);
}
if (brush->gpencil_settings->curve_rand_hue) {
write_curvemapping(writer, brush->gpencil_settings->curve_rand_hue);
}
if (brush->gpencil_settings->curve_rand_saturation) {
write_curvemapping(writer, brush->gpencil_settings->curve_rand_saturation);
}
if (brush->gpencil_settings->curve_rand_value) {
write_curvemapping(writer, brush->gpencil_settings->curve_rand_value);
}
}
if (brush->gradient) {
BLO_write_struct(writer, ColorBand, brush->gradient);
}
}
}
static void write_palette(BlendWriter *writer, Palette *palette, const void *id_address)
{
if (palette->id.us > 0 || BLO_write_is_undo(writer)) {
PaletteColor *color;
BLO_write_id_struct(writer, Palette, id_address, &palette->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &palette->id);
for (color = palette->colors.first; color; color = color->next) {
BLO_write_struct(writer, PaletteColor, color);
}
}
}
static void write_paintcurve(BlendWriter *writer, PaintCurve *pc, const void *id_address)
{
if (pc->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &pc->id);
BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points);
}
}
static void write_movieTracks(BlendWriter *writer, ListBase *tracks)
{
MovieTrackingTrack *track;
track = tracks->first;
while (track) {
BLO_write_struct(writer, MovieTrackingTrack, track);
if (track->markers) {
BLO_write_struct_array(writer, MovieTrackingMarker, track->markersnr, track->markers);
}
track = track->next;
}
}
static void write_moviePlaneTracks(BlendWriter *writer, ListBase *plane_tracks_base)
Merge plane track feature from tomato branch This commit includes all the changes made for plane tracker in tomato branch. Movie clip editor changes: - Artist might create a plane track out of multiple point tracks which belongs to the same track (minimum amount of point tracks is 4, maximum is not actually limited). When new plane track is added, it's getting "tracked" across all point tracks, which makes it stick to the same plane point tracks belong to. - After plane track was added, it need to be manually adjusted in a way it covers feature one might to mask/replace. General transform tools (G, R, S) or sliding corners with a mouse could be sued for this. Plane corner which corresponds to left bottom image corner has got X/Y axis on it (red is for X axis, green for Y). - Re-adjusting plane corners makes plane to be "re-tracked" for the frames sequence between current frame and next and previous keyframes. - Kayframes might be removed from the plane, using Shit-X (Marker Delete) operator. However, currently manual re-adjustment or "re-track" trigger is needed. Compositor changes: - Added new node called Plane Track Deform. - User selects which plane track to use (for this he need to select movie clip datablock, object and track names). - Node gets an image input, which need to be warped into the plane. - Node outputs: * Input image warped into the plane. * Plane, rasterized to a mask. Masking changes: - Mask points might be parented to a plane track, which makes this point deforming in a way as if it belongs to the tracked plane. Some video tutorials are available: - Coder video: http://www.youtube.com/watch?v=vISEwqNHqe4 - Artist video: https://vimeo.com/71727578 This is mine and Keir's holiday code project :)
2013-08-16 09:46:30 +00:00
{
MovieTrackingPlaneTrack *plane_track;
Merge plane track feature from tomato branch This commit includes all the changes made for plane tracker in tomato branch. Movie clip editor changes: - Artist might create a plane track out of multiple point tracks which belongs to the same track (minimum amount of point tracks is 4, maximum is not actually limited). When new plane track is added, it's getting "tracked" across all point tracks, which makes it stick to the same plane point tracks belong to. - After plane track was added, it need to be manually adjusted in a way it covers feature one might to mask/replace. General transform tools (G, R, S) or sliding corners with a mouse could be sued for this. Plane corner which corresponds to left bottom image corner has got X/Y axis on it (red is for X axis, green for Y). - Re-adjusting plane corners makes plane to be "re-tracked" for the frames sequence between current frame and next and previous keyframes. - Kayframes might be removed from the plane, using Shit-X (Marker Delete) operator. However, currently manual re-adjustment or "re-track" trigger is needed. Compositor changes: - Added new node called Plane Track Deform. - User selects which plane track to use (for this he need to select movie clip datablock, object and track names). - Node gets an image input, which need to be warped into the plane. - Node outputs: * Input image warped into the plane. * Plane, rasterized to a mask. Masking changes: - Mask points might be parented to a plane track, which makes this point deforming in a way as if it belongs to the tracked plane. Some video tutorials are available: - Coder video: http://www.youtube.com/watch?v=vISEwqNHqe4 - Artist video: https://vimeo.com/71727578 This is mine and Keir's holiday code project :)
2013-08-16 09:46:30 +00:00
for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) {
BLO_write_struct(writer, MovieTrackingPlaneTrack, plane_track);
Merge plane track feature from tomato branch This commit includes all the changes made for plane tracker in tomato branch. Movie clip editor changes: - Artist might create a plane track out of multiple point tracks which belongs to the same track (minimum amount of point tracks is 4, maximum is not actually limited). When new plane track is added, it's getting "tracked" across all point tracks, which makes it stick to the same plane point tracks belong to. - After plane track was added, it need to be manually adjusted in a way it covers feature one might to mask/replace. General transform tools (G, R, S) or sliding corners with a mouse could be sued for this. Plane corner which corresponds to left bottom image corner has got X/Y axis on it (red is for X axis, green for Y). - Re-adjusting plane corners makes plane to be "re-tracked" for the frames sequence between current frame and next and previous keyframes. - Kayframes might be removed from the plane, using Shit-X (Marker Delete) operator. However, currently manual re-adjustment or "re-track" trigger is needed. Compositor changes: - Added new node called Plane Track Deform. - User selects which plane track to use (for this he need to select movie clip datablock, object and track names). - Node gets an image input, which need to be warped into the plane. - Node outputs: * Input image warped into the plane. * Plane, rasterized to a mask. Masking changes: - Mask points might be parented to a plane track, which makes this point deforming in a way as if it belongs to the tracked plane. Some video tutorials are available: - Coder video: http://www.youtube.com/watch?v=vISEwqNHqe4 - Artist video: https://vimeo.com/71727578 This is mine and Keir's holiday code project :)
2013-08-16 09:46:30 +00:00
BLO_write_pointer_array(writer, plane_track->point_tracksnr, plane_track->point_tracks);
BLO_write_struct_array(
writer, MovieTrackingPlaneMarker, plane_track->markersnr, plane_track->markers);
}
Merge plane track feature from tomato branch This commit includes all the changes made for plane tracker in tomato branch. Movie clip editor changes: - Artist might create a plane track out of multiple point tracks which belongs to the same track (minimum amount of point tracks is 4, maximum is not actually limited). When new plane track is added, it's getting "tracked" across all point tracks, which makes it stick to the same plane point tracks belong to. - After plane track was added, it need to be manually adjusted in a way it covers feature one might to mask/replace. General transform tools (G, R, S) or sliding corners with a mouse could be sued for this. Plane corner which corresponds to left bottom image corner has got X/Y axis on it (red is for X axis, green for Y). - Re-adjusting plane corners makes plane to be "re-tracked" for the frames sequence between current frame and next and previous keyframes. - Kayframes might be removed from the plane, using Shit-X (Marker Delete) operator. However, currently manual re-adjustment or "re-track" trigger is needed. Compositor changes: - Added new node called Plane Track Deform. - User selects which plane track to use (for this he need to select movie clip datablock, object and track names). - Node gets an image input, which need to be warped into the plane. - Node outputs: * Input image warped into the plane. * Plane, rasterized to a mask. Masking changes: - Mask points might be parented to a plane track, which makes this point deforming in a way as if it belongs to the tracked plane. Some video tutorials are available: - Coder video: http://www.youtube.com/watch?v=vISEwqNHqe4 - Artist video: https://vimeo.com/71727578 This is mine and Keir's holiday code project :)
2013-08-16 09:46:30 +00:00
}
static void write_movieReconstruction(BlendWriter *writer,
MovieTrackingReconstruction *reconstruction)
{
if (reconstruction->camnr) {
BLO_write_struct_array(
writer, MovieReconstructedCamera, reconstruction->camnr, reconstruction->cameras);
}
}
static void write_movieclip(BlendWriter *writer, MovieClip *clip, const void *id_address)
Camera tracking integration =========================== Commiting camera tracking integration gsoc project into trunk. This commit includes: - Bundled version of libmv library (with some changes against official repo, re-sync with libmv repo a bit later) - New datatype ID called MovieClip which is optimized to work with movie clips (both of movie files and image sequences) and doing camera/motion tracking operations. - New editor called Clip Editor which is currently used for motion/tracking stuff only, but which can be easily extended to work with masks too. This editor supports: * Loading movie files/image sequences * Build proxies with different size for loaded movie clip, also supports building undistorted proxies to increase speed of playback in undistorted mode. * Manual lens distortion mode calibration using grid and grease pencil * Supervised 2D tracking using two different algorithms KLT and SAD. * Basic algorithm for feature detection * Camera motion solving. scene orientation - New constraints to "link" scene objects with solved motions from clip: * Follow Track (make object follow 2D motion of track with given name or parent object to reconstructed 3D position of track) * Camera Solver to make camera moving in the same way as reconstructed camera This commit NOT includes changes from tomato branch: - New nodes (they'll be commited as separated patch) - Automatic image offset guessing for image input node and image editor (need to do more tests and gather more feedback) - Code cleanup in libmv-capi. It's not so critical cleanup, just increasing readability and understanadability of code. Better to make this chaneg when Keir will finish his current patch. More details about this project can be found on this page: http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011 Further development of small features would be done in trunk, bigger/experimental features would first be implemented in tomato branch.
2011-11-07 12:55:18 +00:00
{
if (clip->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
clip->anim = NULL;
clip->tracking_context = NULL;
clip->tracking.stats = NULL;
MovieTracking *tracking = &clip->tracking;
MovieTrackingObject *object;
Camera tracking integration =========================== Commiting camera tracking integration gsoc project into trunk. This commit includes: - Bundled version of libmv library (with some changes against official repo, re-sync with libmv repo a bit later) - New datatype ID called MovieClip which is optimized to work with movie clips (both of movie files and image sequences) and doing camera/motion tracking operations. - New editor called Clip Editor which is currently used for motion/tracking stuff only, but which can be easily extended to work with masks too. This editor supports: * Loading movie files/image sequences * Build proxies with different size for loaded movie clip, also supports building undistorted proxies to increase speed of playback in undistorted mode. * Manual lens distortion mode calibration using grid and grease pencil * Supervised 2D tracking using two different algorithms KLT and SAD. * Basic algorithm for feature detection * Camera motion solving. scene orientation - New constraints to "link" scene objects with solved motions from clip: * Follow Track (make object follow 2D motion of track with given name or parent object to reconstructed 3D position of track) * Camera Solver to make camera moving in the same way as reconstructed camera This commit NOT includes changes from tomato branch: - New nodes (they'll be commited as separated patch) - Automatic image offset guessing for image input node and image editor (need to do more tests and gather more feedback) - Code cleanup in libmv-capi. It's not so critical cleanup, just increasing readability and understanadability of code. Better to make this chaneg when Keir will finish his current patch. More details about this project can be found on this page: http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011 Further development of small features would be done in trunk, bigger/experimental features would first be implemented in tomato branch.
2011-11-07 12:55:18 +00:00
BLO_write_id_struct(writer, MovieClip, id_address, &clip->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &clip->id);
if (clip->adt) {
write_animdata(writer, clip->adt);
}
write_movieTracks(writer, &tracking->tracks);
write_moviePlaneTracks(writer, &tracking->plane_tracks);
write_movieReconstruction(writer, &tracking->reconstruction);
Camera tracking integration =========================== Commiting camera tracking integration gsoc project into trunk. This commit includes: - Bundled version of libmv library (with some changes against official repo, re-sync with libmv repo a bit later) - New datatype ID called MovieClip which is optimized to work with movie clips (both of movie files and image sequences) and doing camera/motion tracking operations. - New editor called Clip Editor which is currently used for motion/tracking stuff only, but which can be easily extended to work with masks too. This editor supports: * Loading movie files/image sequences * Build proxies with different size for loaded movie clip, also supports building undistorted proxies to increase speed of playback in undistorted mode. * Manual lens distortion mode calibration using grid and grease pencil * Supervised 2D tracking using two different algorithms KLT and SAD. * Basic algorithm for feature detection * Camera motion solving. scene orientation - New constraints to "link" scene objects with solved motions from clip: * Follow Track (make object follow 2D motion of track with given name or parent object to reconstructed 3D position of track) * Camera Solver to make camera moving in the same way as reconstructed camera This commit NOT includes changes from tomato branch: - New nodes (they'll be commited as separated patch) - Automatic image offset guessing for image input node and image editor (need to do more tests and gather more feedback) - Code cleanup in libmv-capi. It's not so critical cleanup, just increasing readability and understanadability of code. Better to make this chaneg when Keir will finish his current patch. More details about this project can be found on this page: http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011 Further development of small features would be done in trunk, bigger/experimental features would first be implemented in tomato branch.
2011-11-07 12:55:18 +00:00
object = tracking->objects.first;
while (object) {
BLO_write_struct(writer, MovieTrackingObject, object);
Camera tracking integration =========================== Commiting camera tracking integration gsoc project into trunk. This commit includes: - Bundled version of libmv library (with some changes against official repo, re-sync with libmv repo a bit later) - New datatype ID called MovieClip which is optimized to work with movie clips (both of movie files and image sequences) and doing camera/motion tracking operations. - New editor called Clip Editor which is currently used for motion/tracking stuff only, but which can be easily extended to work with masks too. This editor supports: * Loading movie files/image sequences * Build proxies with different size for loaded movie clip, also supports building undistorted proxies to increase speed of playback in undistorted mode. * Manual lens distortion mode calibration using grid and grease pencil * Supervised 2D tracking using two different algorithms KLT and SAD. * Basic algorithm for feature detection * Camera motion solving. scene orientation - New constraints to "link" scene objects with solved motions from clip: * Follow Track (make object follow 2D motion of track with given name or parent object to reconstructed 3D position of track) * Camera Solver to make camera moving in the same way as reconstructed camera This commit NOT includes changes from tomato branch: - New nodes (they'll be commited as separated patch) - Automatic image offset guessing for image input node and image editor (need to do more tests and gather more feedback) - Code cleanup in libmv-capi. It's not so critical cleanup, just increasing readability and understanadability of code. Better to make this chaneg when Keir will finish his current patch. More details about this project can be found on this page: http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011 Further development of small features would be done in trunk, bigger/experimental features would first be implemented in tomato branch.
2011-11-07 12:55:18 +00:00
write_movieTracks(writer, &object->tracks);
write_moviePlaneTracks(writer, &object->plane_tracks);
write_movieReconstruction(writer, &object->reconstruction);
Camera tracking integration =========================== Commiting camera tracking integration gsoc project into trunk. This commit includes: - Bundled version of libmv library (with some changes against official repo, re-sync with libmv repo a bit later) - New datatype ID called MovieClip which is optimized to work with movie clips (both of movie files and image sequences) and doing camera/motion tracking operations. - New editor called Clip Editor which is currently used for motion/tracking stuff only, but which can be easily extended to work with masks too. This editor supports: * Loading movie files/image sequences * Build proxies with different size for loaded movie clip, also supports building undistorted proxies to increase speed of playback in undistorted mode. * Manual lens distortion mode calibration using grid and grease pencil * Supervised 2D tracking using two different algorithms KLT and SAD. * Basic algorithm for feature detection * Camera motion solving. scene orientation - New constraints to "link" scene objects with solved motions from clip: * Follow Track (make object follow 2D motion of track with given name or parent object to reconstructed 3D position of track) * Camera Solver to make camera moving in the same way as reconstructed camera This commit NOT includes changes from tomato branch: - New nodes (they'll be commited as separated patch) - Automatic image offset guessing for image input node and image editor (need to do more tests and gather more feedback) - Code cleanup in libmv-capi. It's not so critical cleanup, just increasing readability and understanadability of code. Better to make this chaneg when Keir will finish his current patch. More details about this project can be found on this page: http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011 Further development of small features would be done in trunk, bigger/experimental features would first be implemented in tomato branch.
2011-11-07 12:55:18 +00:00
object = object->next;
}
}
Camera tracking integration =========================== Commiting camera tracking integration gsoc project into trunk. This commit includes: - Bundled version of libmv library (with some changes against official repo, re-sync with libmv repo a bit later) - New datatype ID called MovieClip which is optimized to work with movie clips (both of movie files and image sequences) and doing camera/motion tracking operations. - New editor called Clip Editor which is currently used for motion/tracking stuff only, but which can be easily extended to work with masks too. This editor supports: * Loading movie files/image sequences * Build proxies with different size for loaded movie clip, also supports building undistorted proxies to increase speed of playback in undistorted mode. * Manual lens distortion mode calibration using grid and grease pencil * Supervised 2D tracking using two different algorithms KLT and SAD. * Basic algorithm for feature detection * Camera motion solving. scene orientation - New constraints to "link" scene objects with solved motions from clip: * Follow Track (make object follow 2D motion of track with given name or parent object to reconstructed 3D position of track) * Camera Solver to make camera moving in the same way as reconstructed camera This commit NOT includes changes from tomato branch: - New nodes (they'll be commited as separated patch) - Automatic image offset guessing for image input node and image editor (need to do more tests and gather more feedback) - Code cleanup in libmv-capi. It's not so critical cleanup, just increasing readability and understanadability of code. Better to make this chaneg when Keir will finish his current patch. More details about this project can be found on this page: http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011 Further development of small features would be done in trunk, bigger/experimental features would first be implemented in tomato branch.
2011-11-07 12:55:18 +00:00
}
static void write_mask(BlendWriter *writer, Mask *mask, const void *id_address)
{
if (mask->id.us > 0 || BLO_write_is_undo(writer)) {
MaskLayer *masklay;
BLO_write_id_struct(writer, Mask, id_address, &mask->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &mask->id);
if (mask->adt) {
write_animdata(writer, mask->adt);
}
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
MaskSpline *spline;
MaskLayerShape *masklay_shape;
BLO_write_struct(writer, MaskLayer, masklay);
for (spline = masklay->splines.first; spline; spline = spline->next) {
int i;
void *points_deform = spline->points_deform;
spline->points_deform = NULL;
BLO_write_struct(writer, MaskSpline, spline);
BLO_write_struct_array(writer, MaskSplinePoint, spline->tot_point, spline->points);
spline->points_deform = points_deform;
for (i = 0; i < spline->tot_point; i++) {
MaskSplinePoint *point = &spline->points[i];
if (point->tot_uw) {
BLO_write_struct_array(writer, MaskSplinePointUW, point->tot_uw, point->uw);
}
}
}
for (masklay_shape = masklay->splines_shapes.first; masklay_shape;
masklay_shape = masklay_shape->next) {
BLO_write_struct(writer, MaskLayerShape, masklay_shape);
BLO_write_float_array(
writer, masklay_shape->tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data);
}
}
}
}
static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modifiers)
{
LineStyleModifier *m;
for (m = modifiers->first; m; m = m->next) {
int struct_nr;
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_AlongStroke);
break;
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromCamera);
break;
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromObject);
break;
case LS_MODIFIER_MATERIAL:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Material);
break;
case LS_MODIFIER_TANGENT:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Tangent);
break;
case LS_MODIFIER_NOISE:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Noise);
break;
case LS_MODIFIER_CREASE_ANGLE:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_CreaseAngle);
break;
case LS_MODIFIER_CURVATURE_3D:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Curvature_3D);
break;
default:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */
}
BLO_write_struct_by_id(writer, struct_nr, m);
}
for (m = modifiers->first; m; m = m->next) {
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp);
break;
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
BLO_write_struct(
writer, ColorBand, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp);
break;
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
BLO_write_struct(
writer, ColorBand, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp);
break;
case LS_MODIFIER_MATERIAL:
BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Material *)m)->color_ramp);
break;
case LS_MODIFIER_TANGENT:
BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Tangent *)m)->color_ramp);
break;
case LS_MODIFIER_NOISE:
BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Noise *)m)->color_ramp);
break;
case LS_MODIFIER_CREASE_ANGLE:
BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp);
break;
case LS_MODIFIER_CURVATURE_3D:
BLO_write_struct(
writer, ColorBand, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp);
break;
}
}
}
static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modifiers)
{
LineStyleModifier *m;
for (m = modifiers->first; m; m = m->next) {
int struct_nr;
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_AlongStroke);
break;
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromCamera);
break;
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromObject);
break;
case LS_MODIFIER_MATERIAL:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Material);
break;
case LS_MODIFIER_TANGENT:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Tangent);
break;
case LS_MODIFIER_NOISE:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Noise);
break;
case LS_MODIFIER_CREASE_ANGLE:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_CreaseAngle);
break;
case LS_MODIFIER_CURVATURE_3D:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Curvature_3D);
break;
default:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */
}
BLO_write_struct_by_id(writer, struct_nr, m);
}
for (m = modifiers->first; m; m = m->next) {
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
write_curvemapping(writer, ((LineStyleAlphaModifier_AlongStroke *)m)->curve);
break;
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
write_curvemapping(writer, ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve);
break;
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
write_curvemapping(writer, ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve);
break;
case LS_MODIFIER_MATERIAL:
write_curvemapping(writer, ((LineStyleAlphaModifier_Material *)m)->curve);
break;
case LS_MODIFIER_TANGENT:
write_curvemapping(writer, ((LineStyleAlphaModifier_Tangent *)m)->curve);
break;
case LS_MODIFIER_NOISE:
write_curvemapping(writer, ((LineStyleAlphaModifier_Noise *)m)->curve);
break;
case LS_MODIFIER_CREASE_ANGLE:
write_curvemapping(writer, ((LineStyleAlphaModifier_CreaseAngle *)m)->curve);
break;
case LS_MODIFIER_CURVATURE_3D:
write_curvemapping(writer, ((LineStyleAlphaModifier_Curvature_3D *)m)->curve);
break;
}
}
}
static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *modifiers)
{
LineStyleModifier *m;
for (m = modifiers->first; m; m = m->next) {
int struct_nr;
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_AlongStroke);
break;
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromCamera);
break;
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromObject);
break;
case LS_MODIFIER_MATERIAL:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Material);
break;
case LS_MODIFIER_CALLIGRAPHY:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Calligraphy);
break;
case LS_MODIFIER_TANGENT:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Tangent);
break;
case LS_MODIFIER_NOISE:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Noise);
break;
case LS_MODIFIER_CREASE_ANGLE:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_CreaseAngle);
break;
case LS_MODIFIER_CURVATURE_3D:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Curvature_3D);
break;
default:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */
}
BLO_write_struct_by_id(writer, struct_nr, m);
}
for (m = modifiers->first; m; m = m->next) {
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
write_curvemapping(writer, ((LineStyleThicknessModifier_AlongStroke *)m)->curve);
break;
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
write_curvemapping(writer, ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve);
break;
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
write_curvemapping(writer, ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve);
break;
case LS_MODIFIER_MATERIAL:
write_curvemapping(writer, ((LineStyleThicknessModifier_Material *)m)->curve);
break;
case LS_MODIFIER_TANGENT:
write_curvemapping(writer, ((LineStyleThicknessModifier_Tangent *)m)->curve);
break;
case LS_MODIFIER_CREASE_ANGLE:
write_curvemapping(writer, ((LineStyleThicknessModifier_CreaseAngle *)m)->curve);
break;
case LS_MODIFIER_CURVATURE_3D:
write_curvemapping(writer, ((LineStyleThicknessModifier_Curvature_3D *)m)->curve);
break;
}
}
}
static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *modifiers)
{
LineStyleModifier *m;
for (m = modifiers->first; m; m = m->next) {
int struct_nr;
switch (m->type) {
case LS_MODIFIER_SAMPLING:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Sampling);
break;
case LS_MODIFIER_BEZIER_CURVE:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BezierCurve);
break;
case LS_MODIFIER_SINUS_DISPLACEMENT:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SinusDisplacement);
break;
case LS_MODIFIER_SPATIAL_NOISE:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SpatialNoise);
break;
case LS_MODIFIER_PERLIN_NOISE_1D:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise1D);
break;
case LS_MODIFIER_PERLIN_NOISE_2D:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise2D);
break;
case LS_MODIFIER_BACKBONE_STRETCHER:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BackboneStretcher);
break;
case LS_MODIFIER_TIP_REMOVER:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_TipRemover);
break;
case LS_MODIFIER_POLYGONIZATION:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Polygonalization);
break;
case LS_MODIFIER_GUIDING_LINES:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_GuidingLines);
break;
case LS_MODIFIER_BLUEPRINT:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Blueprint);
break;
case LS_MODIFIER_2D_OFFSET:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DOffset);
break;
case LS_MODIFIER_2D_TRANSFORM:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DTransform);
break;
case LS_MODIFIER_SIMPLIFICATION:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Simplification);
break;
default:
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */
}
BLO_write_struct_by_id(writer, struct_nr, m);
}
}
static void write_linestyle(BlendWriter *writer,
FreestyleLineStyle *linestyle,
const void *id_address)
{
if (linestyle->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &linestyle->id);
if (linestyle->adt) {
write_animdata(writer, linestyle->adt);
}
write_linestyle_color_modifiers(writer, &linestyle->color_modifiers);
write_linestyle_alpha_modifiers(writer, &linestyle->alpha_modifiers);
write_linestyle_thickness_modifiers(writer, &linestyle->thickness_modifiers);
write_linestyle_geometry_modifiers(writer, &linestyle->geometry_modifiers);
for (int a = 0; a < MAX_MTEX; a++) {
if (linestyle->mtex[a]) {
BLO_write_struct(writer, MTex, linestyle->mtex[a]);
}
}
if (linestyle->nodetree) {
BLO_write_struct(writer, bNodeTree, linestyle->nodetree);
write_nodetree_nolib(writer, linestyle->nodetree);
}
}
}
static void write_cachefile(BlendWriter *writer, CacheFile *cache_file, const void *id_address)
{
if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&cache_file->object_paths);
cache_file->handle = NULL;
memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath));
cache_file->handle_readers = NULL;
BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id);
if (cache_file->adt) {
write_animdata(writer, cache_file->adt);
}
}
}
static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const void *id_address)
{
BLO_write_id_struct(writer, WorkSpace, id_address, &workspace->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &workspace->id);
BLO_write_struct_list(writer, WorkSpaceLayout, &workspace->layouts);
BLO_write_struct_list(writer, WorkSpaceDataRelation, &workspace->hook_layout_relations);
BLO_write_struct_list(writer, wmOwnerID, &workspace->owner_ids);
BLO_write_struct_list(writer, bToolRef, &workspace->tools);
LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) {
if (tref->properties) {
IDP_WriteProperty(tref->properties, writer);
}
}
Main Workspace Integration This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup) Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know! (Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.) == Main Changes/Features * Introduces the new Workspaces as data-blocks. * Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces. * Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces). * Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead. * Store screen-layouts (`bScreen`) per workspace. * Store an active screen-layout per workspace. Changing the workspace will enable this layout. * Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.) * Store an active render layer per workspace. * Moved mode switch from 3D View header to Info Editor header. * Store active scene in window (not directly workspace related, but overlaps quite a bit). * Removed 'Use Global Scene' User Preference option. * Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well. * Default .blend only contains one workspace ("General"). * Support appending workspaces. Opening files without UI and commandline rendering should work fine. Note that the UI is temporary! We plan to introduce a new global topbar that contains the workspace options and tabs for switching workspaces. == Technical Notes * Workspaces are data-blocks. * Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now. * A workspace can be active in multiple windows at the same time. * The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned). * The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that). * Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs. * `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those. * Added scene operators `SCENE_OT_`. Was previously done through screen operators. == BPY API Changes * Removed `Screen.scene`, added `Window.scene` * Removed `UserPreferencesView.use_global_scene` * Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces` * Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer` * Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name) == What's left? * There are a few open design questions (T50521). We should find the needed answers and implement them. * Allow adding and removing individual workspaces from workspace configuration (needs UI design). * Get the override system ready and support overrides per workspace. * Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc). * Allow enabling add-ons per workspace. * Support custom workspace keymaps. * Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later. * Get the topbar done. * Workspaces need a proper icon, current one is just a placeholder :) Reviewed By: campbellbarton, mont29 Tags: #user_interface, #bf_blender_2.8 Maniphest Tasks: T50521 Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
}
static void write_hair(BlendWriter *writer, Hair *hair, const void *id_address)
{
if (hair->id.us > 0 || BLO_write_is_undo(writer)) {
CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE];
CustomData_file_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
CustomData_file_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
/* Write LibData */
BLO_write_id_struct(writer, Hair, id_address, &hair->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &hair->id);
/* Direct data */
write_customdata(writer, &hair->id, hair->totpoint, &hair->pdata, players, CD_MASK_ALL);
write_customdata(writer, &hair->id, hair->totcurve, &hair->cdata, clayers, CD_MASK_ALL);
BLO_write_pointer_array(writer, hair->totcol, hair->mat);
if (hair->adt) {
write_animdata(writer, hair->adt);
}
/* Remove temporary data. */
if (players && players != players_buff) {
MEM_freeN(players);
}
if (clayers && clayers != clayers_buff) {
MEM_freeN(clayers);
}
}
}
static void write_pointcloud(BlendWriter *writer, PointCloud *pointcloud, const void *id_address)
{
if (pointcloud->id.us > 0 || BLO_write_is_undo(writer)) {
CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
CustomData_file_write_prepare(
&pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
/* Write LibData */
BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &pointcloud->id);
/* Direct data */
write_customdata(
writer, &pointcloud->id, pointcloud->totpoint, &pointcloud->pdata, players, CD_MASK_ALL);
BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat);
if (pointcloud->adt) {
write_animdata(writer, pointcloud->adt);
}
/* Remove temporary data. */
if (players && players != players_buff) {
MEM_freeN(players);
}
}
}
static void write_volume(BlendWriter *writer, Volume *volume, const void *id_address)
{
if (volume->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
volume->runtime.grids = 0;
/* write LibData */
BLO_write_id_struct(writer, Volume, id_address, &volume->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &volume->id);
/* direct data */
BLO_write_pointer_array(writer, volume->totcol, volume->mat);
if (volume->adt) {
write_animdata(writer, volume->adt);
}
if (volume->packedfile) {
PackedFile *pf = volume->packedfile;
BLO_write_struct(writer, PackedFile, pf);
BLO_write_raw(writer, pf->size, pf->data);
}
}
}
static void write_simulation(BlendWriter *writer, Simulation *simulation, const void *id_address)
{
if (simulation->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, Simulation, id_address, &simulation->id);
2020-06-05 14:45:32 +02:00
write_iddata(writer, &simulation->id);
if (simulation->adt) {
write_animdata(writer, simulation->adt);
}
/* nodetree is integral part of simulation, no libdata */
if (simulation->nodetree) {
BLO_write_struct(writer, bNodeTree, simulation->nodetree);
write_nodetree_nolib(writer, simulation->nodetree);
}
LISTBASE_FOREACH (SimulationState *, state, &simulation->states) {
switch ((eSimulationStateType)state->type) {
case SIM_STATE_TYPE_PARTICLES: {
ParticleSimulationState *particle_state = (ParticleSimulationState *)state;
BLO_write_struct(writer, ParticleSimulationState, particle_state);
CustomDataLayer *layers = NULL;
CustomDataLayer layers_buff[CD_TEMP_CHUNK_SIZE];
CustomData_file_write_prepare(
&particle_state->attributes, &layers, layers_buff, ARRAY_SIZE(layers_buff));
write_customdata(writer,
&simulation->id,
particle_state->tot_particles,
&particle_state->attributes,
layers,
CD_MASK_ALL);
write_pointcaches(writer, &particle_state->ptcaches);
break;
}
}
}
}
}
/* Keep it last of write_foodata functions. */
static void write_libraries(WriteData *wd, Main *main)
{
ListBase *lbarray[MAX_LIBARRAY];
ID *id;
int a, tot;
bool found_one;
for (; main; main = main->next) {
a = tot = set_listbasepointers(main, lbarray);
/* test: is lib being used */
if (main->curlib && main->curlib->packedfile) {
found_one = true;
}
else if (wd->use_memfile) {
/* When writing undo step we always write all existing libraries, makes reading undo step
* much easier when dealing with purely indirectly used libraries. */
found_one = true;
}
else {
found_one = false;
while (!found_one && tot--) {
for (id = lbarray[tot]->first; id; id = id->next) {
if (id->us > 0 &&
((id->tag & LIB_TAG_EXTERN) ||
((id->tag & LIB_TAG_INDIRECT) && (id->flag & LIB_INDIRECT_WEAK_LINK)))) {
found_one = true;
break;
}
}
}
}
/* To be able to restore 'quit.blend' and temp saves,
* the packed blend has to be in undo buffers... */
/* XXX needs rethink, just like save UI in undo files now -
* would be nice to append things only for the 'quit.blend' and temp saves. */
if (found_one) {
/* Not overridable. */
2020-06-05 14:45:32 +02:00
BlendWriter writer = {wd};
writestruct(wd, ID_LI, Library, 1, main->curlib);
2020-06-05 14:45:32 +02:00
write_iddata(&writer, &main->curlib->id);
if (main->curlib->packedfile) {
PackedFile *pf = main->curlib->packedfile;
writestruct(wd, DATA, PackedFile, 1, pf);
writedata(wd, DATA, pf->size, pf->data);
if (wd->use_memfile == false) {
printf("write packed .blend: %s\n", main->curlib->name);
}
}
/* Write link placeholders for all direct linked IDs. */
while (a--) {
for (id = lbarray[a]->first; id; id = id->next) {
if (id->us > 0 &&
((id->tag & LIB_TAG_EXTERN) ||
((id->tag & LIB_TAG_INDIRECT) && (id->flag & LIB_INDIRECT_WEAK_LINK)))) {
if (!BKE_idtype_idcode_is_linkable(GS(id->name))) {
printf(
"ERROR: write file: data-block '%s' from lib '%s' is not linkable "
"but is flagged as directly linked",
id->name,
main->curlib->filepath);
BLI_assert(0);
}
writestruct(wd, ID_LINK_PLACEHOLDER, ID, 1, id);
}
}
}
}
}
mywrite_flush(wd);
}
/* context is usually defined by WM, two cases where no WM is available:
Merge of trunk into blender 2.5: svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r12987:17416 Issues: * GHOST/X11 had conflicting changes. Some code was added in 2.5, which was later added in trunk also, but reverted partially, specifically revision 16683. I have left out this reversion in the 2.5 branch since I think it is needed there. http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16683 * Scons had various conflicting changes, I decided to go with trunk version for everything except priorities and some library renaming. * In creator.c, there were various fixes and fixes for fixes related to the -w -W and -p options. In 2.5 -w and -W is not coded yet, and -p is done differently. Since this is changed so much, and I don't think those fixes would be needed in 2.5, I've left them out. * Also in creator.c: there was code for a python bugfix where the screen was not initialized when running with -P. The code that initializes the screen there I had to disable, that can't work in 2.5 anymore but left it commented as a reminder. Further I had to disable some new function calls. using src/ and python/, as was done already in this branch, disabled function calls: * bpath.c: error reporting * BME_conversions.c: editmesh conversion functions. * SHD_dynamic: disabled almost completely, there is no python/. * KX_PythonInit.cpp and Ketsji/ build files: Mathutils is not there, disabled. * text.c: clipboard copy call. * object.c: OB_SUPPORT_MATERIAL. * DerivedMesh.c and subsurf_ccg, stipple_quarttone. Still to be done: * Go over files and functions that were moved to a different location but could still use changes that were done in trunk.
2008-11-12 21:16:53 +00:00
* - for forward compatibility, curscreen has to be saved
* - for undofile, curscene needs to be saved */
static void write_global(WriteData *wd, int fileflags, Main *mainvar)
2002-10-12 11:37:38 +00:00
{
const bool is_undo = wd->use_memfile;
FileGlobal fg;
bScreen *screen;
Scene *scene;
ViewLayer *view_layer;
char subvstr[8];
/* prevent mem checkers from complaining */
memset(fg._pad, 0, sizeof(fg._pad));
memset(fg.filename, 0, sizeof(fg.filename));
memset(fg.build_hash, 0, sizeof(fg.build_hash));
fg._pad1 = NULL;
current_screen_compat(mainvar, is_undo, &screen, &scene, &view_layer);
/* XXX still remap G */
fg.curscreen = screen;
fg.curscene = scene;
fg.cur_view_layer = view_layer;
/* prevent to save this, is not good convention, and feature with concerns... */
fg.fileflags = (fileflags & ~G_FILE_FLAG_ALL_RUNTIME);
fg.globalf = G.f;
BLI_strncpy(fg.filename, mainvar->name, sizeof(fg.filename));
sprintf(subvstr, "%4d", BLENDER_FILE_SUBVERSION);
memcpy(fg.subvstr, subvstr, 4);
fg.subversion = BLENDER_FILE_SUBVERSION;
fg.minversion = BLENDER_FILE_MIN_VERSION;
fg.minsubversion = BLENDER_FILE_MIN_SUBVERSION;
#ifdef WITH_BUILDINFO
{
extern unsigned long build_commit_timestamp;
extern char build_hash[];
/* TODO(sergey): Add branch name to file as well? */
fg.build_commit_timestamp = build_commit_timestamp;
BLI_strncpy(fg.build_hash, build_hash, sizeof(fg.build_hash));
}
#else
fg.build_commit_timestamp = 0;
BLI_strncpy(fg.build_hash, "unknown", sizeof(fg.build_hash));
#endif
writestruct(wd, GLOB, FileGlobal, 1, &fg);
2002-10-12 11:37:38 +00:00
}
/* preview image, first 2 values are width and height
2018-11-30 14:51:16 +11:00
* second are an RGBA image (uchar)
* note, this uses 'TEST' since new types will segfault on file load for older blender versions.
*/
static void write_thumb(WriteData *wd, const BlendThumbnail *thumb)
{
if (thumb) {
writedata(wd, TEST, BLEN_THUMB_MEMSIZE_FILE(thumb->width, thumb->height), thumb);
}
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name File Writing (Private)
* \{ */
/* if MemFile * there's filesave to memory */
static bool write_file_handle(Main *mainvar,
WriteWrap *ww,
MemFile *compare,
MemFile *current,
int write_flags,
const BlendThumbnail *thumb)
2002-10-12 11:37:38 +00:00
{
BHead bhead;
ListBase mainlist;
char buf[16];
WriteData *wd;
blo_split_main(&mainlist, mainvar);
wd = mywrite_begin(ww, compare, current);
2020-06-05 21:19:03 +02:00
BlendWriter writer = {wd};
sprintf(buf,
"BLENDER%c%c%.3d",
(sizeof(void *) == 8) ? '-' : '_',
(ENDIAN_ORDER == B_ENDIAN) ? 'V' : 'v',
BLENDER_FILE_VERSION);
mywrite(wd, buf, 12);
write_renderinfo(wd, mainvar);
write_thumb(wd, thumb);
write_global(wd, write_flags, mainvar);
/* The windowmanager and screen often change,
* avoid thumbnail detecting changes because of this. */
mywrite_flush(wd);
OverrideLibraryStorage *override_storage =
wd->use_memfile ? NULL : BKE_lib_override_library_operations_store_initialize();
#define ID_BUFFER_STATIC_SIZE 8192
2019-06-12 09:04:10 +10:00
/* This outer loop allows to save first data-blocks from real mainvar,
* then the temp ones from override process,
* if needed, without duplicating whole code. */
Main *bmain = mainvar;
do {
ListBase *lbarray[MAX_LIBARRAY];
int a = set_listbasepointers(bmain, lbarray);
while (a--) {
ID *id = lbarray[a]->first;
if (id == NULL || GS(id->name) == ID_LI) {
continue; /* Libraries are handled separately below. */
}
char id_buffer_static[ID_BUFFER_STATIC_SIZE];
void *id_buffer = id_buffer_static;
const size_t idtype_struct_size = BKE_idtype_get_info_from_id(id)->struct_size;
if (idtype_struct_size > ID_BUFFER_STATIC_SIZE) {
BLI_assert(0);
id_buffer = MEM_mallocN(idtype_struct_size, __func__);
}
for (; id; id = id->next) {
/* We should never attempt to write non-regular IDs
* (i.e. all kind of temp/runtime ones). */
BLI_assert(
(id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0);
const bool do_override = !ELEM(override_storage, NULL, bmain) && id->override_library;
if (do_override) {
BKE_lib_override_library_operations_store_start(bmain, override_storage, id);
}
if (wd->use_memfile) {
/* Record the changes that happened up to this undo push in
* recalc_up_to_undo_push, and clear recalc_after_undo_push again
* to start accumulating for the next undo push. */
id->recalc_up_to_undo_push = id->recalc_after_undo_push;
id->recalc_after_undo_push = 0;
bNodeTree *nodetree = ntreeFromID(id);
if (nodetree != NULL) {
nodetree->id.recalc_up_to_undo_push = nodetree->id.recalc_after_undo_push;
nodetree->id.recalc_after_undo_push = 0;
}
if (GS(id->name) == ID_SCE) {
Scene *scene = (Scene *)id;
if (scene->master_collection != NULL) {
scene->master_collection->id.recalc_up_to_undo_push =
scene->master_collection->id.recalc_after_undo_push;
scene->master_collection->id.recalc_after_undo_push = 0;
}
}
}
mywrite_id_begin(wd, id);
memcpy(id_buffer, id, idtype_struct_size);
((ID *)id_buffer)->tag = 0;
2020-06-05 14:34:00 +10:00
/* Those listbase data change every time we add/remove an ID, and also often when renaming
* one (due to re-sorting). This avoids generating a lot of false 'is changed' detections
* between undo steps. */
((ID *)id_buffer)->prev = NULL;
((ID *)id_buffer)->next = NULL;
switch ((ID_Type)GS(id->name)) {
case ID_WM:
write_windowmanager(&writer, (wmWindowManager *)id_buffer, id);
break;
case ID_WS:
write_workspace(&writer, (WorkSpace *)id_buffer, id);
break;
case ID_SCR:
write_screen(&writer, (bScreen *)id_buffer, id);
break;
case ID_MC:
write_movieclip(&writer, (MovieClip *)id_buffer, id);
break;
case ID_MSK:
write_mask(&writer, (Mask *)id_buffer, id);
break;
case ID_SCE:
2020-06-05 13:55:33 +02:00
write_scene(&writer, (Scene *)id_buffer, id);
break;
case ID_CU:
write_curve(&writer, (Curve *)id_buffer, id);
break;
case ID_MB:
write_mball(&writer, (MetaBall *)id_buffer, id);
break;
case ID_IM:
write_image(&writer, (Image *)id_buffer, id);
break;
case ID_CA:
write_camera(&writer, (Camera *)id_buffer, id);
break;
case ID_LA:
write_light(&writer, (Light *)id_buffer, id);
break;
case ID_LT:
write_lattice(&writer, (Lattice *)id_buffer, id);
break;
case ID_VF:
write_vfont(&writer, (VFont *)id_buffer, id);
break;
case ID_KE:
write_key(&writer, (Key *)id_buffer, id);
break;
case ID_WO:
write_world(&writer, (World *)id_buffer, id);
break;
case ID_TXT:
write_text(&writer, (Text *)id_buffer, id);
break;
case ID_SPK:
write_speaker(&writer, (Speaker *)id_buffer, id);
break;
case ID_LP:
write_probe(&writer, (LightProbe *)id_buffer, id);
break;
case ID_SO:
write_sound(&writer, (bSound *)id_buffer, id);
break;
case ID_GR:
write_collection(&writer, (Collection *)id_buffer, id);
break;
case ID_AR:
write_armature(&writer, (bArmature *)id_buffer, id);
break;
case ID_AC:
write_action(&writer, (bAction *)id_buffer, id);
break;
case ID_OB:
write_object(&writer, (Object *)id_buffer, id);
break;
case ID_MA:
write_material(&writer, (Material *)id_buffer, id);
break;
case ID_TE:
write_texture(&writer, (Tex *)id_buffer, id);
break;
case ID_ME:
write_mesh(&writer, (Mesh *)id_buffer, id);
break;
case ID_PA:
write_particlesettings(&writer, (ParticleSettings *)id_buffer, id);
break;
case ID_NT:
write_nodetree(&writer, (bNodeTree *)id_buffer, id);
break;
case ID_BR:
write_brush(&writer, (Brush *)id_buffer, id);
break;
case ID_PAL:
write_palette(&writer, (Palette *)id_buffer, id);
break;
case ID_PC:
write_paintcurve(&writer, (PaintCurve *)id_buffer, id);
break;
case ID_GD:
write_gpencil(&writer, (bGPdata *)id_buffer, id);
break;
case ID_LS:
write_linestyle(&writer, (FreestyleLineStyle *)id_buffer, id);
break;
case ID_CF:
write_cachefile(&writer, (CacheFile *)id_buffer, id);
break;
case ID_HA:
write_hair(&writer, (Hair *)id_buffer, id);
break;
case ID_PT:
write_pointcloud(&writer, (PointCloud *)id_buffer, id);
break;
case ID_VO:
write_volume(&writer, (Volume *)id_buffer, id);
break;
case ID_SIM:
write_simulation(&writer, (Simulation *)id_buffer, id);
break;
case ID_LI:
/* Do nothing, handled below - and should never be reached. */
BLI_assert(0);
break;
case ID_IP:
/* Do nothing, deprecated. */
break;
default:
/* Should never be reached. */
BLI_assert(0);
break;
}
if (do_override) {
BKE_lib_override_library_operations_store_end(override_storage, id);
}
mywrite_id_end(wd, id);
}
if (id_buffer != id_buffer_static) {
MEM_SAFE_FREE(id_buffer);
}
mywrite_flush(wd);
}
} while ((bmain != override_storage) && (bmain = override_storage));
if (override_storage) {
BKE_lib_override_library_operations_store_finalize(override_storage);
override_storage = NULL;
}
/* Special handling, operating over split Mains... */
write_libraries(wd, mainvar->next);
/* So changes above don't cause a 'DNA1' to be detected as changed on undo. */
mywrite_flush(wd);
if (write_flags & G_FILE_USERPREFS) {
2020-06-05 21:19:03 +02:00
write_userdef(&writer, &U);
}
/* Write DNA last, because (to be implemented) test for which structs are written.
*
* Note that we *borrow* the pointer to 'DNAstr',
* so writing each time uses the same address and doesn't cause unnecessary undo overhead. */
writedata(wd, DNA1, wd->sdna->data_len, wd->sdna->data);
/* end of file */
memset(&bhead, 0, sizeof(BHead));
bhead.code = ENDB;
mywrite(wd, &bhead, sizeof(BHead));
blo_join_main(&mainlist);
return mywrite_end(wd);
2002-10-12 11:37:38 +00:00
}
/* do reverse file history: .blend1 -> .blend2, .blend -> .blend1 */
/* return: success(0), failure(1) */
2014-02-03 18:55:59 +11:00
static bool do_history(const char *name, ReportList *reports)
{
char tempname1[FILE_MAX], tempname2[FILE_MAX];
int hisnr = U.versions;
if (U.versions == 0) {
return 0;
}
if (strlen(name) < 2) {
BKE_report(reports, RPT_ERROR, "Unable to make version backup: filename too short");
return 1;
}
while (hisnr > 1) {
BLI_snprintf(tempname1, sizeof(tempname1), "%s%d", name, hisnr - 1);
if (BLI_exists(tempname1)) {
BLI_snprintf(tempname2, sizeof(tempname2), "%s%d", name, hisnr);
if (BLI_rename(tempname1, tempname2)) {
BKE_report(reports, RPT_ERROR, "Unable to make version backup");
return true;
}
}
hisnr--;
}
/* is needed when hisnr==1 */
if (BLI_exists(name)) {
BLI_snprintf(tempname1, sizeof(tempname1), "%s%d", name, hisnr);
if (BLI_rename(name, tempname1)) {
BKE_report(reports, RPT_ERROR, "Unable to make version backup");
return true;
}
}
return 0;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name File Writing (Public)
* \{ */
2016-03-03 13:35:21 +11:00
/**
* \return Success.
*/
bool BLO_write_file(Main *mainvar,
const char *filepath,
int write_flags,
ReportList *reports,
const BlendThumbnail *thumb)
2002-10-12 11:37:38 +00:00
{
char tempname[FILE_MAX + 1];
eWriteWrapType ww_type;
WriteWrap ww;
/* path backup/restore */
void *path_list_backup = NULL;
const int path_list_flag = (BKE_BPATH_TRAVERSE_SKIP_LIBRARY | BKE_BPATH_TRAVERSE_SKIP_MULTIFILE);
if (G.debug & G_DEBUG_IO && mainvar->lock != NULL) {
BKE_report(reports, RPT_INFO, "Checking sanity of current .blend file *BEFORE* save to disk");
BLO_main_validate_libraries(mainvar, reports);
BLO_main_validate_shapekeys(mainvar, reports);
}
/* open temporary file, so we preserve the original in case we crash */
BLI_snprintf(tempname, sizeof(tempname), "%s@", filepath);
if (write_flags & G_FILE_COMPRESS) {
ww_type = WW_WRAP_ZLIB;
}
else {
ww_type = WW_WRAP_NONE;
}
ww_handle_init(ww_type, &ww);
if (ww.open(&ww, tempname) == false) {
BKE_reportf(
reports, RPT_ERROR, "Cannot open file %s for writing: %s", tempname, strerror(errno));
return 0;
}
/* Remapping of relative paths to new file location. */
if (write_flags & G_FILE_RELATIVE_REMAP) {
char dir_src[FILE_MAX];
char dir_dst[FILE_MAX];
BLI_split_dir_part(mainvar->name, dir_src, sizeof(dir_src));
BLI_split_dir_part(filepath, dir_dst, sizeof(dir_dst));
/* Just in case there is some subtle difference. */
BLI_path_normalize(mainvar->name, dir_dst);
BLI_path_normalize(mainvar->name, dir_src);
if (G.relbase_valid && (BLI_path_cmp(dir_dst, dir_src) == 0)) {
/* Saved to same path. Nothing to do. */
write_flags &= ~G_FILE_RELATIVE_REMAP;
}
else {
/* Check if we need to backup and restore paths. */
if (UNLIKELY(G_FILE_SAVE_COPY & write_flags)) {
path_list_backup = BKE_bpath_list_backup(mainvar, path_list_flag);
}
if (G.relbase_valid) {
/* Saved, make relative paths relative to new location (if possible). */
BKE_bpath_relative_rebase(mainvar, dir_src, dir_dst, NULL);
}
else {
/* Unsaved, make all relative. */
BKE_bpath_relative_convert(mainvar, dir_dst, NULL);
}
}
}
/* actual file writing */
const bool err = write_file_handle(mainvar, &ww, NULL, NULL, write_flags, thumb);
ww.close(&ww);
if (UNLIKELY(path_list_backup)) {
BKE_bpath_list_restore(mainvar, path_list_flag, path_list_backup);
BKE_bpath_list_free(path_list_backup);
}
if (err) {
BKE_report(reports, RPT_ERROR, strerror(errno));
remove(tempname);
return 0;
}
/* file save to temporary file was successful */
/* now do reverse file history (move .blend1 -> .blend2, .blend -> .blend1) */
if (write_flags & G_FILE_HISTORY) {
const bool err_hist = do_history(filepath, reports);
if (err_hist) {
BKE_report(reports, RPT_ERROR, "Version backup failed (file saved with @)");
return 0;
}
}
if (BLI_rename(tempname, filepath) != 0) {
BKE_report(reports, RPT_ERROR, "Cannot change old file (file saved with @)");
return 0;
}
if (G.debug & G_DEBUG_IO && mainvar->lock != NULL) {
BKE_report(reports, RPT_INFO, "Checking sanity of current .blend file *AFTER* save to disk");
BLO_main_validate_libraries(mainvar, reports);
}
return 1;
2002-10-12 11:37:38 +00:00
}
2016-03-03 13:35:21 +11:00
/**
* \return Success.
*/
bool BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int write_flags)
{
write_flags &= ~G_FILE_USERPREFS;
const bool err = write_file_handle(mainvar, NULL, compare, current, write_flags, NULL);
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
return (err == 0);
2016-03-03 13:35:21 +11:00
}
void BLO_write_raw(BlendWriter *writer, int size_in_bytes, const void *data_ptr)
{
writedata(writer->wd, DATA, size_in_bytes, data_ptr);
}
void BLO_write_struct_by_name(BlendWriter *writer, const char *struct_name, const void *data_ptr)
{
int struct_id = BLO_get_struct_id_by_name(writer, struct_name);
BLO_write_struct_by_id(writer, struct_id, data_ptr);
}
void BLO_write_struct_array_by_name(BlendWriter *writer,
const char *struct_name,
int array_size,
const void *data_ptr)
{
int struct_id = BLO_get_struct_id_by_name(writer, struct_name);
BLO_write_struct_array_by_id(writer, struct_id, array_size, data_ptr);
}
void BLO_write_struct_by_id(BlendWriter *writer, int struct_id, const void *data_ptr)
{
writestruct_nr(writer->wd, DATA, struct_id, 1, data_ptr);
}
void BLO_write_struct_at_address_by_id(BlendWriter *writer,
int struct_id,
const void *address,
const void *data_ptr)
{
writestruct_at_address_nr(writer->wd, DATA, struct_id, 1, address, data_ptr);
}
void BLO_write_struct_array_by_id(BlendWriter *writer,
int struct_id,
int array_size,
const void *data_ptr)
{
writestruct_nr(writer->wd, DATA, struct_id, array_size, data_ptr);
}
void BLO_write_struct_array_at_address_by_id(
BlendWriter *writer, int struct_id, int array_size, const void *address, const void *data_ptr)
{
writestruct_at_address_nr(writer->wd, DATA, struct_id, array_size, address, data_ptr);
}
void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, ListBase *list)
{
writelist_nr(writer->wd, DATA, struct_id, list);
}
void BLO_write_struct_list_by_name(BlendWriter *writer, const char *struct_name, ListBase *list)
{
BLO_write_struct_list_by_id(writer, BLO_get_struct_id_by_name(writer, struct_name), list);
}
void blo_write_id_struct(BlendWriter *writer, int struct_id, const void *id_address, const ID *id)
{
writestruct_at_address_nr(writer->wd, GS(id->name), struct_id, 1, id_address, id);
}
int BLO_get_struct_id_by_name(BlendWriter *writer, const char *struct_name)
{
int struct_id = DNA_struct_find_nr(writer->wd->sdna, struct_name);
BLI_assert(struct_id >= 0);
return struct_id;
}
void BLO_write_int32_array(BlendWriter *writer, int size, const int32_t *data_ptr)
{
BLO_write_raw(writer, sizeof(int32_t) * size, data_ptr);
}
void BLO_write_uint32_array(BlendWriter *writer, int size, const uint32_t *data_ptr)
{
BLO_write_raw(writer, sizeof(uint32_t) * size, data_ptr);
}
void BLO_write_float_array(BlendWriter *writer, int size, const float *data_ptr)
{
BLO_write_raw(writer, sizeof(float) * size, data_ptr);
}
void BLO_write_pointer_array(BlendWriter *writer, int size, const void *data_ptr)
{
BLO_write_raw(writer, sizeof(void *) * size, data_ptr);
}
void BLO_write_float3_array(BlendWriter *writer, int size, const float *data_ptr)
{
BLO_write_raw(writer, sizeof(float) * 3 * size, data_ptr);
}
/**
* Write a null terminated string.
*/
void BLO_write_string(BlendWriter *writer, const char *str)
{
if (str != NULL) {
BLO_write_raw(writer, strlen(str) + 1, str);
}
}
/**
* Sometimes different data is written depending on whether the file is saved to disk or used for
* undo. This function returns true when the current file-writing is done for undo.
*/
bool BLO_write_is_undo(BlendWriter *writer)
{
return writer->wd->use_memfile;
}
/** \} */