﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3ASource%2FPhysics%2FCollision_Modifier</id>
	<title>Dev:Source/Physics/Collision Modifier - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3ASource%2FPhysics%2FCollision_Modifier"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:Source/Physics/Collision_Modifier&amp;action=history"/>
	<updated>2026-07-10T04:20:38Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:Source/Physics/Collision_Modifier&amp;diff=58552&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:Source/Physics/Collision_Modifier&amp;diff=58552&amp;oldid=prev"/>
		<updated>2018-06-28T17:54:00Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 17:54時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:Source/Physics/Collision_Modifier&amp;diff=58551&amp;oldid=prev</id>
		<title>2014年8月19日 (火) 00:54にwiki&gt;Britaによる</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:Source/Physics/Collision_Modifier&amp;diff=58551&amp;oldid=prev"/>
		<updated>2014-08-19T00:54:00Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{NiceTip&lt;br /&gt;
|This page is outdated&lt;br /&gt;
|This page was last updated in 2008, it is outdated.&amp;lt;br/&amp;gt;&lt;br /&gt;
If you have questions, ask in #blendercoders at IRC}}&lt;br /&gt;
&lt;br /&gt;
= Collision Modifier =&lt;br /&gt;
The collision modifier gets created automatically through pressing the &amp;quot;Deflection&amp;quot; button in the &amp;quot;Deflection&amp;quot; panel or using the Softbody deflection panel.&lt;br /&gt;
== Internals ==&lt;br /&gt;
=== What does it do ===&lt;br /&gt;
The collision modifier safes the position of the vertices of the object at the corresponding position on the modifier stack. It does this for the current and the last position using GLOBAL coordinates.&lt;br /&gt;
The data is only valid as long as&lt;br /&gt;
* you don't skip ahead/back several frames [TODO: should be enhanced later]&lt;br /&gt;
* the number of vertices don't change on the modifier stack. &lt;br /&gt;
&lt;br /&gt;
If any of these events happens, the safed position will get reseted.&lt;br /&gt;
&lt;br /&gt;
=== Structure ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
typedef struct CollisionModifierData {&lt;br /&gt;
	ModifierData	modifier;&lt;br /&gt;
	&lt;br /&gt;
	struct MVert *x; /* position at the beginning of the frame */&lt;br /&gt;
	struct MVert *xnew; /* position at the end of the frame */&lt;br /&gt;
	struct MVert *xold; /* unsued atm, but was discussed during sprint */&lt;br /&gt;
	struct MVert *current_xnew; /* new position at the actual inter-frame step */&lt;br /&gt;
	struct MVert *current_x; /* position at the actual inter-frame step */&lt;br /&gt;
	struct MVert *current_v; /* (xnew - x) at the actual inter-frame step */&lt;br /&gt;
	&lt;br /&gt;
	struct MFace *mfaces; /* object face data */&lt;br /&gt;
	&lt;br /&gt;
	unsigned int numverts;&lt;br /&gt;
	unsigned int numfaces;&lt;br /&gt;
	int pad;&lt;br /&gt;
	float time;		/* cfra time of modifier */&lt;br /&gt;
	struct BVH *tree;	/* collision tree (kdop bvh) for this cloth object */&lt;br /&gt;
} CollisionModifierData;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
==== collision_move_object ====&lt;br /&gt;
That's a function to set the position of the object to a specific time (is using linear interpolation):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void collision_move_object(CollisionModifierData *collmd, float step, float prevstep);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''collmd''': Pointer to collision modifier data&lt;br /&gt;
&lt;br /&gt;
* '''step''': Time at the end of timestep &lt;br /&gt;
* '''prevstep''': Time at the start of timestep &lt;br /&gt;
'''step''' and '''prevstep''' are limited from 0 to 1 which would mean that at 0 all vertices are put at the start positions of the frame and 1 put the vertices at the end of the frame.&lt;br /&gt;
&lt;br /&gt;
==== Example usage of collision_move_object ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
collision_move_object(collmd, step + dt, step);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where '''dt''' means an arbitrary timestep '''deltatime''' and '''step''' calculated as &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
step += dt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Additional functions ====&lt;br /&gt;
The collision modifier can be also used as a partner for a '''KDOP BVH''' collision query. The '''KDOP BVH''' collision query tests 2 bounding boxes if they overlap (see at bottom).&lt;br /&gt;
&lt;br /&gt;
Here the sample code:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
bvh_traverse((ModifierData *)clmd, (ModifierData *)collmd, cloth_bvh-&amp;gt;root,&lt;br /&gt;
             collmd-&amp;gt;tree-&amp;gt;root, step, cloth_collision_static, 0);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Context Example ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
if (collmd-&amp;gt;tree) &lt;br /&gt;
{&lt;br /&gt;
	/* get pointer to bounding volume hierarchy */	&lt;br /&gt;
	BVH *coll_bvh = collmd-&amp;gt;tree; &lt;br /&gt;
		&lt;br /&gt;
	/* move object to position (step) in time */		&lt;br /&gt;
	collision_move_object(collmd, step + dt, step); &lt;br /&gt;
	&lt;br /&gt;
	/* search for overlapping collision pairs */		&lt;br /&gt;
	bvh_traverse((ModifierData *)clmd, &lt;br /&gt;
                     (ModifierData *)collmd, &lt;br /&gt;
                     cloth_bvh-&amp;gt;root, &lt;br /&gt;
                     coll_bvh-&amp;gt;root, &lt;br /&gt;
                     step, cloth_collision_static, 0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= KDOP BVH =&lt;br /&gt;
The '''kdop bvh''' is a bounding volume hierarchy structure which can be used to test if two bounding boxes oberlap. If they do, a predefined callback function is called for each overlapping leaf.&lt;br /&gt;
== Internals ==&lt;br /&gt;
Definition of traverse function to test if two BVH structures overlap:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
int bvh_traverse ( ModifierData * md1, ModifierData * md2, CollisionTree * tree1,&lt;br /&gt;
                   CollisionTree * tree2, float step, &lt;br /&gt;
                   CM_COLLISION_RESPONSE collision_response, int selfcollision);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Definition of CollisionTree:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
typedef struct CollisionTree&lt;br /&gt;
{&lt;br /&gt;
	struct CollisionTree *nodes[4]; // 4 children --&amp;gt; quad-tree&lt;br /&gt;
	struct CollisionTree *parent;&lt;br /&gt;
	struct CollisionTree *nextLeaf;&lt;br /&gt;
	struct CollisionTree *prevLeaf;&lt;br /&gt;
	float	bv[26]; // Bounding volume of all nodes / we have 7 axes on a 14-DOP&lt;br /&gt;
	unsigned int tri_index; // this saves the index of the face&lt;br /&gt;
	int	count_nodes; // how many nodes are used&lt;br /&gt;
	int	traversed;  // how many nodes already traversed until this level?&lt;br /&gt;
	int	isleaf;&lt;br /&gt;
	float alpha; /* for selfcollision */&lt;br /&gt;
	float normal[3]; /* for selfcollision */&lt;br /&gt;
}&lt;br /&gt;
CollisionTree;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Since you get the corresponding leafs/'''CollisionTrees''' as arguments of the '''CM_COLLISION_RESPONSE''' callback function you can e.g. easily lookup their vertices and check if the two faces really collided.&lt;br /&gt;
&lt;br /&gt;
Defition of callback function:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
typedef void ( *CM_COLLISION_RESPONSE ) ( ModifierData *md1, ModifierData *md2,&lt;br /&gt;
                                          CollisionTree *tree1, CollisionTree *tree2 );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating a CollisionTree ===&lt;br /&gt;
You can create a collition tree out of every mesh. You just alloc a '''BVH''' structure and fill the specific structures with the information according to your mesh structure and call the '''bvh_build()''' function. &lt;br /&gt;
You can also use existing functions which do the trick for you (like '''bvh_build_from_mvert'''). &lt;br /&gt;
&lt;br /&gt;
Information to be set in the '''BVH''' structure before calling '''bvh_build()''':&lt;br /&gt;
* '''epsilon''': Thickness / minimum distance (higher results in more overlapping leafs)&lt;br /&gt;
* '''numfaces''': Number of faces&lt;br /&gt;
* '''mfaces''': Pointer to faces (Type: MFace *)&lt;br /&gt;
* '''numverts''': Number of vertices&lt;br /&gt;
* '''current_x''': Has to be alloc'ed and fill edwith current vertex positions&lt;br /&gt;
&lt;br /&gt;
==== Definition of '''bvh_build''' function ====&lt;br /&gt;
Builds the BVH KDOP hierarchy structure out of a prealloc'ed and filled BVH structure.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void bvh_build (BVH *bvh);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Example of filling and using the '''bvh_build''' function (content of '''bvh_build_from_mvert''' function) ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
	BVH *bvh=NULL;&lt;br /&gt;
	&lt;br /&gt;
	bvh = MEM_callocN(sizeof(BVH), &amp;quot;BVH&amp;quot;);&lt;br /&gt;
	if (bvh == NULL) &lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;bvh: Out of memory.\n&amp;quot;);&lt;br /&gt;
		return NULL;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	// in the moment, return zero if no faces there&lt;br /&gt;
	if(!numfaces)&lt;br /&gt;
		return NULL;&lt;br /&gt;
&lt;br /&gt;
	bvh-&amp;gt;epsilon = epsilon;&lt;br /&gt;
	bvh-&amp;gt;numfaces = numfaces;&lt;br /&gt;
	bvh-&amp;gt;mfaces = mfaces;&lt;br /&gt;
	&lt;br /&gt;
	// we have no faces, we save seperate points&lt;br /&gt;
	if(!mfaces)&lt;br /&gt;
	{&lt;br /&gt;
		bvh-&amp;gt;numfaces = numverts;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	bvh-&amp;gt;numverts = numverts;&lt;br /&gt;
	bvh-&amp;gt;current_x = MEM_dupallocN(x);&lt;br /&gt;
	&lt;br /&gt;
	bvh_build(bvh);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Definition of '''bvh_build_from_mvert''' function ====&lt;br /&gt;
Allocs, fills and builds a BVH KDOP structureout of MVert vertex structure which is ready for use.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
BVH *bvh_build_from_mvert (MFace *mfaces, &lt;br /&gt;
                           unsigned int numfaces, &lt;br /&gt;
                           MVert *x, &lt;br /&gt;
                           unsigned int numverts, &lt;br /&gt;
                           float epsilon);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating bvh structure ===&lt;br /&gt;
There is also an option to update the position of the vertices / of the bounding box hierarchy. You just put the new positions into '''bvh-&amp;gt;current_x''' and '''bvh-&amp;gt;current_xold''' and call the bvh_update function.&lt;br /&gt;
You can also use existing functions like '''bvh_update_from_mvert''' which uses MVert structure to update the hierarchy.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void bvh_update(BVH * bvh, int moving);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
* '''bvh''': Pointer to ready initialized and build BVH structure&lt;br /&gt;
* '''moving''': Can be 0 or 1. 0 means static object, only bvh-&amp;gt;current_xold will be used for updating positions. 1 means dynamic/moving resulting that also bvh-&amp;gt;current_x will be used for positions update at the end of the timeframe. It's used to catch fast moving object collisions.&lt;br /&gt;
&lt;br /&gt;
There is also a function which does all the trick for you using a MVert structure:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void bvh_update_from_mvert(BVH * bvh, MVert *x, unsigned int numverts, &lt;br /&gt;
                           MVert *xnew, int moving);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
* '''bvh''': Pointer to ready initialized and build BVH structure&lt;br /&gt;
* '''x''': Current vertex positions&lt;br /&gt;
* '''numverts''': Number of vertices&lt;br /&gt;
* '''xnew''': Positions of vertices at the end of the timestep (only used if '''moving''' is 1)&lt;br /&gt;
* '''moving''': Can be 0 or 1. 0 means static object, only bvh-&amp;gt;current_xold will be used for updating positions. 1 means dynamic/moving resulting that also bvh-&amp;gt;current_x will be used for positions update at the end of the timeframe. It's used to catch fast moving object collisions.&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;/div&gt;</summary>
		<author><name>wiki&gt;Brita</name></author>
		
	</entry>
</feed>