Merge pull request #55 from specklesystems/origin/texture-coordinates-fix
Updates to Mesh conversion - Texcoords, N-gons, displayValue, Normals
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56f15216bd310954bb57d0900839c613
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Normals
|
||||
m_Shader: {fileID: 4800000, guid: 75756b5b04ca7b5438e346a8f9f754ba, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats: []
|
||||
m_Colors: []
|
||||
m_BuildTextureStacks: []
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 763d54739fbe63e4bbd1598690d1af38
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
Shader "Unlit/Normals"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
half3 normal : NORMAL;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
half3 normal : NORMAL;
|
||||
};
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.normal = v.normal;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag (v2f i) : SV_Target
|
||||
{
|
||||
half4 color = 0;
|
||||
color.rgb = i.normal * 0.5 + 0.5;
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75756b5b04ca7b5438e346a8f9f754ba
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,87 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: SpeckleSurface
|
||||
m_Shader: {fileID: 4800000, guid: 837fc98dbf6a92c479b902184ca947bf, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _GridSize: 128
|
||||
- _Margin: 0.15
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _Mul: 8192
|
||||
- _NormalSaturation: 0.03
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _Saturation: 0.323
|
||||
- _SmoothnessSaturation: 0.02
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Thickness: 0.32
|
||||
- _UVSec: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Color0: {r: 0.6, g: 0.6, b: 0.6, a: 1}
|
||||
- _Color1: {r: 0.57, g: 0.57, b: 0.57, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2830afbce900e634985de6a3930d9608
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,128 @@
|
||||
Shader "Custom/SpeckleSurface"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[Header(Cube)]
|
||||
_Thickness("Thickness", Range(0, 1)) = 0.32
|
||||
_Margin("Margin", Range(0, 1)) = 0.15
|
||||
_NormalSaturation("Normal Saturation", range(0,1)) = 0.03
|
||||
_SmoothnessSaturation("Smoothness Saturation", range(0,1)) = 0.02
|
||||
|
||||
[Header(Tiling)]
|
||||
_Mul("Multiple", int) = 8192
|
||||
_GridSize("Grid Size", int) = 128
|
||||
|
||||
_Color0("Color 0", Color) = (0.6, 0.6, 0.6, 1)
|
||||
_Color1("Color 1", Color) = (0.57, 0.57, 0.57, 1)
|
||||
_MainTex ("Albedo (RGB)", 2D) = "white" {}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 200
|
||||
|
||||
CGPROGRAM
|
||||
// Physically based Standard lighting model, and enable shadows on all light types
|
||||
#pragma surface surf Standard fullforwardshadows
|
||||
|
||||
// Use shader model 3.0 target, to get nicer looking lighting
|
||||
//#pragma target 3.0
|
||||
|
||||
struct Input
|
||||
{
|
||||
float2 uv_MainTex;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
float _Thickness;
|
||||
float _Margin;
|
||||
int _Mul;
|
||||
int _GridSize;
|
||||
|
||||
fixed4 _Color0;
|
||||
fixed4 _Color1;
|
||||
float _NormalSaturation;
|
||||
float _SmoothnessSaturation;
|
||||
|
||||
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
|
||||
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
|
||||
// #pragma instancing_options assumeuniformscaling
|
||||
//UNITY_INSTANCING_BUFFER_START(Props)
|
||||
// put more per-instance properties here
|
||||
//UNITY_INSTANCING_BUFFER_END(Props)
|
||||
|
||||
|
||||
fixed speckleSample(float2 pos)
|
||||
{
|
||||
// sample the texture
|
||||
const fixed top = +0.5;
|
||||
const fixed left = -1;
|
||||
const fixed base = -0.5;
|
||||
|
||||
bool invert;
|
||||
{ //Fine Grid
|
||||
float2 grid_pos = (pos + 0.5) * _Mul / 2.0;
|
||||
grid_pos = grid_pos - floor(grid_pos);
|
||||
invert = grid_pos.x > 0.5 ^ grid_pos.y > 0.5;
|
||||
}
|
||||
|
||||
|
||||
float2 cell_pos = (pos + 0.5) * _Mul;
|
||||
cell_pos = cell_pos - floor(cell_pos);
|
||||
//cell_pos between 0-1 for each Speckle cube
|
||||
|
||||
fixed grey;
|
||||
|
||||
//Cube
|
||||
{
|
||||
if(cell_pos.x + cell_pos.y < 1.0)
|
||||
grey = left;
|
||||
else
|
||||
grey = top;
|
||||
|
||||
if(cell_pos.x > _Thickness && cell_pos.y < 1.0 -_Thickness)
|
||||
grey = base;
|
||||
}
|
||||
|
||||
if(invert) grey = grey - 1;
|
||||
|
||||
//Ears
|
||||
if( cell_pos.x + cell_pos.y < _Thickness
|
||||
|| 1.0 - cell_pos.x + 1.0 - cell_pos.y < _Thickness)
|
||||
{
|
||||
grey = 0;
|
||||
}
|
||||
|
||||
//Margins
|
||||
const bool inCube = cell_pos.x > _Margin && cell_pos.y < 1.0 -_Margin;
|
||||
if(!inCube) grey = 0;
|
||||
|
||||
return grey;
|
||||
}
|
||||
|
||||
|
||||
void surf (Input IN, inout SurfaceOutputStandard o)
|
||||
{
|
||||
fixed4 background = _Color0;
|
||||
|
||||
//Coarse grid
|
||||
float2 grid_pos = (IN.uv_MainTex + 0.5) * _Mul / _GridSize;
|
||||
grid_pos = grid_pos - floor(grid_pos);
|
||||
if(grid_pos.x > 0.5 ^ grid_pos.y > 0.5)
|
||||
{
|
||||
background = _Color1;
|
||||
}
|
||||
|
||||
const half grey = speckleSample(IN.uv_MainTex);
|
||||
|
||||
o.Albedo = background;
|
||||
o.Metallic = 0.0;
|
||||
o.Normal = o.Normal + (grey + 1) * _NormalSaturation;
|
||||
o.Smoothness = grey * _SmoothnessSaturation;
|
||||
o.Alpha = background.a;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
FallBack "Diffuse"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 837fc98dbf6a92c479b902184ca947bf
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
Shader "Unlit/UVs"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float2 colors : TEXCOORD0;
|
||||
};
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.colors = v.uv;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag (v2f i) : SV_Target
|
||||
{
|
||||
return half4(i.colors.x, i.colors.y, 0, 0);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6778d5072232804689f36bb771a2122
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Uvs
|
||||
m_Shader: {fileID: 4800000, guid: f6778d5072232804689f36bb771a2122, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _UVSec: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fe0ba5d1c59c7548be17ef9fb8e2e40
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: VertexColors
|
||||
m_Shader: {fileID: 4800000, guid: 3b849de517d871d46874414758a096f2, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _Shininess: 0.078125
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _SpecColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c84690dfb148c6e4f8343f76b3cad987
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
Shader "Unlit/VertexColors"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
half4 color : COLOR0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
half4 color : COLOR0;
|
||||
};
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.color = v.color;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag (v2f i) : SV_Target
|
||||
{
|
||||
return i.color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b849de517d871d46874414758a096f2
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Speckle.Core.Api;
|
||||
using Speckle.Core.Logging;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -157,6 +158,13 @@ namespace Speckle.ConnectorUnity
|
||||
statusText.text = $"Sent {commitId}";
|
||||
sendProgress.gameObject.SetActive(false); //hide
|
||||
});
|
||||
},
|
||||
onErrorAction: (id, e) =>
|
||||
{
|
||||
MakeButtonsInteractable(true);
|
||||
statusText.text = $"Error {id}";
|
||||
sendProgress.gameObject.SetActive(false); //hide
|
||||
throw new SpeckleException(e.Message, e);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Speckle.ConnectorUnity
|
||||
private List<Stream> StreamList = null;
|
||||
private Stream SelectedStream = null;
|
||||
private List<GameObject> StreamPanels = new List<GameObject>();
|
||||
|
||||
|
||||
async void Start()
|
||||
{
|
||||
@@ -40,7 +41,7 @@ namespace Speckle.ConnectorUnity
|
||||
|
||||
SelectStreamText.text = $"Select a stream on {defaultAccount.serverInfo.name}:";
|
||||
|
||||
StreamList = await Streams.List();
|
||||
StreamList = await Streams.List(30);
|
||||
if (!StreamList.Any())
|
||||
{
|
||||
Debug.Log("There are no streams in your account, please create one online.");
|
||||
@@ -82,7 +83,7 @@ namespace Speckle.ConnectorUnity
|
||||
private async void AddReceiver()
|
||||
{
|
||||
var autoReceive = AutoReceiveToggle.isOn;
|
||||
var stream = await Streams.Get(SelectedStream.id, 10);
|
||||
var stream = await Streams.Get(SelectedStream.id, 30);
|
||||
|
||||
var streamPrefab = Instantiate(StreamPanel, new Vector3(0, 0, 0),
|
||||
Quaternion.identity);
|
||||
|
||||
@@ -1245,7 +1245,7 @@ MeshCollider:
|
||||
m_GameObject: {fileID: 512580998}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
m_Enabled: 0
|
||||
serializedVersion: 4
|
||||
m_Convex: 1
|
||||
m_CookingOptions: 30
|
||||
@@ -1269,7 +1269,7 @@ MeshRenderer:
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||
- {fileID: 2100000, guid: 2830afbce900e634985de6a3930d9608, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
@@ -1298,7 +1298,7 @@ MeshFilter:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 512580998}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!4 &512581002
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1308,7 +1308,7 @@ Transform:
|
||||
m_GameObject: {fileID: 512580998}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: -2.5, z: 0}
|
||||
m_LocalScale: {x: 500, y: 0.1, z: 500}
|
||||
m_LocalScale: {x: 512, y: 1, z: 512}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 2
|
||||
@@ -4181,7 +4181,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2068176107}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -30.5}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -32}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
"dependencies": {
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.collab-proxy": "1.13.5",
|
||||
"com.unity.ide.rider": "2.0.7",
|
||||
"com.unity.ide.visualstudio": "2.0.11",
|
||||
"com.unity.ide.rider": "3.0.7",
|
||||
"com.unity.ide.visualstudio": "2.0.12",
|
||||
"com.unity.ide.vscode": "1.2.4",
|
||||
"com.unity.test-framework": "1.1.29",
|
||||
"com.unity.test-framework": "1.1.30",
|
||||
"com.unity.textmeshpro": "3.0.6",
|
||||
"com.unity.timeline": "1.4.8",
|
||||
"com.unity.ugui": "1.0.0",
|
||||
|
||||
@@ -24,16 +24,16 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.rider": {
|
||||
"version": "2.0.7",
|
||||
"version": "3.0.7",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.test-framework": "1.1.1"
|
||||
"com.unity.ext.nunit": "1.0.6"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.visualstudio": {
|
||||
"version": "2.0.11",
|
||||
"version": "2.0.12",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@@ -65,7 +65,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.test-framework": {
|
||||
"version": "1.1.29",
|
||||
"version": "1.1.30",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
using Objects.Geometry;
|
||||
using System;
|
||||
using System;
|
||||
using Objects.Geometry;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Objects.Other;
|
||||
using Objects.Primitive;
|
||||
using Objects.Utils;
|
||||
using Speckle.ConnectorUnity;
|
||||
using Speckle.Core.Models;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using Mesh = Objects.Geometry.Mesh;
|
||||
using Object = UnityEngine.Object;
|
||||
using SColor = System.Drawing.Color;
|
||||
|
||||
namespace Objects.Converter.Unity
|
||||
{
|
||||
public partial class ConverterUnity
|
||||
{
|
||||
|
||||
private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor");
|
||||
private static readonly int Metallic = Shader.PropertyToID("_Metallic");
|
||||
private static readonly int Glossiness = Shader.PropertyToID("_Glossiness");
|
||||
|
||||
#region helper methods
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -57,14 +64,14 @@ namespace Objects.Converter.Unity
|
||||
/// </summary>
|
||||
/// <param name="arr"></param>
|
||||
/// <returns></returns>
|
||||
public Vector3[] ArrayToPoints(IEnumerable<double> arr, string units)
|
||||
public Vector3[] ArrayToPoints(IList<double> arr, string units)
|
||||
{
|
||||
if (arr.Count() % 3 != 0) throw new Exception("Array malformed: length%3 != 0.");
|
||||
if (arr.Count % 3 != 0) throw new Exception("Array malformed: length%3 != 0.");
|
||||
|
||||
Vector3[] points = new Vector3[arr.Count() / 3];
|
||||
var asArray = arr.ToArray();
|
||||
for (int i = 2, k = 0; i < arr.Count(); i += 3)
|
||||
points[k++] = VectorByCoordinates(asArray[i - 2], asArray[i - 1], asArray[i], units);
|
||||
Vector3[] points = new Vector3[arr.Count / 3];
|
||||
|
||||
for (int i = 2, k = 0; i < arr.Count; i += 3)
|
||||
points[k++] = VectorByCoordinates(arr[i - 2], arr[i - 1], arr[i], units);
|
||||
|
||||
|
||||
return points;
|
||||
@@ -109,53 +116,62 @@ namespace Objects.Converter.Unity
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Speckle mesh to a GameObject with a mesh renderer
|
||||
/// Converts the <see cref="MeshFilter"/> component on <paramref name="go"/> into a Speckle <see cref="Mesh"/>
|
||||
/// </summary>
|
||||
/// <param name="speckleMesh"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="go">The Unity <see cref="GameObject"/> to convert</param>
|
||||
/// <returns>The converted <see cref="Mesh"/>, <see langword="null"/> if no <see cref="MeshFilter"/> on <paramref name="go"/> exists</returns>
|
||||
public Mesh MeshToSpeckle(GameObject go)
|
||||
{
|
||||
//TODO: support multiple filters?
|
||||
var filter = go.GetComponent<MeshFilter>();
|
||||
if (filter == null)
|
||||
if (filter == null) return null;
|
||||
|
||||
var nativeMesh = filter.mesh;
|
||||
|
||||
var nTriangles = nativeMesh.triangles;
|
||||
List<int> sFaces = new List<int>(nTriangles.Length * 4);
|
||||
for (int i = 2; i < nTriangles.Length; i += 3)
|
||||
{
|
||||
return null;
|
||||
sFaces.Add(0); //Triangle cardinality indicator
|
||||
|
||||
sFaces.Add(nTriangles[i]);
|
||||
sFaces.Add(nTriangles[i - 1]);
|
||||
sFaces.Add(nTriangles[i - 2]);
|
||||
}
|
||||
|
||||
//convert triangle array into speckleMesh faces
|
||||
List<int> faces = new List<int>();
|
||||
int i = 0;
|
||||
//store them here, makes it like 1000000x faster?
|
||||
var triangles = filter.mesh.triangles;
|
||||
while (i < triangles.Length)
|
||||
var nVertices = nativeMesh.vertices;
|
||||
List<double> sVertices = new List<double>(nVertices.Length * 3);
|
||||
foreach (var vertex in nVertices)
|
||||
{
|
||||
faces.Add(0);
|
||||
var p = go.transform.TransformPoint(vertex);
|
||||
sVertices.Add(p.x);
|
||||
sVertices.Add(p.z); //z and y swapped
|
||||
sVertices.Add(p.y);
|
||||
}
|
||||
|
||||
var nColors = nativeMesh.colors;
|
||||
List<int> sColors = new List<int>(nColors.Length);
|
||||
sColors.AddRange(nColors.Select(c => c.ToIntColor()));
|
||||
|
||||
faces.Add(triangles[i + 0]);
|
||||
faces.Add(triangles[i + 2]);
|
||||
faces.Add(triangles[i + 1]);
|
||||
i += 3;
|
||||
var nTexCoords = nativeMesh.uv;
|
||||
List<double> sTexCoords = new List<double>(nTexCoords.Length * 2);
|
||||
foreach (var uv in nTexCoords)
|
||||
{
|
||||
sTexCoords.Add(uv.x);
|
||||
sTexCoords.Add(uv.y);
|
||||
}
|
||||
|
||||
var mesh = new Mesh();
|
||||
// get the speckle data from the go here
|
||||
// so that if the go comes from speckle, typed props will get overridden below
|
||||
AttachUnityProperties(mesh, go);
|
||||
|
||||
|
||||
mesh.vertices = sVertices;
|
||||
mesh.faces = sFaces;
|
||||
mesh.colors = sColors;
|
||||
mesh.textureCoordinates = sTexCoords;
|
||||
mesh.units = ModelUnits;
|
||||
|
||||
var vertices = filter.mesh.vertices;
|
||||
foreach (var vertex in vertices)
|
||||
{
|
||||
var p = go.transform.TransformPoint(vertex);
|
||||
var sp = PointToSpeckle(p);
|
||||
mesh.vertices.Add(sp.x);
|
||||
mesh.vertices.Add(sp.y);
|
||||
mesh.vertices.Add(sp.z);
|
||||
}
|
||||
|
||||
mesh.faces = faces;
|
||||
|
||||
return mesh;
|
||||
}
|
||||
#endregion
|
||||
@@ -181,7 +197,7 @@ namespace Objects.Converter.Unity
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Speckle point to a GameObject with a line renderer
|
||||
/// Converts a Speckle <paramref name="point"/> to a <see cref="GameObject"/> with a <see cref="LineRenderer"/>
|
||||
/// </summary>
|
||||
/// <param name="point"></param>
|
||||
/// <returns></returns>
|
||||
@@ -189,13 +205,13 @@ namespace Objects.Converter.Unity
|
||||
{
|
||||
Vector3 newPt = VectorByCoordinates(point.x, point.y, point.z, point.units);
|
||||
|
||||
var go = NewPointBasedGameObject(new Vector3[2] { newPt, newPt }, point.speckle_type);
|
||||
var go = NewPointBasedGameObject(new Vector3[] { newPt, newPt }, point.speckle_type);
|
||||
return go;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Speckle line to a GameObject with a line renderer
|
||||
/// Converts a Speckle <paramref name="line"/> to a <see cref="GameObject"/> with a <see cref="LineRenderer"/>
|
||||
/// </summary>
|
||||
/// <param name="line"></param>
|
||||
/// <returns></returns>
|
||||
@@ -208,145 +224,52 @@ namespace Objects.Converter.Unity
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Speckle polyline to a GameObject with a line renderer
|
||||
/// Converts a Speckle <paramref name="polyline"/> to a <see cref="GameObject"/> with a <see cref="LineRenderer"/>
|
||||
/// </summary>
|
||||
/// <param name="polyline"></param>
|
||||
/// <returns></returns>
|
||||
public GameObject PolylineToNative(Polyline polyline)
|
||||
{
|
||||
var points = polyline.points.Select(x => VectorFromPoint(x));
|
||||
var points = polyline.GetPoints().Select(VectorFromPoint);
|
||||
|
||||
var go = NewPointBasedGameObject(points.ToArray(), polyline.speckle_type);
|
||||
return go;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Speckle curve to a GameObject with a line renderer
|
||||
/// Converts a Speckle <paramref name="curve"/> to a <see cref="GameObject"/> with a <see cref="LineRenderer"/>
|
||||
/// </summary>
|
||||
/// <param name="curve"></param>
|
||||
/// <returns></returns>
|
||||
public GameObject CurveToNative(Curve curve)
|
||||
{
|
||||
var points = ArrayToPoints(curve.points, curve.units);
|
||||
var go = NewPointBasedGameObject(points.ToArray(), curve.speckle_type);
|
||||
var go = NewPointBasedGameObject(points, curve.speckle_type);
|
||||
return go;
|
||||
}
|
||||
|
||||
|
||||
public GameObject MeshToNative(Base speckleMeshObject)
|
||||
{
|
||||
if (!(speckleMeshObject["displayMesh"] is Mesh))
|
||||
return null;
|
||||
|
||||
return MeshToNative(speckleMeshObject["displayMesh"] as Mesh,
|
||||
speckleMeshObject["renderMaterial"] as RenderMaterial, speckleMeshObject.GetMembers());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Speckle mesh to a GameObject with a mesh renderer
|
||||
/// Converts multiple <paramref name="meshes"/> (e.g. with different materials) into one native mesh
|
||||
/// </summary>
|
||||
/// <param name="speckleMesh">Mesh to convert</param>
|
||||
/// <param name="renderMaterial">If provided will override the renderMaterial on the mesh itself</param>
|
||||
/// <param name="properties">If provided will override the properties on the mesh itself</param>
|
||||
/// <returns></returns>
|
||||
public GameObject MeshToNative(
|
||||
Mesh speckleMesh, RenderMaterial renderMaterial = null,
|
||||
Dictionary<string, object> properties = null
|
||||
)
|
||||
/// <param name="element">The <see cref="Base"/> element from which properties should be grabbed from</param>
|
||||
/// <param name="meshes">Collection of <see cref="Objects.Geometry.Mesh"/>es that shall be converted</param>
|
||||
/// <param name="properties">If provided, will override the properties on the mesh itself</param>
|
||||
/// <returns>A <see cref="GameObject"/> with the converted <see cref="UnityEngine.Mesh"/>, <see cref="MeshFilter"/>, and <see cref="MeshRenderer"/></returns>
|
||||
public GameObject MeshesToNative(Base element, IReadOnlyCollection<Mesh> meshes, Dictionary<string, object> properties = null)
|
||||
{
|
||||
if (speckleMesh.vertices.Count == 0 || speckleMesh.faces.Count == 0)
|
||||
MeshDataToNative(meshes, out var nativeMesh, out var nativeMaterials);
|
||||
|
||||
var go = new GameObject
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var recenterMeshTransforms = true; //TODO: figure out how best to change this?
|
||||
|
||||
|
||||
var verts = ArrayToPoints(speckleMesh.vertices, speckleMesh.units);
|
||||
|
||||
|
||||
//convert speckleMesh.faces into triangle array
|
||||
List<int> tris = new List<int>();
|
||||
int i = 0;
|
||||
// TODO: Check if this is causing issues with normals for mesh
|
||||
while (i < speckleMesh.faces.Count)
|
||||
{
|
||||
if (speckleMesh.faces[i] == 0)
|
||||
{
|
||||
//Triangles
|
||||
tris.Add(speckleMesh.faces[i + 1]);
|
||||
tris.Add(speckleMesh.faces[i + 3]);
|
||||
tris.Add(speckleMesh.faces[i + 2]);
|
||||
i += 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Quads to triangles
|
||||
tris.Add(speckleMesh.faces[i + 1]);
|
||||
tris.Add(speckleMesh.faces[i + 3]);
|
||||
tris.Add(speckleMesh.faces[i + 2]);
|
||||
|
||||
tris.Add(speckleMesh.faces[i + 1]);
|
||||
tris.Add(speckleMesh.faces[i + 4]);
|
||||
tris.Add(speckleMesh.faces[i + 3]);
|
||||
|
||||
i += 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var go = new GameObject { name = speckleMesh.speckle_type };
|
||||
var mesh = new UnityEngine.Mesh { name = speckleMesh.speckle_type };
|
||||
|
||||
if (verts.Length >= 65535)
|
||||
mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
|
||||
|
||||
|
||||
// center transform pivot according to the bounds of the model
|
||||
if (recenterMeshTransforms)
|
||||
{
|
||||
Bounds meshBounds = new Bounds
|
||||
{
|
||||
center = verts[0]
|
||||
};
|
||||
|
||||
foreach (var vert in verts)
|
||||
{
|
||||
meshBounds.Encapsulate(vert);
|
||||
}
|
||||
|
||||
go.transform.position = meshBounds.center;
|
||||
|
||||
// offset mesh vertices
|
||||
for (int l = 0; l < verts.Length; l++)
|
||||
{
|
||||
verts[l] -= meshBounds.center;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
mesh.SetVertices(verts);
|
||||
mesh.SetTriangles(tris, 0);
|
||||
|
||||
if (speckleMesh.bbox != null)
|
||||
{
|
||||
var uv = GenerateUV(verts, (float)speckleMesh.bbox.xSize.Length, (float)speckleMesh.bbox.ySize.Length).ToList();
|
||||
mesh.SetUVs(0, uv);
|
||||
|
||||
}
|
||||
|
||||
// BUG: causing some funky issues with meshes
|
||||
// mesh.RecalculateNormals( );
|
||||
mesh.Optimize();
|
||||
// Setting mesh to filter once all mesh modifying is done
|
||||
go.SafeMeshSet(mesh, true);
|
||||
|
||||
|
||||
name = element.speckle_type
|
||||
};
|
||||
|
||||
go.SafeMeshSet(nativeMesh, true);
|
||||
|
||||
var meshRenderer = go.AddComponent<MeshRenderer>();
|
||||
var speckleMaterial = renderMaterial ?? (RenderMaterial)speckleMesh["renderMaterial"];
|
||||
meshRenderer.sharedMaterial = GetMaterial(speckleMaterial);
|
||||
|
||||
meshRenderer.sharedMaterials = nativeMaterials;
|
||||
//Add mesh collider
|
||||
// MeshCollider mc = go.AddComponent<MeshCollider>( );
|
||||
// mc.sharedMesh = mesh;
|
||||
@@ -357,16 +280,164 @@ namespace Objects.Converter.Unity
|
||||
//means the mesh originated in Rhino or similar
|
||||
if (properties == null)
|
||||
{
|
||||
var meshprops = typeof(Mesh).GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(x => x.Name)
|
||||
.ToList();
|
||||
properties = speckleMesh.GetMembers()
|
||||
.Where(x => !meshprops.Contains(x.Key))
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
var meshprops = typeof(Base).GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(x => x.Name)
|
||||
.ToList();
|
||||
properties = element.GetMembers()
|
||||
.Where(x => !meshprops.Contains(x.Key))
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
}
|
||||
|
||||
AttachSpeckleProperties(go, properties);
|
||||
return go;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="speckleMesh"/> to a <see cref="GameObject"/> with a <see cref="MeshRenderer"/>
|
||||
/// </summary>
|
||||
/// <param name="speckleMesh">Mesh to convert</param>
|
||||
/// <param name="properties">If provided, will override the properties on the mesh itself</param>
|
||||
/// <returns></returns>
|
||||
public GameObject MeshToNative(Mesh speckleMesh, Dictionary<string, object> properties = null)
|
||||
{
|
||||
if (speckleMesh.vertices.Count == 0 || speckleMesh.faces.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return MeshesToNative(speckleMesh, new[] {speckleMesh}, properties);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="meshes">meshes to be converted as SubMeshes</param>
|
||||
/// <param name="nativeMesh">The converted native mesh</param>
|
||||
/// <param name="nativeMaterials">The converted materials (one per converted sub-mesh)</param>
|
||||
public void MeshDataToNative(IReadOnlyCollection<Mesh> meshes, out UnityEngine.Mesh nativeMesh, out Material[] nativeMaterials)
|
||||
{
|
||||
var verts = new List<Vector3>();
|
||||
|
||||
var uvs = new List<Vector2>();
|
||||
var vertexColors = new List<Color>();
|
||||
|
||||
var materials = new List<Material>(meshes.Count);
|
||||
var subMeshes = new List<List<int>>(meshes.Count);
|
||||
|
||||
foreach (Mesh m in meshes)
|
||||
{
|
||||
if(m.vertices.Count == 0 || m.faces.Count == 0 ) continue;
|
||||
List<int> tris = new List<int>();
|
||||
SubmeshToNative(m, verts, tris, uvs, vertexColors, materials);
|
||||
subMeshes.Add(tris);
|
||||
}
|
||||
nativeMaterials = materials.ToArray();
|
||||
|
||||
nativeMesh = new UnityEngine.Mesh();
|
||||
|
||||
//TODO not sure if this is necessary, could just set the GameObject transform like we are in unreal?
|
||||
// center transform pivot according to the bounds of the model
|
||||
// if (recenterMeshTransforms)
|
||||
// {
|
||||
// Bounds meshBounds = new Bounds
|
||||
// {
|
||||
// center = verts[0]
|
||||
// };
|
||||
//
|
||||
// foreach (var vert in verts)
|
||||
// {
|
||||
// meshBounds.Encapsulate(vert);
|
||||
// }
|
||||
//
|
||||
// // offset mesh vertices
|
||||
// for (int l = 0; l < verts.Count; l++)
|
||||
// {
|
||||
// verts[l] -= meshBounds.center;
|
||||
// }
|
||||
// }
|
||||
|
||||
nativeMesh.subMeshCount = subMeshes.Count;
|
||||
|
||||
nativeMesh.SetVertices(verts);
|
||||
nativeMesh.SetUVs(0, uvs);
|
||||
nativeMesh.SetColors(vertexColors);
|
||||
|
||||
|
||||
int j = 0;
|
||||
foreach(var subMeshTriangles in subMeshes)
|
||||
{
|
||||
nativeMesh.SetTriangles(subMeshTriangles, j);
|
||||
j++;
|
||||
}
|
||||
|
||||
if (nativeMesh.vertices.Length >= UInt16.MaxValue)
|
||||
nativeMesh.indexFormat = IndexFormat.UInt32;
|
||||
|
||||
nativeMesh.Optimize();
|
||||
nativeMesh.RecalculateBounds();
|
||||
nativeMesh.RecalculateNormals();
|
||||
nativeMesh.RecalculateTangents();
|
||||
}
|
||||
|
||||
|
||||
private void SubmeshToNative(Mesh speckleMesh, List<Vector3> verts, List<int> tris, List<Vector2> texCoords, List<Color> vertexColors, List<Material> materials)
|
||||
{
|
||||
speckleMesh.AlignVerticesWithTexCoordsByIndex();
|
||||
speckleMesh.TriangulateMesh();
|
||||
|
||||
int indexOffset = verts.Count;
|
||||
|
||||
// Convert Vertices
|
||||
verts.AddRange(ArrayToPoints(speckleMesh.vertices, speckleMesh.units));
|
||||
|
||||
// Convert texture coordinates
|
||||
bool hasValidUVs = speckleMesh.TextureCoordinatesCount == speckleMesh.VerticesCount;
|
||||
if(speckleMesh.textureCoordinates.Count > 0 && !hasValidUVs) Debug.LogWarning($"Expected number of UV coordinates to equal vertices. Got {speckleMesh.TextureCoordinatesCount} expected {speckleMesh.VerticesCount}. \nID = {speckleMesh.id}");
|
||||
|
||||
if (hasValidUVs)
|
||||
{
|
||||
texCoords.Capacity += speckleMesh.TextureCoordinatesCount;
|
||||
for (int j = 0; j < speckleMesh.TextureCoordinatesCount; j++)
|
||||
{
|
||||
var (u, v) = speckleMesh.GetTextureCoordinate(j);
|
||||
texCoords.Add(new Vector2((float)u,(float)v));
|
||||
}
|
||||
}
|
||||
else if (speckleMesh.bbox != null)
|
||||
{
|
||||
//Attempt to generate some crude UV coordinates using bbox //TODO this will be broken for submeshes
|
||||
texCoords.AddRange(GenerateUV(verts, (float)speckleMesh.bbox.xSize.Length, (float)speckleMesh.bbox.ySize.Length));
|
||||
}
|
||||
|
||||
// Convert vertex colors
|
||||
if (speckleMesh.colors != null)
|
||||
{
|
||||
if (speckleMesh.colors.Count == speckleMesh.VerticesCount)
|
||||
{
|
||||
vertexColors.AddRange(speckleMesh.colors.Select(c => c.ToUnityColor()));
|
||||
}
|
||||
else if (speckleMesh.colors.Count != 0)
|
||||
{
|
||||
//TODO what if only some submeshes have colors?
|
||||
Debug.LogWarning($"{typeof(Mesh)} {speckleMesh.id} has invalid number of vertex {nameof(Mesh.colors)}. Expected 0 or {speckleMesh.VerticesCount}, got {speckleMesh.colors.Count}");
|
||||
}
|
||||
}
|
||||
|
||||
// Convert faces
|
||||
tris.Capacity += (int) (speckleMesh.faces.Count / 4f) * 3;
|
||||
|
||||
for (int i = 0; i < speckleMesh.faces.Count; i += 4)
|
||||
{
|
||||
//We can safely assume all faces are triangles since we called TriangulateMesh
|
||||
tris.Add(speckleMesh.faces[i + 1] + indexOffset);
|
||||
tris.Add(speckleMesh.faces[i + 3] + indexOffset);
|
||||
tris.Add(speckleMesh.faces[i + 2] + indexOffset);
|
||||
}
|
||||
|
||||
// Convert RenderMaterial
|
||||
materials.Add(GetMaterial(speckleMesh["renderMaterial"] as RenderMaterial));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static IEnumerable<Vector2> GenerateUV(IReadOnlyList<Vector3> verts, float xSize, float ySize)
|
||||
{
|
||||
@@ -416,10 +487,16 @@ namespace Objects.Converter.Unity
|
||||
}
|
||||
|
||||
var c = renderMaterial.diffuse.ToUnityColor();
|
||||
mat.color = new Color(c.r, c.g, c.b, Convert.ToSingle(renderMaterial.opacity));
|
||||
mat.name = renderMaterial.name == null ? "material-"+ Guid.NewGuid().ToString().Substring(0,8) : renderMaterial.name;
|
||||
|
||||
mat.color = new Color(c.r, c.g, c.b, (float)renderMaterial.opacity);
|
||||
mat.name = renderMaterial.name ?? "material-"+ Guid.NewGuid().ToString().Substring(0,8);
|
||||
|
||||
mat.SetFloat(Metallic, (float)renderMaterial.metalness);
|
||||
mat.SetFloat(Glossiness, 1 - (float)renderMaterial.roughness);
|
||||
|
||||
if (renderMaterial.emissive != SColor.Black.ToArgb()) mat.EnableKeyword ("_EMISSION");
|
||||
mat.SetColor(EmissionColor, renderMaterial.emissive.ToUnityColor());
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (StreamManager.GenerateMaterials)
|
||||
{
|
||||
@@ -429,8 +506,7 @@ namespace Objects.Converter.Unity
|
||||
if (AssetDatabase.LoadAllAssetsAtPath("Assets/Resources/Materials/Speckle Generated/" + mat.name + ".mat").Length == 0) AssetDatabase.CreateAsset(mat, "Assets/Resources/Materials/Speckle Generated/" + mat.name + ".mat");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
return mat;
|
||||
}
|
||||
// 3. if not renderMaterial was passed, the default shader will be used
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Objects.BuiltElements;
|
||||
using Unity.Plastic.Antlr3.Runtime.Debug;
|
||||
using UnityEngine;
|
||||
using Mesh = Objects.Geometry.Mesh;
|
||||
|
||||
@@ -16,6 +17,8 @@ namespace Objects.Converter.Unity
|
||||
{
|
||||
#region implemented methods
|
||||
|
||||
public void SetConverterSettings(object settings) => throw new NotImplementedException();
|
||||
|
||||
public string Description => "Default Speckle Kit for Unity";
|
||||
public string Name => nameof(ConverterUnity);
|
||||
public string Author => "Speckle";
|
||||
@@ -66,20 +69,23 @@ namespace Objects.Converter.Unity
|
||||
// return View3DToNative(o);
|
||||
case Mesh o:
|
||||
return MeshToNative(o);
|
||||
//Built elements with a mesh representation implement this interface
|
||||
case IDisplayMesh o:
|
||||
return MeshToNative((Base) o);
|
||||
default:
|
||||
//capture any other object that might have a mesh representation
|
||||
if (@object["displayMesh"] is Mesh)
|
||||
return MeshToNative(@object["displayMesh"] as Mesh);
|
||||
throw new NotSupportedException();
|
||||
if (@object["displayValue"] is Base b)
|
||||
return ConvertToNative(b);
|
||||
if (@object["displayValue"] is IEnumerable<Base> bs)
|
||||
return MeshesToNative(@object, bs.OfType<Mesh>().ToList());
|
||||
if (@object["displayMesh"] is Base m)
|
||||
return ConvertToNative(m);
|
||||
Debug.LogWarning($"Skipping {@object.GetType()} {@object.id} - Not supported type");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<Base> ConvertToSpeckle(List<object> objects)
|
||||
{
|
||||
return objects.Select(x => ConvertToSpeckle(x)).ToList();
|
||||
return objects.Select(ConvertToSpeckle).ToList();
|
||||
}
|
||||
|
||||
public List<object> ConvertToNative(List<Base> objects)
|
||||
@@ -115,12 +121,16 @@ namespace Objects.Converter.Unity
|
||||
// return true;
|
||||
// case View2D _:
|
||||
// return false;
|
||||
case IDisplayMesh _:
|
||||
return true;
|
||||
case Mesh _:
|
||||
return true;
|
||||
default:
|
||||
return @object["displayMesh"] is Mesh;
|
||||
if (@object["displayValue"] is Base)
|
||||
return true;
|
||||
if (@object["displayValue"] is IEnumerable<Base>)
|
||||
return true;
|
||||
if (@object["displayMesh"] is Base)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ PluginImporter:
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isOverridable: 1
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
|
||||
Binary file not shown.
@@ -706,6 +706,12 @@
|
||||
</summary>
|
||||
<param name="objects"></param>
|
||||
</member>
|
||||
<member name="M:Speckle.Core.Kits.ISpeckleConverter.SetConverterSettings(System.Object)">
|
||||
<summary>
|
||||
Some converters need to be able to receive some settings to modify their internal behaviour (i.e. Rhino's Brep Meshing options). Use this method to set them.
|
||||
</summary>
|
||||
<param name="settings">The object representing the settings for your converter.</param>
|
||||
</member>
|
||||
<member name="P:Speckle.Core.Kits.ISpeckleKit.Types">
|
||||
<summary>
|
||||
Returns all the object types (the object model) provided by this kit.
|
||||
@@ -774,6 +780,74 @@
|
||||
<param name="referenceName">The reference assembly name.</param>
|
||||
<returns>A boolean value indicating if there is a reference.</returns>
|
||||
</member>
|
||||
<member name="T:Speckle.Core.Logging.Analytics">
|
||||
<summary>
|
||||
Anonymous telemetry to help us understand how to make a better Speckle.
|
||||
This really helps us to deliver a better open source project and product!
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Speckle.Core.Logging.Analytics.Events">
|
||||
<summary>
|
||||
Default Mixpanel events
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Speckle.Core.Logging.Analytics.Events.Send">
|
||||
<summary>
|
||||
Event triggered when data is sent to a Speckle Server
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Speckle.Core.Logging.Analytics.Events.Receive">
|
||||
<summary>
|
||||
Event triggered when data is received from a Speckle Server
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Speckle.Core.Logging.Analytics.Events.NodeRun">
|
||||
<summary>
|
||||
Event triggered when a node is executed in a visual programming environment, it should contain the name of the action and the host application
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Speckle.Core.Logging.Analytics.Events.DUIAction">
|
||||
<summary>
|
||||
Event triggered when an action is executed in Desktop UI, it should contain the name of the action and the host application
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Speckle.Core.Logging.Analytics.LastEmail">
|
||||
<summary>
|
||||
Cached email
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Speckle.Core.Logging.Analytics.LastServer">
|
||||
<summary>
|
||||
Cached server URL
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Speckle.Core.Logging.Analytics.TrackEvent(Speckle.Core.Logging.Analytics.Events,System.Collections.Generic.Dictionary{System.String,System.Object})">
|
||||
<summary>
|
||||
Tracks an event without specifying the email and server.
|
||||
It's not always possible to know which account the user has selected, especially in visual programming.
|
||||
Therefore we are caching the email and server values so that they can be used also when nodes such as "Serialize" are used.
|
||||
If no account info is cached, we use the default account data.
|
||||
</summary>
|
||||
<param name="eventName">Name of the even</param>
|
||||
<param name="customProperties">Additional parameters to pass in to event</param>
|
||||
</member>
|
||||
<member name="M:Speckle.Core.Logging.Analytics.TrackEvent(Speckle.Core.Credentials.Account,Speckle.Core.Logging.Analytics.Events,System.Collections.Generic.Dictionary{System.String,System.Object})">
|
||||
<summary>
|
||||
Tracks an event from a specified account, anonymizes personal information
|
||||
</summary>
|
||||
<param name="account">Account to use, it will be anonymized</param>
|
||||
<param name="eventName">Name of the event</param>
|
||||
<param name="customProperties">Additional parameters to pass to the event</param>
|
||||
</member>
|
||||
<member name="M:Speckle.Core.Logging.Analytics.TrackEvent(System.String,System.String,Speckle.Core.Logging.Analytics.Events,System.Collections.Generic.Dictionary{System.String,System.Object})">
|
||||
<summary>
|
||||
Tracks an event from a specified email and server, anonymizes personal information
|
||||
</summary>
|
||||
<param name="email">Email of the user, it will be anonymized</param>
|
||||
<param name="server">Server URL, it will be anonymized</param>
|
||||
<param name="eventName">Name of the event</param>
|
||||
<param name="customProperties">Additional parameters to pass to the event</param>
|
||||
</member>
|
||||
<member name="T:Speckle.Core.Logging.Log">
|
||||
<summary>
|
||||
Anonymous telemetry to help us understand how to make a better Speckle.
|
||||
@@ -958,7 +1032,7 @@
|
||||
</member>
|
||||
<member name="T:Speckle.Core.Models.Abstract">
|
||||
<summary>
|
||||
Wrapper around other, thrid party, classes that are not coming from a speckle kit.
|
||||
Wrapper around other, third party, classes that are not coming from a speckle kit.
|
||||
<para>Serialization and deserialization of the base object happens through default Newtonsoft converters. If your object does not de/serialize correctly, this class will not prevent that from happening.</para>
|
||||
<para><b>Limitations:</b></para>
|
||||
<para>- Base object needs to be serializable.</para>
|
||||
|
||||
@@ -24,77 +24,81 @@ namespace Speckle.ConnectorUnity
|
||||
private int _totalChildrenCount = 0;
|
||||
private StreamManager _streamManager;
|
||||
|
||||
public int StreamsLimit { get; set; } = 30;
|
||||
public int BranchesLimit { get; set; } = 30;
|
||||
public int CommitsLimit { get; set; } = 25;
|
||||
|
||||
private int SelectedAccountIndex
|
||||
{
|
||||
get { return _streamManager.SelectedAccountIndex; }
|
||||
set { _streamManager.SelectedAccountIndex = value; }
|
||||
get => _streamManager.SelectedAccountIndex;
|
||||
set => _streamManager.SelectedAccountIndex = value;
|
||||
}
|
||||
|
||||
private int SelectedStreamIndex
|
||||
{
|
||||
get { return _streamManager.SelectedStreamIndex; }
|
||||
set { _streamManager.SelectedStreamIndex = value; }
|
||||
get => _streamManager.SelectedStreamIndex;
|
||||
set => _streamManager.SelectedStreamIndex = value;
|
||||
}
|
||||
|
||||
private int SelectedBranchIndex
|
||||
{
|
||||
get { return _streamManager.SelectedBranchIndex; }
|
||||
set { _streamManager.SelectedBranchIndex = value; }
|
||||
get => _streamManager.SelectedBranchIndex;
|
||||
set => _streamManager.SelectedBranchIndex = value;
|
||||
}
|
||||
|
||||
private int SelectedCommitIndex
|
||||
{
|
||||
get { return _streamManager.SelectedCommitIndex; }
|
||||
set { _streamManager.SelectedCommitIndex = value; }
|
||||
get => _streamManager.SelectedCommitIndex;
|
||||
set => _streamManager.SelectedCommitIndex = value;
|
||||
}
|
||||
|
||||
private int OldSelectedAccountIndex
|
||||
{
|
||||
get { return _streamManager.OldSelectedAccountIndex; }
|
||||
set { _streamManager.OldSelectedAccountIndex = value; }
|
||||
get => _streamManager.OldSelectedAccountIndex;
|
||||
set => _streamManager.OldSelectedAccountIndex = value;
|
||||
}
|
||||
|
||||
private int OldSelectedStreamIndex
|
||||
{
|
||||
get { return _streamManager.OldSelectedStreamIndex; }
|
||||
set { _streamManager.OldSelectedStreamIndex = value; }
|
||||
get => _streamManager.OldSelectedStreamIndex;
|
||||
set => _streamManager.OldSelectedStreamIndex = value;
|
||||
}
|
||||
|
||||
private Client Client
|
||||
{
|
||||
get { return _streamManager.Client; }
|
||||
set { _streamManager.Client = value; }
|
||||
get => _streamManager.Client;
|
||||
set => _streamManager.Client = value;
|
||||
}
|
||||
|
||||
private Account SelectedAccount
|
||||
{
|
||||
get { return _streamManager.SelectedAccount; }
|
||||
set { _streamManager.SelectedAccount = value; }
|
||||
get => _streamManager.SelectedAccount;
|
||||
set => _streamManager.SelectedAccount = value;
|
||||
}
|
||||
|
||||
private Stream SelectedStream
|
||||
{
|
||||
get { return _streamManager.SelectedStream; }
|
||||
set { _streamManager.SelectedStream = value; }
|
||||
get => _streamManager.SelectedStream;
|
||||
set => _streamManager.SelectedStream = value;
|
||||
}
|
||||
|
||||
public List<Account> Accounts
|
||||
{
|
||||
get { return _streamManager.Accounts; }
|
||||
set { _streamManager.Accounts = value; }
|
||||
get => _streamManager.Accounts;
|
||||
set => _streamManager.Accounts = value;
|
||||
}
|
||||
|
||||
private List<Stream> Streams
|
||||
{
|
||||
get { return _streamManager.Streams; }
|
||||
set { _streamManager.Streams = value; }
|
||||
get => _streamManager.Streams;
|
||||
set => _streamManager.Streams = value;
|
||||
}
|
||||
|
||||
private List<Branch> Branches
|
||||
{
|
||||
get { return _streamManager.Branches; }
|
||||
get => _streamManager.Branches;
|
||||
|
||||
set { _streamManager.Branches = value; }
|
||||
set => _streamManager.Branches = value;
|
||||
}
|
||||
|
||||
private async Task LoadAccounts()
|
||||
@@ -124,7 +128,7 @@ namespace Speckle.ConnectorUnity
|
||||
private async Task LoadStreams()
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Loading streams...", "", 0);
|
||||
Streams = await Client.StreamsGet();
|
||||
Streams = await Client.StreamsGet(StreamsLimit);
|
||||
EditorUtility.ClearProgressBar();
|
||||
if (Streams.Any())
|
||||
await SelectStream(0);
|
||||
@@ -137,7 +141,7 @@ namespace Speckle.ConnectorUnity
|
||||
SelectedStream = Streams[i];
|
||||
|
||||
EditorUtility.DisplayProgressBar("Loading stream details...", "", 0);
|
||||
Branches = await Client.StreamGetBranches(SelectedStream.id);
|
||||
Branches = await Client.StreamGetBranches(SelectedStream.id, BranchesLimit, CommitsLimit);
|
||||
if (Branches.Any())
|
||||
{
|
||||
SelectedBranchIndex = 0;
|
||||
|
||||
Binary file not shown.
@@ -54,18 +54,24 @@ namespace Speckle.ConnectorUnity
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unity color to an ARBG int
|
||||
/// </summary>
|
||||
public static int ToIntColor(this Color c)
|
||||
{
|
||||
return
|
||||
System.Drawing.Color
|
||||
.FromArgb(Convert.ToInt32(c.r * 255), Convert.ToInt32(c.r * 255), Convert.ToInt32(c.r * 255))
|
||||
.FromArgb(Convert.ToInt32(c.r * 255), Convert.ToInt32(c.g * 255), Convert.ToInt32(c.b * 255))
|
||||
.ToArgb();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Converts a ARGB formatted int to a Unity Color
|
||||
/// </summary>
|
||||
public static Color ToUnityColor(this int c)
|
||||
{
|
||||
var argb = System.Drawing.Color.FromArgb(c);
|
||||
return new Color(argb.R / 255.0f, argb.G / 255.0f, argb.B / 255.0f);
|
||||
return new Color(argb.R / 255f, argb.G / 255f, argb.B / 255f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user