模型预览透明背景
This commit is contained in:
@@ -13,7 +13,8 @@ namespace NBF
|
|||||||
{
|
{
|
||||||
private ModelViewerSettings _viewerSettings;
|
private ModelViewerSettings _viewerSettings;
|
||||||
public Transform modelRoot { get; private set; }
|
public Transform modelRoot { get; private set; }
|
||||||
|
public Camera Camera => _camera;
|
||||||
|
|
||||||
Camera _camera;
|
Camera _camera;
|
||||||
Image _image;
|
Image _image;
|
||||||
Transform _root;
|
Transform _root;
|
||||||
@@ -23,7 +24,7 @@ namespace NBF
|
|||||||
int _width;
|
int _width;
|
||||||
int _height;
|
int _height;
|
||||||
bool _cacheTexture;
|
bool _cacheTexture;
|
||||||
float _rotating;
|
Vector3 _rotating;
|
||||||
|
|
||||||
const int RENDER_LAYER = 0;
|
const int RENDER_LAYER = 0;
|
||||||
const int HIDDEN_LAYER = 10;
|
const int HIDDEN_LAYER = 10;
|
||||||
@@ -102,7 +103,7 @@ namespace NBF
|
|||||||
_model = null;
|
_model = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_rotating = 0;
|
_rotating = Vector3.zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -168,10 +169,7 @@ namespace NBF
|
|||||||
};
|
};
|
||||||
// _renderTexture.Create();
|
// _renderTexture.Create();
|
||||||
_image.texture = new NTexture(_renderTexture);
|
_image.texture = new NTexture(_renderTexture);
|
||||||
_image.shader = "Unlit/Transparent"; //Shader.Find("Unlit/Transparent");
|
_image.shader = "Unlit/Transparent";
|
||||||
// _material = new Material(Shader.Find("Unlit/Transparent"));
|
|
||||||
// _image.blendMode = BlendMode.Off;
|
|
||||||
// _image.blendMode = BlendMode.Normal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DestroyTexture()
|
void DestroyTexture()
|
||||||
@@ -206,10 +204,10 @@ namespace NBF
|
|||||||
|
|
||||||
void Render(object param = null)
|
void Render(object param = null)
|
||||||
{
|
{
|
||||||
if (_rotating != 0 && modelRoot != null)
|
if (_rotating != Vector3.zero && this.modelRoot != null)
|
||||||
{
|
{
|
||||||
Vector3 localRotation = modelRoot.localRotation.eulerAngles;
|
Vector3 localRotation = modelRoot.localRotation.eulerAngles;
|
||||||
localRotation.y += _rotating;
|
localRotation += _rotating;
|
||||||
modelRoot.localRotation = Quaternion.Euler(localRotation);
|
modelRoot.localRotation = Quaternion.Euler(localRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,6 +234,19 @@ namespace NBF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region 旋转
|
||||||
|
|
||||||
|
public void StartRotate(Vector3 delta)
|
||||||
|
{
|
||||||
|
_rotating = delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StopRotate()
|
||||||
|
{
|
||||||
|
_rotating = Vector3.zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region MyRegion
|
#region MyRegion
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ namespace NBF
|
|||||||
public partial class ModelViewer : GComponent
|
public partial class ModelViewer : GComponent
|
||||||
{
|
{
|
||||||
ModelViewRenderImage _renderImage;
|
ModelViewRenderImage _renderImage;
|
||||||
private Material _material;
|
|
||||||
private MeshRenderer _meshRenderer;
|
private Transform ModelRoot => _renderImage?.modelRoot;
|
||||||
|
private Camera ViewCamera => _renderImage.Camera;
|
||||||
|
|
||||||
private void OnInited()
|
private void OnInited()
|
||||||
{
|
{
|
||||||
@@ -20,8 +21,7 @@ namespace NBF
|
|||||||
TouchHolder.onRollOut.Set(OnFocusOut);
|
TouchHolder.onRollOut.Set(OnFocusOut);
|
||||||
Stage.inst.onMouseWheel.Add(OnMouseWheel);
|
Stage.inst.onMouseWheel.Add(OnMouseWheel);
|
||||||
|
|
||||||
_material = new Material(Shader.Find("Unlit/Transparent"));
|
SetRotateListening();
|
||||||
_material.name = "fk";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
@@ -38,27 +38,16 @@ namespace NBF
|
|||||||
|
|
||||||
public void SetData(ItemConfig itemConfig)
|
public void SetData(ItemConfig itemConfig)
|
||||||
{
|
{
|
||||||
//Assets/Resources/gfx/baits/worm_01/worm_01.prefab
|
|
||||||
// _renderImage.LoadModel("gfx/baits/worm_01/worm_01");
|
|
||||||
_renderImage.LoadModel("gfx/" + itemConfig.Model);
|
_renderImage.LoadModel("gfx/" + itemConfig.Model);
|
||||||
_meshRenderer = ModelHolder.displayObject.cachedTransform.GetComponent<MeshRenderer>();
|
|
||||||
|
|
||||||
// ChangeMaterial();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int count = 0;
|
|
||||||
|
|
||||||
protected override void OnUpdate()
|
|
||||||
{
|
|
||||||
base.OnUpdate();
|
|
||||||
|
|
||||||
// ChangeMaterial();
|
|
||||||
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region 用户输入操作(滑动,拖动等)
|
#region 用户输入操作(滑动,拖动等)
|
||||||
|
private bool _focus;
|
||||||
|
|
||||||
|
private float _minFOV = 10f;
|
||||||
|
private float _maxFOV = 120f;
|
||||||
|
|
||||||
private void SetRotateListening()
|
private void SetRotateListening()
|
||||||
{
|
{
|
||||||
var dragObj = TouchHolder;
|
var dragObj = TouchHolder;
|
||||||
@@ -69,53 +58,56 @@ namespace NBF
|
|||||||
|
|
||||||
private void OnSwipeMove(EventContext context)
|
private void OnSwipeMove(EventContext context)
|
||||||
{
|
{
|
||||||
|
var gesture = context.sender as SwipeGesture;
|
||||||
|
if (gesture == null) return;
|
||||||
|
var v = Vector3.zero;
|
||||||
|
|
||||||
|
|
||||||
|
if (context.inputEvent.button == 0)
|
||||||
|
{
|
||||||
|
v.y = -gesture.delta.x * 0.2f;
|
||||||
|
v.z = -gesture.delta.y * 0.2f;
|
||||||
|
if (!gesture.snapping)
|
||||||
|
{
|
||||||
|
v.y = 0;
|
||||||
|
v.z = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Mathf.Abs(v.y) < 1) //消除手抖影响
|
||||||
|
v.y = 0;
|
||||||
|
if (Mathf.Abs(v.z) < 1) //消除手抖影响
|
||||||
|
v.z = 0;
|
||||||
|
_renderImage.StartRotate(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSwipeEnd(EventContext context)
|
private void OnSwipeEnd(EventContext context)
|
||||||
{
|
{
|
||||||
|
_renderImage.StopRotate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFocusIn()
|
private void OnFocusIn()
|
||||||
{
|
{
|
||||||
// _focus = true;
|
_focus = true;
|
||||||
Log.Info("focus true");
|
Log.Info("focus true");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFocusOut()
|
private void OnFocusOut()
|
||||||
{
|
{
|
||||||
// _focus = false;
|
_focus = false;
|
||||||
Log.Info("focus false");
|
Log.Info("focus false");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMouseWheel(EventContext context)
|
private void OnMouseWheel(EventContext context)
|
||||||
{
|
{
|
||||||
|
if (!_focus) return;
|
||||||
|
float delta = context.inputEvent.mouseWheelDelta / Stage.devicePixelRatio;
|
||||||
|
SetZoom(delta);
|
||||||
}
|
}
|
||||||
|
private void SetZoom(float delta)
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region NMSL
|
|
||||||
|
|
||||||
private void ChangeMaterial()
|
|
||||||
{
|
{
|
||||||
if (_meshRenderer != null && _meshRenderer.material != _material)
|
ViewCamera.fieldOfView = Mathf.Clamp(ViewCamera.fieldOfView + delta, _minFOV, _maxFOV);
|
||||||
{
|
|
||||||
var old = _meshRenderer.material;
|
|
||||||
_material.mainTexture = old.mainTexture;
|
|
||||||
_meshRenderer.material = _material;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBackground(GObject image)
|
|
||||||
{
|
|
||||||
SetBackground(image, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void SetBackground(GObject image1, GObject image2)
|
|
||||||
{
|
|
||||||
// _renderImage.SetBackground(image1, image2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ namespace NBF
|
|||||||
//Camera Settings
|
//Camera Settings
|
||||||
cameraPosition = new Vector3(1, Mathf.Sqrt(2), 1);
|
cameraPosition = new Vector3(1, Mathf.Sqrt(2), 1);
|
||||||
perspLastScale = 1;
|
perspLastScale = 1;
|
||||||
cameraOrtho = true;
|
cameraOrtho = false;
|
||||||
cameraFov = 60;
|
cameraFov = 60;
|
||||||
cameraSize = 5;
|
cameraSize = 5;
|
||||||
camerasScaleFactor = 1;
|
camerasScaleFactor = 1;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABindingFlags_002Ecs_002Fl_003AC_0021_003FUsers_003Fbob_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5a41d6b7189842eca409fd0b1c3e3dcf17bf78_003Fa8_003F57a4f791_003FBindingFlags_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABindingFlags_002Ecs_002Fl_003AC_0021_003FUsers_003Fbob_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5a41d6b7189842eca409fd0b1c3e3dcf17bf78_003Fa8_003F57a4f791_003FBindingFlags_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABindingFlags_002Ecs_002Fl_003AC_0021_003FUsers_003Fbob_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9c2967a135e648bdb993c5397a44991b573620_003F94_003F16186629_003FBindingFlags_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABindingFlags_002Ecs_002Fl_003AC_0021_003FUsers_003Fbob_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9c2967a135e648bdb993c5397a44991b573620_003F94_003F16186629_003FBindingFlags_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACameraClearFlags_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb4c8c45fec274213bfac03ee0e9a3d621f5a00_003F95_003Ff32b203b_003FCameraClearFlags_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACameraClearFlags_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb4c8c45fec274213bfac03ee0e9a3d621f5a00_003F95_003Ff32b203b_003FCameraClearFlags_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACamera_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb4c8c45fec274213bfac03ee0e9a3d621f5a00_003F64_003Fac29cf98_003FCamera_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACharacterController_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F21f01dcabaec42e5804351a26927d8a329c00_003Fa8_003Ff67063b8_003FCharacterController_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACharacterController_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F21f01dcabaec42e5804351a26927d8a329c00_003Fa8_003Ff67063b8_003FCharacterController_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACollider_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F03ef825315384b1cab81c4b53eb03d922ac00_003Fd1_003Fa6f13559_003FCollider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACollider_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F03ef825315384b1cab81c4b53eb03d922ac00_003Fd1_003Fa6f13559_003FCollider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AColor_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb4c8c45fec274213bfac03ee0e9a3d621f5a00_003Fd8_003F7935a946_003FColor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AColor_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb4c8c45fec274213bfac03ee0e9a3d621f5a00_003Fd8_003F7935a946_003FColor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
|||||||
Reference in New Issue
Block a user