模型预览透明背景
This commit is contained in:
@@ -13,7 +13,8 @@ namespace NBF
|
||||
{
|
||||
private ModelViewerSettings _viewerSettings;
|
||||
public Transform modelRoot { get; private set; }
|
||||
|
||||
public Camera Camera => _camera;
|
||||
|
||||
Camera _camera;
|
||||
Image _image;
|
||||
Transform _root;
|
||||
@@ -23,7 +24,7 @@ namespace NBF
|
||||
int _width;
|
||||
int _height;
|
||||
bool _cacheTexture;
|
||||
float _rotating;
|
||||
Vector3 _rotating;
|
||||
|
||||
const int RENDER_LAYER = 0;
|
||||
const int HIDDEN_LAYER = 10;
|
||||
@@ -102,7 +103,7 @@ namespace NBF
|
||||
_model = null;
|
||||
}
|
||||
|
||||
_rotating = 0;
|
||||
_rotating = Vector3.zero;
|
||||
}
|
||||
|
||||
|
||||
@@ -168,10 +169,7 @@ namespace NBF
|
||||
};
|
||||
// _renderTexture.Create();
|
||||
_image.texture = new NTexture(_renderTexture);
|
||||
_image.shader = "Unlit/Transparent"; //Shader.Find("Unlit/Transparent");
|
||||
// _material = new Material(Shader.Find("Unlit/Transparent"));
|
||||
// _image.blendMode = BlendMode.Off;
|
||||
// _image.blendMode = BlendMode.Normal;
|
||||
_image.shader = "Unlit/Transparent";
|
||||
}
|
||||
|
||||
void DestroyTexture()
|
||||
@@ -206,10 +204,10 @@ namespace NBF
|
||||
|
||||
void Render(object param = null)
|
||||
{
|
||||
if (_rotating != 0 && modelRoot != null)
|
||||
if (_rotating != Vector3.zero && this.modelRoot != null)
|
||||
{
|
||||
Vector3 localRotation = modelRoot.localRotation.eulerAngles;
|
||||
localRotation.y += _rotating;
|
||||
localRotation += _rotating;
|
||||
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
|
||||
|
||||
|
||||
@@ -10,8 +10,9 @@ namespace NBF
|
||||
public partial class ModelViewer : GComponent
|
||||
{
|
||||
ModelViewRenderImage _renderImage;
|
||||
private Material _material;
|
||||
private MeshRenderer _meshRenderer;
|
||||
|
||||
private Transform ModelRoot => _renderImage?.modelRoot;
|
||||
private Camera ViewCamera => _renderImage.Camera;
|
||||
|
||||
private void OnInited()
|
||||
{
|
||||
@@ -20,8 +21,7 @@ namespace NBF
|
||||
TouchHolder.onRollOut.Set(OnFocusOut);
|
||||
Stage.inst.onMouseWheel.Add(OnMouseWheel);
|
||||
|
||||
_material = new Material(Shader.Find("Unlit/Transparent"));
|
||||
_material.name = "fk";
|
||||
SetRotateListening();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
@@ -38,27 +38,16 @@ namespace NBF
|
||||
|
||||
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);
|
||||
_meshRenderer = ModelHolder.displayObject.cachedTransform.GetComponent<MeshRenderer>();
|
||||
|
||||
// ChangeMaterial();
|
||||
}
|
||||
|
||||
private int count = 0;
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
base.OnUpdate();
|
||||
|
||||
// ChangeMaterial();
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
#region 用户输入操作(滑动,拖动等)
|
||||
|
||||
private bool _focus;
|
||||
|
||||
private float _minFOV = 10f;
|
||||
private float _maxFOV = 120f;
|
||||
|
||||
private void SetRotateListening()
|
||||
{
|
||||
var dragObj = TouchHolder;
|
||||
@@ -69,53 +58,56 @@ namespace NBF
|
||||
|
||||
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)
|
||||
{
|
||||
_renderImage.StopRotate();
|
||||
}
|
||||
|
||||
private void OnFocusIn()
|
||||
{
|
||||
// _focus = true;
|
||||
_focus = true;
|
||||
Log.Info("focus true");
|
||||
}
|
||||
|
||||
private void OnFocusOut()
|
||||
{
|
||||
// _focus = false;
|
||||
_focus = false;
|
||||
Log.Info("focus false");
|
||||
}
|
||||
|
||||
private void OnMouseWheel(EventContext context)
|
||||
{
|
||||
if (!_focus) return;
|
||||
float delta = context.inputEvent.mouseWheelDelta / Stage.devicePixelRatio;
|
||||
SetZoom(delta);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region NMSL
|
||||
|
||||
private void ChangeMaterial()
|
||||
private void SetZoom(float delta)
|
||||
{
|
||||
if (_meshRenderer != null && _meshRenderer.material != _material)
|
||||
{
|
||||
var old = _meshRenderer.material;
|
||||
_material.mainTexture = old.mainTexture;
|
||||
_meshRenderer.material = _material;
|
||||
}
|
||||
ViewCamera.fieldOfView = Mathf.Clamp(ViewCamera.fieldOfView + delta, _minFOV, _maxFOV);
|
||||
}
|
||||
|
||||
public void SetBackground(GObject image)
|
||||
{
|
||||
SetBackground(image, null);
|
||||
}
|
||||
|
||||
|
||||
public void SetBackground(GObject image1, GObject image2)
|
||||
{
|
||||
// _renderImage.SetBackground(image1, image2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ namespace NBF
|
||||
//Camera Settings
|
||||
cameraPosition = new Vector3(1, Mathf.Sqrt(2), 1);
|
||||
perspLastScale = 1;
|
||||
cameraOrtho = true;
|
||||
cameraOrtho = false;
|
||||
cameraFov = 60;
|
||||
cameraSize = 5;
|
||||
camerasScaleFactor = 1;
|
||||
|
||||
Reference in New Issue
Block a user