Skip to content

Commit

Permalink
mqsdk 3.11 ベースへ更新
Browse files Browse the repository at this point in the history
  • Loading branch information
mfakane committed Jul 14, 2013
1 parent 673cd88 commit e1bf2a6
Show file tree
Hide file tree
Showing 12 changed files with 1,175 additions and 42 deletions.
735 changes: 713 additions & 22 deletions Metasequoia.Sharp/Classes/Classes.Generated.cs

Large diffs are not rendered by default.

35 changes: 33 additions & 2 deletions Metasequoia.Sharp/Classes/Classes.tt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ namespace Metasequoia
<#
var path = Path.Combine(Path.GetDirectoryName(this.Host.TemplateFile), "..", "..", "mqsdk", "MQPlugin.h");
var enc = Encoding.GetEncoding(932);
var regex = new Regex(@"^inline (?<returnType>\w+)\s+MQC(?<className>\w+)\:\:(?<methodName>\w+)\((?<params>.*?)\)\s*\{(?<content>(.|\n)+?)\}", RegexOptions.Compiled | RegexOptions.Multiline);
var regex = new Regex(@"^inline (?<returnType>\w+)\s+MQC(?<className>\w+)\:\:(?<methodName>\w+)\((?<params>.*?)\)\s*\{(?<content>(\{(.|\n)*?\}|.|\n)+?)\}", RegexOptions.Compiled | RegexOptions.Multiline);
var ignore = new[]
{
"Document.GetMappingImageSize",
"Document.CreateUserData",
"Document.FindUserData",
};
var defs = regex.Matches(File.ReadAllText(path, enc).Replace("\r\n", "\n"))
.Cast<Match>()
.Select(_ =>
Expand All @@ -34,7 +40,8 @@ var defs = regex.Matches(File.ReadAllText(path, enc).Replace("\r\n", "\n"))
Content = _.Groups["content"].Value,
Handled = new[] { false },
};
});
})
.Where(_ => !ignore.Contains(_.ClassName + "." + _.MethodName));
var map = new Dictionary<string, string>
{
{ "MQMatrix&", "ref Matrix" },
Expand All @@ -54,7 +61,9 @@ var map = new Dictionary<string, string>
{ "uint map_type", "Mapping map_type" },
{ "float *", "float[] " },
{ "int *", "int[] " },
{ "int&", "out int" },
{ "UINT", "uint" },
{ "void *", "byte[] " },
{ "MQ", "" },
};
var flagMap = new Dictionary<string, string[]>
Expand All @@ -67,6 +76,7 @@ var flagMap = new Dictionary<string, string[]>
{ "Object.GetMirrorAxis", new[] { "ObjectMirrorAxis", "axis" } },
{ "Object.GetLatheType", new[] { "ObjectLathe", "type", "int" } },
{ "Object.GetLatheAxis", new[] { "ObjectLatheAxis", "axis" } },
{ "Object.GetType", new[] { "ObjectType", "type", "int" } },
{ "Material.GetShader", new[] { "MaterialShader", "shader", "int" } },
{ "Material.GetVertexColor", new[] { "MaterialVertexcolor", "value", "int" } },
{ "Material.GetMappingType", new[] { "MaterialProjection", "type", "int" } },
Expand Down Expand Up @@ -184,6 +194,13 @@ foreach (var k in defs.GroupBy(_ => _.ClassName))
.Replace("MQObj_GetFaceCoordinateArray(this, face, uvarray);", "unsafe { fixed (void* ptr = uvarray) MQObj_GetFaceCoordinateArray(this, face, (IntPtr)ptr); }")
.Replace("MQObj_SetFaceCoordinateArray(this, face, uvarray);", "unsafe { fixed (void* ptr = uvarray) MQObj_SetFaceCoordinateArray(this, face, (IntPtr)ptr); }")

.Replace("return MQDoc_GetUnusedObjectName", "MQDoc_GetUnusedObjectName")
.Replace("return MQDoc_GetUnusedMaterialName", "MQDoc_GetUnusedMaterialName")
.Replace("MQObj_GetIntValue(this, MQOBJ_ID_SELECTED)", "MQObj_GetIntValue(this, MQOBJ_ID_SELECTED) != 0")
.Replace("MQObj_SetIntValue(this, MQOBJ_ID_SELECTED, flag)", "MQObj_SetIntValue(this, MQOBJ_ID_SELECTED, flag ? 1 : 0)")
.Replace("MQMat_GetIntValue(this, MQMAT_ID_SELECTED)", "MQMat_GetIntValue(this, MQMAT_ID_SELECTED) != 0")
.Replace("MQMat_SetIntValue(this, MQMAT_ID_SELECTED, flag)", "MQMat_SetIntValue(this, MQMAT_ID_SELECTED, flag ? 1 : 0)")

.Replace("if (w != NULL) *w", "w")

.Replace("; ", ";\r\n\t\t\t")
Expand Down Expand Up @@ -217,9 +234,23 @@ foreach (var k in defs.GroupBy(_ => _.ClassName))
.Replace("MQPoint(", "new Point(")
.Replace("MQAngle(", "new Angle(")
.Replace("VALID, flag)", "VALID, flag ? 1 : 0)")
.Replace("!= 0 ? TRUE : FALSE", "!= 0")
.Replace("? TRUE : FALSE", "!= 0")

.Replace("MQUSERDATA_OBJECT", "(int)Userdata.Object")
.Replace("MQUSERDATA_VERTEX", "(int)Userdata.Vertex")
.Replace("MQUSERDATA_FACE", "(int)Userdata.Face")
.Replace("MQUSERDATA_MATERIAL", "(int)Userdata.Material")
.Replace("MQUserDataInfo", "UserDataInfo")

.Replace("int val[1];", "var val = new int[1];")
.Replace("int val[2];", "var val = new int[2];")
.Replace("int val[3];", "var val = new int[3];")
.Replace("MQSCENE_SET_MULTILIGHT_INDEX,&index", "MQSCENE_SET_MULTILIGHT_INDEX,new[]{index}")

.Replace("TRUE", "true")
.Replace("FALSE", "false")
.Replace("NULL", "null")
.Replace("MQ", "NativeMethods.MQ")
.Replace("\n", "\r\n")
.Replace("\r\r\n", "\r\n");
Expand Down
108 changes: 107 additions & 1 deletion Metasequoia.Sharp/Classes/Document.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Text;
using System;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;

namespace Metasequoia
{
Expand Down Expand Up @@ -29,6 +32,34 @@ public ReadOnlyIndexer<Material> Materials
private set;
}

public string GetUnusedObjectName()
{
return GetUnusedObjectName(null);
}

public string GetUnusedObjectName(string basename)
{
var sb = new StringBuilder(Object.NameBufferLength);

this.GetUnusedObjectName(sb, sb.Capacity, basename);

return sb.ToString();
}

public string GetUnusedMaterialName()
{
return GetUnusedMaterialName(null);
}

public string GetUnusedMaterialName(string basename)
{
var sb = new StringBuilder(Material.NameBufferLength);

this.GetUnusedMaterialName(sb, sb.Capacity, basename);

return sb.ToString();
}

public string FindMappingFile(string filename, Mapping mapType)
{
var sb = new StringBuilder(Material.TextureNameBufferLength);
Expand All @@ -52,5 +83,80 @@ partial void BeforeAddMaterial(Material mat)
{
mat.deletable = false;
}

#region Interop

/// <summary>
/// BOOL GetMappingImageSize(const char *filename, DWORD map_type, int&amp; width, int&amp; height)
/// </summary>
public unsafe bool GetMappingImageSize(string filename, Mapping mapType, out int width, out int height)
{
var array = new IntPtr[5];
int bpp;
IntPtr buffer;

fixed (int* widthp = &width)
fixed (int* heightp = &height)
{
array[0] = (IntPtr)widthp;
array[1] = (IntPtr)heightp;
array[2] = (IntPtr)(&bpp);
array[3] = IntPtr.Zero;
array[4] = (IntPtr)(&buffer);

if (!NativeMethods.MQDoc_GetMappingImage(this, filename, (uint)mapType, array))
{
width = height = 0;
return false;
}
}

return true;
}

/// <summary>
/// int CreateUserData(DWORD productID, DWORD pluginID, const char *identifier, int userdata_type, int bytes_per_object)
/// </summary>
public int CreateUserData(uint productID, uint pluginID, string identifier, int userdata_type, int bytes_per_object)
{
BeforeCreateUserData(productID, pluginID, identifier, userdata_type, bytes_per_object);

var info = new UserDataInfo
{
dwSize = (uint)Marshal.SizeOf(typeof(UserDataInfo)),
ProductID = productID,
PluginID = pluginID,
Identifier = Plugin.Get932(identifier).Take(15).Concat(new byte[] { 0 }).ToArray(),
UserdataType = userdata_type,
BytesPerElement = bytes_per_object,
Create = true,
};

return NativeMethods.MQDoc_CreateUserData(this, ref info);
}

partial void BeforeCreateUserData(uint productID, uint pluginID, string identifier, int userdata_type, int bytes_per_object);
/// <summary>
/// int FindUserData(DWORD productID, DWORD pluginID, const char *identifier, int userdata_type)
/// </summary>
public int FindUserData(uint productID, uint pluginID, string identifier, int userdata_type)
{
BeforeFindUserData(productID, pluginID, identifier, userdata_type);

var info = new UserDataInfo
{
dwSize = (uint)Marshal.SizeOf(typeof(UserDataInfo)),
ProductID = productID,
PluginID = pluginID,
Identifier = Plugin.Get932(identifier).Take(15).Concat(new byte[] { 0 }).ToArray(),
UserdataType = userdata_type,
BytesPerElement = 0,
};

return NativeMethods.MQDoc_CreateUserData(this, ref info);
}
partial void BeforeFindUserData(uint productID, uint pluginID, string identifier, int userdata_type);

#endregion
}
}
106 changes: 105 additions & 1 deletion Metasequoia.Sharp/Enums/Enums.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ partial class Plugin
/// <summary>
/// MQPLUGIN_VERSION
/// </summary>
public const int Version = 0x0249;
public const int Version = 0x0311;
}

public enum PluginType
Expand Down Expand Up @@ -339,6 +339,26 @@ public enum Mapping
Bump = 3,
}

public enum Userdata
{
/// <summary>
/// MQUSERDATA_OBJECT
/// </summary>
Object = 1,
/// <summary>
/// MQUSERDATA_MATERIAL
/// </summary>
Material = 2,
/// <summary>
/// MQUSERDATA_VERTEX
/// </summary>
Vertex = 3,
/// <summary>
/// MQUSERDATA_FACE
/// </summary>
Face = 4,
}

public enum MQScene
{
/// <summary>
Expand Down Expand Up @@ -405,6 +425,54 @@ public enum MQScene
/// MQSCENE_CONVERT_SCREEN_TO_3D
/// </summary>
ConvertScreenTo3d = 0x301,
/// <summary>
/// MQSCENE_ADD_MULTILIGHT
/// </summary>
AddMultilight = 0x400,
/// <summary>
/// MQSCENE_DELETE_MULTILIGHT
/// </summary>
DeleteMultilight = 0x401,
/// <summary>
/// MQSCENE_GET_MULTILIGHT_NUMBER
/// </summary>
GetMultilightNumber = 0x402,
/// <summary>
/// MQSCENE_SET_MULTILIGHT_INDEX
/// </summary>
SetMultilightIndex = 0x403,
/// <summary>
/// MQSCENE_GET_MULTILIGHT_DIR
/// </summary>
GetMultilightDir = 0x404,
/// <summary>
/// MQSCENE_SET_MULTILIGHT_DIR
/// </summary>
SetMultilightDir = 0x405,
/// <summary>
/// MQSCENE_GET_MULTILIGHT_COLOR
/// </summary>
GetMultilightColor = 0x406,
/// <summary>
/// MQSCENE_SET_MULTILIGHT_COLOR
/// </summary>
SetMultilightColor = 0x407,
}

public enum ObjectType
{
/// <summary>
/// MQOBJECT_TYPE_NORMAL
/// </summary>
Normal = 0,
/// <summary>
/// MQOBJECT_TYPE_POINT_LIGHT
/// </summary>
PointLight = 1,
/// <summary>
/// MQOBJECT_TYPE_DIRECTIONAL_LIGHT
/// </summary>
DirectionalLight = 2,
}

[Flags]
Expand Down Expand Up @@ -621,6 +689,18 @@ public enum ObjId
/// </summary>
UniqueId = 0x104,
/// <summary>
/// MQOBJ_ID_TYPE
/// </summary>
Type = 0x105,
/// <summary>
/// MQOBJ_ID_SELECTED
/// </summary>
Selected = 0x106,
/// <summary>
/// MQOBJ_ID_PATCH_TRIANGLE
/// </summary>
PatchTriangle = 0x107,
/// <summary>
/// MQOBJ_ID_COLOR
/// </summary>
Color = 0x201,
Expand Down Expand Up @@ -648,6 +728,22 @@ public enum ObjId
/// MQOBJ_ID_LOCAL_INVERSE_MATRIX
/// </summary>
LocalInverseMatrix = 0x305,
/// <summary>
/// MQOBJ_ID_LIGHT_VALUE
/// </summary>
LightValue = 0x401,
/// <summary>
/// MQOBJ_ID_LIGHT_ATTENUATION
/// </summary>
LightAttenuation = 0x402,
/// <summary>
/// MQOBJ_ID_LIGHT_FALLOFF_END
/// </summary>
LightFalloffEnd = 0x403,
/// <summary>
/// MQOBJ_ID_LIGHT_FALLOFF_HALF
/// </summary>
LightFalloffHalf = 0x404,
}

public enum MatId
Expand All @@ -665,6 +761,14 @@ public enum MatId
/// </summary>
UniqueId = 0x103,
/// <summary>
/// MQMAT_ID_DOUBLESIDED
/// </summary>
Doublesided = 0x104,
/// <summary>
/// MQMAT_ID_SELECTED
/// </summary>
Selected = 0x106,
/// <summary>
/// MQMAT_ID_MAPPROJ
/// </summary>
Mapproj = 0x301,
Expand Down
4 changes: 3 additions & 1 deletion Metasequoia.Sharp/Enums/Enums.tt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ var enums = regex.Matches(File.ReadAllText(path, enc).Replace("\r\n", "\n"))
.Replace("file_type", "fileType")
.Replace("object_lathe_x", "object_lathe_axis_x")
.Replace("object_lathe_y", "object_lathe_axis_y")
.Replace("object_lathe_z", "object_lathe_axis_z");
.Replace("object_lathe_z", "object_lathe_axis_z")
.Replace("point_light", "pointLight")
.Replace("directional_light", "directionalLight");
var idx = name.StartsWith("plugin_type") || name.StartsWith("object_") || name.StartsWith("material_")
? name.LastIndexOf('_')
: name.IndexOf('_');
Expand Down
Loading

0 comments on commit e1bf2a6

Please sign in to comment.