How to create destroyable wheels: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
(Some wiki formatting + categories)
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==File Format==
{{TOC|side}}
=== The Principle ===


{| border="1"
The model already contains the destroyed wheels, but they are hidden with animations. These animations uses the damage value of hitpoints to switch the wheels when needed.
!Offset
!Datatype
!Content
!Description
|-
|0
|char[4]
|"WSS0"
|file signature
|-
|4
|ulong
|<compression>
|if <compression> == 8 the PCM data is compressed, otherwise <compression> == 0
|-
|8
|ushort
|<format tag>
|defines in which format the data is saved. Always 0x0001 in WSS files
|-
|10
|ushort
|<channels>
|number of channels: 1=mono, 2=stereo
|-
|12
|ulong
|<sample rate>
|sample rate in Hz (e.g. 44100Hz)
|-
|16
|ulong
|<bytes/second>
|<sample rate> * <block align>
|-
|20
|ushort
|<block align>
|<channels> * (<bits/sample> / 8)
|-
|22
|ushort
|<bits/sample>
|usually 0x0010 in WSS files
|-
|24
|ushort
|<unknown>
|unknown value
|-
|26
|byte[fileSize-26]
|<soundData>
|here the PCM data of the sound is stored
|-
|}


==Decompression==
=== Prepare the model ===
If the <soundData> is compressed the following (C#) code can be used for decompression:


PCMData = new Int16[soundData.Length];
In the case of wheels it makes sense to create an extra model for a destroyed wheel. This way you are able to implement the destroyed wheels in the original model via proxies which reference to the destroyed wheel model. It doesn't need to be done via proxies though. Now, you just need to create named selections for every wheel and for every destroyed wheel. The normal wheels are called "wheel_x_x_hide" and the destroyed ones "wheel_x_x_unhide" in this tutorial.
for (int j = 0; j < PCMData.Length; j++)
 
{
=== The Animations ===
  SByte srcSample = (SByte)soundData[j];
 
  if (srcSample != 0)
You should have some basic knowledge about animations and [[Model_Config|model.cfg]] as this is not covered here.
  {
 
    double asFloat = Math.Abs(srcSample) / 28.12574042515172;
The following class is an example animation that makes the destroyed wheel visible:
    asFloat *= 2.3025850929940456840; //ln(10)
<syntaxhighlight lang="cpp">
    asFloat *= 1.4426950408889634070; //log2(e)
class wheel_1_1_destruct_unhide
    double rnd = Math.Round(asFloat);
{
    double mantisse = Math.Pow(2.0, asFloat - rnd);
type = "hide";
    asFloat = mantisse * Math.Pow(2, rnd);
source = "HitLFWheel";
    if (srcSample < 0) asFloat *= -1;
sourceAddress = "mirror";
    Int32 asInt = (int)Math.Round(asFloat);
selection = "wheel_1_1_unhide";
    asInt = (j == 0) ? asInt : (asInt + PCMData[j - 1]);
minValue = -1;
    if (asInt > short.MaxValue) asInt = short.MaxValue;
maxValue = 0;
    if (asInt < short.MinValue) asInt = short.MinValue;
minPhase = -1;
    PCMData[j] = (Int16)asInt;
maxPhase = 0;
  }
hideValue = 0.010000;
  else PCMData[j] = (j == 0) ? (Int16)0 : PCMData[j - 1];
};
}
</syntaxhighlight>
 
The animation that hides the undestroyed wheel looks like this:
<syntaxhighlight lang="cpp">
class wheel_1_1_destruct
{
type = "hide";
source = "HitLFWheel";
selection = "wheel_1_1_hide";
minValue = 0;
maxValue = 1;
minPhase = 0;
maxPhase = 1;
hideValue = 0.990000;
};
</syntaxhighlight>
 
Make sure that the sum of the hideValues of two corresponding anims is 1, so the switch happens at the same time.
 
=== Animation sources ===
 
The animationsource used in the previous section is a custom one which needs to be defined in the config of the vehicle:
<syntaxhighlight lang="cpp">
class AnimationSources
{
class HitLFWheel
{
source = "Hit";
hitpoint = "HitLFWheel";
raw = 1;
};
};
</syntaxhighlight>
 
The hitpoint entry refers to the hitpoints defined in the vehicle config, e.g.
<syntaxhighlight lang="cpp">
class HitLFWheel
{
armor = 0.15;
material = -1;
name = "wheel_1_1_steering";
visual = "";
passThrough = 0.3;
};
</syntaxhighlight>
 
 
{{GameCategory|arma1|Addon Editing}}
{{GameCategory|arma2|Editing}}
{{GameCategory|arma3|Editing}}

Latest revision as of 02:10, 30 October 2021

The Principle

The model already contains the destroyed wheels, but they are hidden with animations. These animations uses the damage value of hitpoints to switch the wheels when needed.

Prepare the model

In the case of wheels it makes sense to create an extra model for a destroyed wheel. This way you are able to implement the destroyed wheels in the original model via proxies which reference to the destroyed wheel model. It doesn't need to be done via proxies though. Now, you just need to create named selections for every wheel and for every destroyed wheel. The normal wheels are called "wheel_x_x_hide" and the destroyed ones "wheel_x_x_unhide" in this tutorial.

The Animations

You should have some basic knowledge about animations and model.cfg as this is not covered here.

The following class is an example animation that makes the destroyed wheel visible:

class wheel_1_1_destruct_unhide
{
	type = "hide";
	source = "HitLFWheel";
	sourceAddress = "mirror";
	selection = "wheel_1_1_unhide";
	minValue = -1;
	maxValue = 0;
	minPhase = -1;
	maxPhase = 0;
	hideValue = 0.010000;
};

The animation that hides the undestroyed wheel looks like this:

class wheel_1_1_destruct
{
	type = "hide";
	source = "HitLFWheel";
	selection = "wheel_1_1_hide";
	minValue = 0;
	maxValue = 1;
	minPhase = 0;
	maxPhase = 1;
	hideValue = 0.990000;
};

Make sure that the sum of the hideValues of two corresponding anims is 1, so the switch happens at the same time.

Animation sources

The animationsource used in the previous section is a custom one which needs to be defined in the config of the vehicle:

class AnimationSources
{
	class HitLFWheel
	{
		source = "Hit";
		hitpoint = "HitLFWheel";
		raw = 1;
	};
};

The hitpoint entry refers to the hitpoints defined in the vehicle config, e.g.

class HitLFWheel
{
	armor = 0.15;
	material = -1;
	name = "wheel_1_1_steering";
	visual = "";
	passThrough = 0.3;
};