Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- PI = 3.14159265359;
- procedure ApplyTransform(aTriShape: TwbNifBlock);
- var
- scale: single; // Transform scale.
- translation: array[1..3] of single; // Transform translation.
- rotation: array[1..9] of single; // Transform rotation matrix.
- y, p, r: single; // Yaw / Pitch / Roll for rotation matrix.
- sinX, cosX, sinY, cosY, sinZ, cosZ: single; // temp trigonometry variables.
- pX, pY, pZ: single; // point coordinates.
- tX, tY, tZ: single; // transformed point coordinates.
- TriShapeData: TwbNifBlock; // Shape Data to transform point.
- // stuff to iterate over things.
- ref: TdfElement;
- i, n: integer;
- arr: TdfElement;
- sl: TStringList;
- begin
- scale := aTriShape.NativeValues['Transform\Scale'];
- translation[1] := aTriShape.NativeValues['Transform\Translation\X'];
- translation[2] := aTriShape.NativeValues['Transform\Translation\Y'];
- translation[3] := aTriShape.NativeValues['Transform\Translation\Z'];
- sl := TStringList.Create;
- sl.Delimiter := ' ';
- sl.StrictDelimiter := false;
- sl.DelimitedText := aTriShape.EditValues['Transform\Rotation'];
- y := StrToFloat(sl[0]) * PI / 180;
- p := StrToFloat(sl[1]) * PI / 180;
- r := StrToFloat(sl[2]) * PI / 180;
- sl.Free;
- sinX := sin(y);
- cosX := cos(y);
- sinY := sin(p);
- cosY := cos(p);
- sinZ := sin(r);
- cosZ := cos(r);
- rotation[1] := cosY * cosZ;
- rotation[2] := -cosY * sinZ;
- rotation[3] := sinY;
- rotation[4] := sinX * sinY * cosZ + sinZ * cosX;
- rotation[5] := cosX * cosZ - sinX * sinY * sinZ;
- rotation[6] := -sinX * cosY;
- rotation[7] := sinX * sinZ - cosX * sinY * cosZ;
- rotation[8] := cosX * sinY * sinZ + sinX * cosZ;
- rotation[9] := cosX * cosY;
- for i := 0 to Pred(aTriShape.RefsCount) do begin
- ref := aTriShape.Refs[i];
- TriShapeData := TwbNifBlock(ref.LinksTo);
- if Assigned(TriShapeData) then begin
- if SameText(TriShapeData.BlockType, 'NiTriShapeData') then begin
- n := TriShapeData.NativeValues['Num Vertices'];
- arr := TriShapeData.Elements['Vertices'];
- for i := 0 to Pred(n) do begin
- pX := arr[i].NativeValues['X'];
- pY := arr[i].NativeValues['Y'];
- pZ := arr[i].NativeValues['Z'];
- tX := (pX * rotation[1] + pY * rotation[2] + pZ * rotation[3]) * scale + translation[1];
- tY := (pX * rotation[4] + pY * rotation[5] + pZ * rotation[6]) * scale + translation[2];
- tZ := (pX * rotation[7] + pY * rotation[8] + pZ * rotation[9]) * scale + translation[3];
- arr[i].EditValue := FloatToStr(tX) + ' ' + FloatToStr(tY) + ' '+ FloatToStr(tZ);
- end;
- end;
- end;
- end;
- aTriShape.EditValues['Transform\Translation'] := '0.000000 0.000000 0.000000';
- aTriShape.EditValues['Transform\Rotation'] := '0.000000 0.000000 0.000000';
- aTriShape.EditValues['Transform\Scale'] := '1.000000';
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement