Commit 077ba676 authored by s520's avatar s520 Committed by Christopher Lees

New: Add Obj file parser using Assimp (#297)

* Fix: OpenBVE.sln

* New: Add Obj file parser using Assimp

* Fix: OpenBVE.sln

* Fix: the copyright notice of Assimp Obj parser

* Change: combine the two Assimp DLLs into one
parent 77d96023
......@@ -58,7 +58,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DefaultDisplayPlugin", "sou
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Texture.Tga", "source\Plugins\Texture.Tga\Texture.Tga.csproj", "{F714A9FA-1C4B-456B-BACF-D6763223A81C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssimpXParser", "source\AssimpXParser\AssimpXParser.csproj", "{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssimpParser", "source\AssimpParser\AssimpParser.csproj", "{77CCAE62-D374-468E-98A0-DD8ADB461C10}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -297,6 +297,7 @@ Global
{3D833D81-4F14-4A68-B0DE-6469B8CF4E62}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{3D833D81-4F14-4A68-B0DE-6469B8CF4E62}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{3D833D81-4F14-4A68-B0DE-6469B8CF4E62}.Release|x86.ActiveCfg = Release|Any CPU
{3D833D81-4F14-4A68-B0DE-6469B8CF4E62}.Release|x86.Build.0 = Release|Any CPU
{F714A9FA-1C4B-456B-BACF-D6763223A81C}.Debug|Any CPU.ActiveCfg = Debug|x86
{F714A9FA-1C4B-456B-BACF-D6763223A81C}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{F714A9FA-1C4B-456B-BACF-D6763223A81C}.Debug|Mixed Platforms.Build.0 = Debug|x86
......@@ -307,18 +308,18 @@ Global
{F714A9FA-1C4B-456B-BACF-D6763223A81C}.Release|Mixed Platforms.Build.0 = Release|x86
{F714A9FA-1C4B-456B-BACF-D6763223A81C}.Release|x86.ActiveCfg = Release|x86
{F714A9FA-1C4B-456B-BACF-D6763223A81C}.Release|x86.Build.0 = Release|x86
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Debug|x86.ActiveCfg = Debug|Any CPU
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Debug|x86.Build.0 = Debug|Any CPU
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Release|Any CPU.Build.0 = Release|Any CPU
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Release|x86.ActiveCfg = Release|Any CPU
{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}.Release|x86.Build.0 = Release|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Debug|x86.ActiveCfg = Debug|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Debug|x86.Build.0 = Debug|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Release|Any CPU.Build.0 = Release|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Release|x86.ActiveCfg = Release|Any CPU
{77CCAE62-D374-468E-98A0-DD8ADB461C10}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -332,9 +333,11 @@ Global
{E9B64673-65B7-4D77-A4DB-4B441A7C9197} = {3D6660F8-52D2-4A30-8F1E-1922DDCF10F9}
{EEC75E83-E284-44E0-B321-3F5C6512074F} = {16553295-E70F-4596-AA78-848EEA576C4A}
{E81B7BD8-A326-47D3-B7EE-E9C7D4D119FA} = {16553295-E70F-4596-AA78-848EEA576C4A}
{B8955CA6-E002-48A6-8FBF-90C2084C3508} = {16553295-E70F-4596-AA78-848EEA576C4A}
{A2FC4D71-1ED9-40D4-B746-FE6AB3C7D55E} = {16553295-E70F-4596-AA78-848EEA576C4A}
{0C73C749-FCAE-4254-A614-AE1B03AF45C9} = {851ADF1E-4500-4A14-B4AA-C1087A6C537E}
{3D833D81-4F14-4A68-B0DE-6469B8CF4E62} = {851ADF1E-4500-4A14-B4AA-C1087A6C537E}
{F714A9FA-1C4B-456B-BACF-D6763223A81C} = {16553295-E70F-4596-AA78-848EEA576C4A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {50B52A67-69B1-4B19-A59C-FF058FD9EBDF}
......
......@@ -76,8 +76,8 @@ OPEN_BVE_FILE :=OpenBve.exe
OPEN_BVE_API_ROOT :=source/OpenBveApi
OPEN_BVE_API_FILE :=OpenBveApi.dll
ASSIMP_X_ROOT :=source/AssimpXParser
ASSIMP_X_FILE :=AssimpXParser.exe
ASSIMP_ROOT :=source/AssimpParser
ASSIMP_FILE :=AssimpParser.dll
DEFAULT_DISPLAY_ROOT :=source/InputDevicePlugins/DefaultDisplayPlugin
DEFAULT_DISPLAY_FILE :=Data/InputDevicePlugins/DefaultDisplayPlugin.dll
......@@ -257,7 +257,7 @@ clean:
# DLL
rm -f bin*/OpenBveApi.dll* bin*/OpenBveApi.pdb
rm -f bin*/AssimpXParser.dll* bin*/AssimpXParser.pdb
rm -f bin*/AssimpParser.dll* bin*/AssimpParser.pdb
rm -f bin*/Data/Formats/Formats.Msts.dll* bin*/Data/Formats/Formats.Msts.pdb
rm -f bin*/Data/Formats/Formats.DirectX.dll* bin*/Data/Formats/Formats.DirectX.pdb
rm -f bin*/Data/InputDevicePlugins/DefaultDisplayPlugin.dll* bin*/Data/InputDevicePlugins/DefaultDisplayPlugin.pdb
......@@ -358,7 +358,7 @@ $(OPEN_BVE_ROOT)/Properties/AssemblyInfo.cs: $(OPEN_BVE_ROOT)/Properties/Assembl
$(call create_resource, $(OPEN_BVE_RESOURCE), $(OPEN_BVE_RESX))
$(DEBUG_DIR)/$(OPEN_BVE_FILE): $(DEBUG_DIR)/$(OPEN_BVE_API_FILE)
$(DEBUG_DIR)/$(OPEN_BVE_FILE): $(DEBUG_DIR)/$(ASSIMP_X_FILE)
$(DEBUG_DIR)/$(OPEN_BVE_FILE): $(DEBUG_DIR)/$(ASSIMP_FILE)
$(DEBUG_DIR)/$(OPEN_BVE_FILE): $(DEBUG_DIR)/$(DEFAULT_DISPLAY_FILE)
$(DEBUG_DIR)/$(OPEN_BVE_FILE): $(DEBUG_DIR)/$(SAN_YING_INPUT_FILE)
$(DEBUG_DIR)/$(OPEN_BVE_FILE): $(DEBUG_DIR)/$(OPEN_BVE_ATS_FILE)
......@@ -374,7 +374,7 @@ $(DEBUG_DIR)/$(OPEN_BVE_FILE): $(DEBUG_DIR)/$(FORMATS_MSTS_FILE)
$(DEBUG_DIR)/$(OPEN_BVE_FILE): $(DEBUG_DIR)/$(FORMATS_DIRECTX_FILE)
$(RELEASE_DIR)/$(OPEN_BVE_FILE): $(RELEASE_DIR)/$(OPEN_BVE_API_FILE)
$(RELEASE_DIR)/$(OPEN_BVE_FILE): $(RELEASE_DIR)/$(ASSIMP_X_FILE)
$(RELEASE_DIR)/$(OPEN_BVE_FILE): $(RELEASE_DIR)/$(ASSIMP_FILE)
$(RELEASE_DIR)/$(OPEN_BVE_FILE): $(RELEASE_DIR)/$(DEFAULT_DISPLAY_FILE)
$(RELEASE_DIR)/$(OPEN_BVE_FILE): $(RELEASE_DIR)/$(SAN_YING_INPUT_FILE)
$(RELEASE_DIR)/$(OPEN_BVE_FILE): $(RELEASE_DIR)/$(OPEN_BVE_ATS_FILE)
......@@ -393,7 +393,7 @@ $(DEBUG_DIR)/$(OPEN_BVE_FILE) $(RELEASE_DIR)/$(OPEN_BVE_FILE): $(OPEN_BVE_ROOT)/
@echo $(COLOR_MAGENTA)Building $(COLOR_CYAN)$(OPEN_BVE_OUT)$(COLOR_END)
@$(CSC) /out:$(OPEN_BVE_OUT) /target:winexe /main:OpenBve.Program $(OPEN_BVE_SRC) $(ARGS) $(OPEN_BVE_DOC) \
$(OPEN_BVE_ROOT)/Properties/AssemblyInfo.cs \
/reference:$(OUTPUT_DIR)/OpenTK.dll /reference:$(OPEN_BVE_API_OUT) /reference:$(ASSIMP_X_OUT) /reference:$(FORMATS_MSTS_OUT) /reference:$(FORMATS_DIRECTX_OUT) \
/reference:$(OUTPUT_DIR)/OpenTK.dll /reference:$(OPEN_BVE_API_OUT) /reference:$(ASSIMP_OUT) /reference:$(FORMATS_MSTS_OUT) /reference:$(FORMATS_DIRECTX_OUT) \
/reference:$(OUTPUT_DIR)/CSScriptLibrary.dll /reference:$(OUTPUT_DIR)/NUniversalCharDet.dll /reference:$(OUTPUT_DIR)/SharpCompress.dll /reference:$(OUTPUT_DIR)/PIEHid32Net.dll \
/reference:System.Core.dll /reference:System.dll \
/win32icon:$(ICON) $(addprefix /resource:, $(OPEN_BVE_RESOURCE))
......@@ -425,28 +425,28 @@ $(DEBUG_DIR)/$(OPEN_BVE_API_FILE) $(RELEASE_DIR)/$(OPEN_BVE_API_FILE): $(OPEN_BV
$(addprefix /resource:, $(OPEN_BVE_API_RESOURCE))
#################
# AssimpXParser #
#################
################
# AssimpParser #
################
ASSIMP_X_FOLDERS := $(shell find $(ASSIMP_X_ROOT) -type d)
ASSIMP_X_SRC := $(foreach sdir, $(ASSIMP_X_FOLDERS), $(wildcard $(sdir)/*.cs))
ASSIMP_X_DOC := $(addprefix /doc:, $(foreach sdir, $(ASSIMP_X_FOLDERS), $(wildcard $(sdir)/*.xml)))
ASSIMP_X_RESX := $(foreach sdir, $(ASSIMP_X_FOLDERS), $(wildcard $(sdir)/*.resx))
ASSIMP_X_RESOURCE := $(addprefix $(ASSIMP_X_ROOT)/, $(subst /,., $(subst /./,/, $(patsubst $(dir $(ASSIMP_X_ROOT))%.resx, %.resources, $(ASSIMP_X_RESX)))))
ASSIMP_X_OUT =$(OUTPUT_DIR)/$(ASSIMP_X_FILE)
ASSIMP_FOLDERS := $(shell find $(ASSIMP_ROOT) -type d)
ASSIMP_SRC := $(foreach sdir, $(ASSIMP_FOLDERS), $(wildcard $(sdir)/*.cs))
ASSIMP_DOC := $(addprefix /doc:, $(foreach sdir, $(ASSIMP_FOLDERS), $(wildcard $(sdir)/*.xml)))
ASSIMP_RESX := $(foreach sdir, $(ASSIMP_FOLDERS), $(wildcard $(sdir)/*.resx))
ASSIMP_RESOURCE := $(addprefix $(ASSIMP_ROOT)/, $(subst /,., $(subst /./,/, $(patsubst $(dir $(ASSIMP_ROOT))%.resx, %.resources, $(ASSIMP_RESX)))))
ASSIMP_OUT =$(OUTPUT_DIR)/$(ASSIMP_FILE)
$(call create_resource, $(ASSIMP_X_RESOURCE), $(ASSIMP_X_RESX))
$(call create_resource, $(ASSIMP_RESOURCE), $(ASSIMP_RESX))
$(DEBUG_DIR)/$(ASSIMP_X_FILE): $(DEBUG_DEPEND)
$(RELEASE_DIR)/$(ASSIMP_X_FILE): $(RELEASE_DEPEND)
$(DEBUG_DIR)/$(ASSIMP_FILE): $(DEBUG_DEPEND)
$(RELEASE_DIR)/$(ASSIMP_FILE): $(RELEASE_DEPEND)
$(DEBUG_DIR)/$(ASSIMP_X_FILE) $(RELEASE_DIR)/$(ASSIMP_X_FILE): $(ASSIMP_X_SRC) $(ASSIMP_X_RESOURCE)
@echo $(COLOR_MAGENTA)Building $(COLOR_CYAN)$(ASSIMP_X_OUT)$(COLOR_END)
@$(CSC) /out:$(ASSIMP_X_OUT) /target:library $(ASSIMP_X_SRC) $(ARGS) $(ASSIMP_X_DOC) \
$(DEBUG_DIR)/$(ASSIMP_FILE) $(RELEASE_DIR)/$(ASSIMP_FILE): $(ASSIMP_SRC) $(ASSIMP_RESOURCE)
@echo $(COLOR_MAGENTA)Building $(COLOR_CYAN)$(ASSIMP_OUT)$(COLOR_END)
@$(CSC) /out:$(ASSIMP_OUT) /target:library $(ASSIMP_SRC) $(ARGS) $(ASSIMP_DOC) \
/reference:$(OUTPUT_DIR)/Ionic.Zlib.dll /reference:$(OUTPUT_DIR)/OpenTK.dll \
/reference:System.Core.dll /reference:System.dll \
$(addprefix /resource:, $(ASSIMP_X_RESOURCE))
$(addprefix /resource:, $(ASSIMP_RESOURCE))
########################
# DefaultDisplayPlugin #
......@@ -780,7 +780,7 @@ $(RELEASE_DIR)/$(OBJECT_VIEWER_FILE): $(RELEASE_DIR)/$(OPEN_BVE_API_FILE)
$(DEBUG_DIR)/$(OBJECT_VIEWER_FILE) $(RELEASE_DIR)/$(OBJECT_VIEWER_FILE): $(OBJECT_VIEWER_SRC) $(OBJECT_VIEWER_RESOURCE)
@echo $(COLOR_MAGENTA)Building $(COLOR_CYAN)$(OBJECT_VIEWER_OUT)$(COLOR_END)
@$(CSC) /out:$(OBJECT_VIEWER_OUT) /target:winexe /main:OpenBve.Program $(OBJECT_VIEWER_SRC) $(ARGS) $(OBJECT_VIEWER_DOC) \
/reference:$(OPEN_BVE_API_OUT) /reference:$(ASSIMP_X_OUT) /reference:$(FORMATS_MSTS_OUT) /reference:$(FORMATS_DIRECTX_OUT) /reference:$(OUTPUT_DIR)/OpenTK.dll /reference:$(OUTPUT_DIR)/SharpCompress.dll /reference:System.Core.dll \
/reference:$(OPEN_BVE_API_OUT) /reference:$(ASSIMP_OUT) /reference:$(FORMATS_MSTS_OUT) /reference:$(FORMATS_DIRECTX_OUT) /reference:$(OUTPUT_DIR)/OpenTK.dll /reference:$(OUTPUT_DIR)/SharpCompress.dll /reference:System.Core.dll \
/win32icon:$(ICON) $(addprefix /resource:, $(OBJECT_VIEWER_RESOURCE))
###############
......
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{572CD7FF-A0C9-4A48-81B7-79B65E37D3C7}</ProjectGuid>
<ProjectGuid>{77CCAE62-D374-468E-98A0-DD8ADB461C10}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AssimpNET</RootNamespace>
<AssemblyName>AssimpXParser</AssemblyName>
<RootNamespace>AssimpParser</RootNamespace>
<AssemblyName>AssimpParser</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
......@@ -33,19 +33,33 @@
<Reference Include="Ionic.Zlib">
<HintPath>..\..\dependencies\Ionic.Zlib.dll</HintPath>
</Reference>
<Reference Include="OpenTK, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="OpenTK">
<HintPath>..\..\dependencies\OpenTK.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DeflateCompression.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XFileHelper.cs" />
<Compile Include="XFileParser.cs" />
<Compile Include="Wavefront\Mesh.cs" />
<Compile Include="Wavefront\ObjFileData.cs" />
<Compile Include="Wavefront\ObjFileMtlImporter.cs" />
<Compile Include="Wavefront\ObjFileParser.cs" />
<Compile Include="Wavefront\ObjTools.cs" />
<Compile Include="X\DeflateCompression.cs" />
<Compile Include="X\XFileHelper.cs" />
<Compile Include="X\XFileParser.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenBveApi\OpenBveApi.csproj">
<Project>{27134980-4415-4375-a564-40a9014dfa5f}</Project>
<Name>OpenBveApi</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
......
using System.Reflection;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
// アセンブリに関連付けられている情報を変更するには、
// これらの属性値を変更してください。
[assembly: AssemblyTitle("AssimpXParser")]
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
// アセンブリに関連付けられている情報を変更するには、
// これらの属性値を変更してください。
[assembly: AssemblyTitle("AssimpParser")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AssimpXParser")]
[assembly: AssemblyProduct("AssimpParser")]
[assembly: AssemblyCopyright("assimp team, The openBVE Project")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから
// 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、
// その型の ComVisible 属性を true に設定してください。
// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから
// 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、
// その型の ComVisible 属性を true に設定してください。
[assembly: ComVisible(false)]
// 次の GUID は、このプロジェクトが COM に公開される場合の、typelib の ID です
[assembly: Guid("af0471c9-5f0b-4ffb-b156-e887c6e9048f")]
// 次の GUID は、このプロジェクトが COM に公開される場合の、typelib の ID です
[assembly: Guid("403e58cc-8713-478f-9deb-6239c07d80e8")]
// アセンブリのバージョン情報は、以下の 4 つの値で構成されています:
// アセンブリのバージョン情報は、以下の 4 つの値で構成されています:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
// Open Asset Import Library (assimp)
//
// Copyright (c) 2006-2016, assimp team, 2018, The openBVE Project
// All rights reserved.
//
// Redistribution and use of this software in source and binary forms,
// with or without modification, are permitted provided that the
// following conditions are met:
//
// * Redistributions of source code must retain the above
// copyright notice, this list of conditions and the
// following disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// * Neither the name of the assimp team, nor the names of its
// contributors may be used to endorse or promote products
// derived from this software without specific prior
// written permission of the assimp team.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//
//
// ******************************************************************************
//
// AN EXCEPTION applies to all files in the ./test/models-nonbsd folder.
// These are 3d models for testing purposes, from various free sources
// on the internet. They are - unless otherwise stated - copyright of
// their respective creators, which may impose additional requirements
// on the use of their work. For any of these models, see
// <model-name>.source.txt for more legal information. Contact us if you
// are a copyright holder and believe that we credited you inproperly or
// if you don't want your files to appear in the repository.
//
//
// ******************************************************************************
//
// Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
// http://code.google.com/p/poly2tri/
//
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Poly2Tri nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace AssimpNET.Obj
{
// ---------------------------------------------------------------------------
/** @brief Enumerates the types of geometric primitives supported by Assimp.
*
* @see aiFace Face data structure
* @see aiProcess_SortByPType Per-primitive sorting of meshes
* @see aiProcess_Triangulate Automatic triangulation
* @see AI_CONFIG_PP_SBP_REMOVE Removal of specific primitive types.
*/
public enum PrimitiveType
{
/** A point primitive.
*
* This is just a single vertex in the virtual world,
* #aiFace contains just one index for such a primitive.
*/
PrimitiveType_POINT = 0x1,
/** A line primitive.
*
* This is a line defined through a start and an end position.
* #aiFace contains exactly two indices for such a primitive.
*/
PrimitiveType_LINE = 0x2,
/** A triangular primitive.
*
* A triangle consists of three indices.
*/
PrimitiveType_TRIANGLE = 0x4,
/** A higher-level polygon with more than 3 edges.
*
* A triangle is a polygon, but polygon in this context means
* "all polygons that are not triangles". The "Triangulate"-Step
* is provided for your convenience, it splits all polygons in
* triangles (which are much easier to handle).
*/
PrimitiveType_POLYGON = 0x8
};
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -84,7 +84,7 @@ using VectorKey = System.Collections.Generic.KeyValuePair<double, OpenTK.Vector3
using QuatKey = System.Collections.Generic.KeyValuePair<double, OpenTK.Quaternion>;
using MatrixKey = System.Collections.Generic.KeyValuePair<double, OpenTK.Matrix4>;
namespace AssimpNET
namespace AssimpNET.X
{
/** Helper structure representing a XFile mesh face */
public class Face
......
......@@ -91,7 +91,7 @@ using VectorKey = System.Collections.Generic.KeyValuePair<double, OpenTK.Vector3
using QuatKey = System.Collections.Generic.KeyValuePair<double, OpenTK.Quaternion>;
using MatrixKey = System.Collections.Generic.KeyValuePair<double, OpenTK.Matrix4>;
namespace AssimpNET
namespace AssimpNET.X
{
public class XFileParser
{
......
......@@ -119,7 +119,8 @@ namespace OpenBve {
internal int AntialiasingLevel;
internal int ObjectOptimizationBasicThreshold;
internal int ObjectOptimizationFullThreshold;
internal int UseNewXParser;
internal int CurrentXParser;
internal int CurrentObjParser;
}
internal static Options CurrentOptions;
......
......@@ -1541,11 +1541,11 @@ namespace OpenBve
Result = CsvB3dObjectParser.ReadObject(FileName, Encoding, LoadMode, ForceTextureRepeatX, ForceTextureRepeatY);
break;
case ".x":
if (Interface.CurrentOptions.UseNewXParser > 0)
if (Interface.CurrentOptions.CurrentXParser > 0)
{
try
{
if (Interface.CurrentOptions.UseNewXParser == 1)
if (Interface.CurrentOptions.CurrentXParser == 1)
{
Result = NewXParser.ReadObject(FileName, Encoding, LoadMode);
}
......@@ -1576,7 +1576,22 @@ namespace OpenBve
Result = Ls3DGrpParser.ReadObject(FileName, Encoding, LoadMode, Rotation);
break;
case ".obj":
if (Interface.CurrentOptions.CurrentObjParser == 1)
{
try
{
Result = AssimpObjParser.ReadObject(FileName);
}
catch (Exception e)
{
Interface.AddMessage(MessageType.Error, false, "The new Obj parser raised the following exception: " + e);
Result = WavefrontObjParser.ReadObject(FileName, Encoding, LoadMode, ForceTextureRepeatX, ForceTextureRepeatY);
}
}
else
{
Result = WavefrontObjParser.ReadObject(FileName, Encoding, LoadMode, ForceTextureRepeatX, ForceTextureRepeatY);
}
break;
case ".s":
Result = MsTsShapeParser.ReadObject(FileName);
......@@ -1637,11 +1652,11 @@ namespace OpenBve
Result = CsvB3dObjectParser.ReadObject(FileName, Encoding, LoadMode, ForceTextureRepeatX, ForceTextureRepeatY);
break;
case ".x":
if (Interface.CurrentOptions.UseNewXParser > 0)
if (Interface.CurrentOptions.CurrentXParser > 0)
{
try
{
if (Interface.CurrentOptions.UseNewXParser == 1)
if (Interface.CurrentOptions.CurrentXParser == 1)
{
Result = NewXParser.ReadObject(FileName, Encoding, LoadMode);
}
......@@ -1672,7 +1687,22 @@ namespace OpenBve
Interface.AddMessage(MessageType.Error, false, "Tried to load an animated object even though only static objects are allowed: " + FileName);
return null;
case ".obj":
if (Interface.CurrentOptions.CurrentObjParser == 1)
{
try
{
Result = AssimpObjParser.ReadObject(FileName);
}
catch (Exception e)
{
Interface.AddMessage(MessageType.Error, false, "The new Obj parser raised the following exception: " + e);
Result = WavefrontObjParser.ReadObject(FileName, Encoding, LoadMode, ForceTextureRepeatX, ForceTextureRepeatY);
}
}
else
{
Result = WavefrontObjParser.ReadObject(FileName, Encoding, LoadMode, ForceTextureRepeatX, ForceTextureRepeatY);
}
break;
default:
Interface.AddMessage(MessageType.Error, false, "The file extension is not supported: " + FileName);
......
......@@ -80,6 +80,7 @@
<Compile Include="FunctionScripts.cs" />
<Compile Include="Hosts.cs" />
<Compile Include="Options.cs" />
<Compile Include="Parsers\AssimpObjParser.cs" />
<Compile Include="Parsers\Generic\AssimpXParser.cs" />
<Compile Include="Parsers\Ls3DGrpParser.cs" />
<Compile Include="Parsers\Ls3DObjectParser.cs" />
......@@ -121,9 +122,9 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AssimpXParser\AssimpXParser.csproj">
<Project>{572cd7ff-a0c9-4a48-81b7-79b65e37d3c7}</Project>
<Name>AssimpXParser</Name>
<ProjectReference Include="..\AssimpParser\AssimpParser.csproj">
<Project>{77ccae62-d374-468e-98a0-dd8adb461c10}</Project>
<Name>AssimpParser</Name>
</ProjectReference>
<ProjectReference Include="..\OpenBveApi\OpenBveApi.csproj">
<Project>{27134980-4415-4375-A564-40A9014DFA5F}</Project>
......@@ -136,7 +137,7 @@
</ProjectReference>
<ProjectReference Include="..\Plugins\Formats.Msts\Formats.Msts.csproj">
<Project>{E81B7BD8-A326-47D3-B7EE-E9C7D4D119FA}</Project>
<Name>OpenBve.Formats.Msts</Name>
<Name>Formats.Msts</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
......
......@@ -130,6 +130,36 @@ namespace OpenBve
}
} break;
} break;
case "parsers":
switch (Key)
{
case "xobject":
{
int p;
if (!int.TryParse(Value, NumberStyles.Integer, Culture, out p) || p < 0 || p > 3)
{
Interface.CurrentOptions.CurrentXParser = 0;
}
else
{
Interface.CurrentOptions.CurrentXParser = p;
}
break;
}
case "objobject":
{
int p;
if (!int.TryParse(Value, NumberStyles.Integer, Culture, out p) || p < 0 || p > 2)
{
Interface.CurrentOptions.CurrentObjParser = 0;
}
else
{
Interface.CurrentOptions.CurrentObjParser = p;
}
break;
}
} break;
}
}
}
......@@ -169,6 +199,10 @@ namespace OpenBve
Builder.AppendLine("anisotropicfilteringlevel = " + Interface.CurrentOptions.AnisotropicFilteringLevel.ToString(Culture));
Builder.AppendLine("antialiasinglevel = " + Interface.CurrentOptions.AntialiasingLevel.ToString(Culture));
Builder.AppendLine("transparencyMode = " + ((int)Interface.CurrentOptions.TransparencyMode).ToString(Culture));
Builder.AppendLine();
Builder.AppendLine("[Parsers]");
Builder.AppendLine("xObject = " + Interface.CurrentOptions.CurrentXParser);
Builder.AppendLine("objObject = " + Interface.CurrentOptions.CurrentObjParser);
string configFile = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "1.5.0/options_ov.cfg");
System.IO.File.WriteAllText(configFile, Builder.ToString(), new System.Text.UTF8Encoding(true));
}
......
using System;
using System.Collections.Generic;
using OpenBveApi.Colors;
using OpenBveApi.Interface;
using OpenBveApi.Math;
using OpenBveApi.Objects;
using AssimpNET.Obj;
namespace OpenBve
{
class AssimpObjParser
{
private static string currentFolder;
private static string currentFile;
internal static ObjectManager.StaticObject ReadObject(string FileName)
{
currentFolder = System.IO.Path.GetDirectoryName(FileName);
currentFile = FileName;
#if !DEBUG
try
{
#endif
ObjFileParser parser = new ObjFileParser(System.IO.File.ReadAllLines(currentFile), null, System.IO.Path.GetFileNameWithoutExtension(currentFile), currentFile);
Model model = parser.GetModel();
ObjectManager.StaticObject obj = new ObjectManager.StaticObject();
obj.Mesh.Faces = new World.MeshFace[] { };
obj.Mesh.Materials = new World.MeshMaterial[] { };
obj.Mesh.Vertices = new VertexTemplate[] { };
MeshBuilder builder = new MeshBuilder();
List<Vertex> allVertices = new List<Vertex>();
foreach (var vertex in model.Vertices)
{
allVertices.Add(new Vertex(vertex.X, vertex.Y, vertex.Z));
}
List<Vector2> allTexCoords = new List<Vector2>();
foreach (var texCoord in model.TextureCoord)
{
allTexCoords.Add(new Vector2(texCoord.X, texCoord.Y));
}
List<Vector3> allNormals = new List<Vector3>();
foreach (var normal in model.Normals)
{
allNormals.Add(new Vector3(normal.X, normal.Y, normal.Z));
}
foreach (Mesh mesh in model.Meshes)
{
foreach (Face face in mesh.Faces)
{
int nVerts = face.Vertices.Count;
if (nVerts == 0)
{
throw new Exception("nVertices must be greater than zero");
}
int v = builder.Vertices.Length;
Array.Resize(ref builder.Vertices, v + nVerts);
for (int i = 0; i < nVerts; i++)
{
builder.Vertices[v + i] = allVertices[(int)face.Vertices[i]];
}
int f = builder.Faces.Length;
Array.Resize(ref builder.Faces, f + 1);
builder.Faces[f] = new World.MeshFace();
builder.Faces[f].Vertices = new World.MeshFaceVertex[nVerts];
for (int i = 0; i < nVerts; i++)
{
builder.Faces[f].Vertices[i].Index = (ushort)i;
}
builder.Faces[f].Material = 1;
int m = builder.Materials.Length;
Array.Resize(ref builder.Materials, m + 1);
builder.Materials[m] = new Material();
uint materialIndex = mesh.MaterialIndex;
if (materialIndex != AssimpNET.Obj.Mesh.NoMaterial)
{
AssimpNET.Obj.Material material = model.MaterialMap[model.MaterialLib[(int)materialIndex]];
builder.Materials[m].Color = new Color32((byte)(255 * material.Diffuse.R), (byte)(255 * material.Diffuse.G), (byte)(255 * material.Diffuse.B), (byte)(255 * material.Diffuse.A));
Color24 mSpecular = new Color24((byte)material.Specular.R, (byte)material.Specular.G, (byte)material.Specular.B);
builder.Materials[m].EmissiveColor = new Color24((byte)(255 * material.Emissive.R), (byte)(255 * material.Emissive.G), (byte)(255 * material.Emissive.B));
builder.Materials[m].EmissiveColorUsed = true; //TODO: Check exact behaviour
builder.Materials[m].TransparentColor = new Color24((byte)(255 * material.Transparent.R), (byte)(255 * material.Transparent.G), (byte)(255 * material.Transparent.B));
builder.Materials[m].TransparentColorUsed = true;
if (material.Texture != null)
{
builder.Materials[m].DaytimeTexture = OpenBveApi.Path.CombineFile(currentFolder, material.Texture);
if (!System.IO.File.Exists(builder.Materials[m].DaytimeTexture))
{
Interface.AddMessage(MessageType.Error, true, "Texure " + builder.Materials[m].DaytimeTexture + " was not found in file " + currentFile);
builder.Materials[m].DaytimeTexture = null;
}
}
}
int nCoords = face.TexturCoords.Count;
for (int i = 0; i < nCoords; i++)
{
builder.Vertices[i].TextureCoordinates = allTexCoords[(int)face.TexturCoords[i]];
}
int nNormals = face.Normals.Count;
Vector3[] normals = new Vector3[nNormals];
for (int i = 0; i < nNormals; i++)
{
normals[i] = allNormals[(int)face.Normals[i]];
normals[i].Normalize();
}
for (int i = 0; i < nNormals; i++)
{
builder.Faces[0].Vertices[i].Normal = normals[i];
}
builder.Apply(ref obj);
builder = new MeshBuilder();
}
}
obj.Mesh.CreateNormals();
return obj;
#if !DEBUG
}
catch (Exception e)