[add] first
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ac72e159-0c04-4538-8ef8-4cb13c61b744",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { _decorator, Component, Node, Game, Camera, find } from 'cc';
|
||||
import { StaticOcclusionCulling } from '../../../../extensions/pipeline/pipeline/components/occlusion-culling/static/static-occlusion-culling';
|
||||
import { Msg } from '../../core/msg/msg';
|
||||
import { UtilNode } from '../../core/util/util';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('CameraAutoBindOcclusion')
|
||||
export class CameraAutoBindOcclusion extends Component {
|
||||
|
||||
onEnable() {
|
||||
const culling = find('static-occlusion-culling');
|
||||
if (culling === undefined || culling === null) {
|
||||
console.warn(`Can not find static-occlusion-culling.`);
|
||||
return;
|
||||
}
|
||||
const occlusionCulling = culling.getComponent(StaticOcclusionCulling);
|
||||
if(occlusionCulling === null) throw new Error(`culling node not find 'StaticOcclusionCulling'`);
|
||||
occlusionCulling.camera = this.getComponent(Camera);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "37314010-0f5c-4b28-8052-ab60e8272a8f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
|
||||
import { _decorator, Component, Node, find, Vec3, v3 } from 'cc';
|
||||
import { Msg } from '../../core/msg/msg';
|
||||
import { GVec3 } from '../../core/util/g-math';
|
||||
import { UtilVec3 } from '../../core/util/util';
|
||||
import { SmoothLocalZ } from './smooth-local-z';
|
||||
const { ccclass, property } = _decorator;
|
||||
@ccclass('CameraController')
|
||||
export class CameraController extends Component {
|
||||
|
||||
@property
|
||||
smooth: number = 0.5;
|
||||
@property
|
||||
maxOffsetZ: number = 2;
|
||||
@property
|
||||
target: string = 'actor';
|
||||
|
||||
_velocity: Vec3 = new Vec3(0, 0, 0);
|
||||
_followTarget: Node = Object.create(null);
|
||||
|
||||
_offsetZ: number = 0;
|
||||
_offsetZScale: number = 1;
|
||||
_target: Vec3 = v3(0, 0, 0);
|
||||
_dir: Vec3 = v3(0, 0, 0);
|
||||
_pos: Vec3 = v3(0, 0, 0);
|
||||
|
||||
controlZ: SmoothLocalZ = Object.create(null);
|
||||
|
||||
start () {
|
||||
this._followTarget = find(this.target);
|
||||
this._target = this._followTarget.position.clone();
|
||||
UtilVec3.copy(this._pos, this._target);
|
||||
this.node.setWorldPosition(this._target);
|
||||
this.controlZ = this.node.children[0].children[0].getComponent(SmoothLocalZ);
|
||||
Msg.bind('set_camera_len', this.setLen, this);
|
||||
Msg.bind('set_offset_scale', this.setOffsetScale, this);
|
||||
|
||||
console.log('camera controller:', this.node.worldPosition);
|
||||
}
|
||||
|
||||
onDestroy () {
|
||||
Msg.off('set_camera_len', this.setLen);
|
||||
Msg.off('set_offset_scale', this.setOffsetScale);
|
||||
}
|
||||
|
||||
setLen (offset: number) {
|
||||
|
||||
this.controlZ.setOffset(offset);
|
||||
}
|
||||
|
||||
setOffsetScale (scale: number) {
|
||||
|
||||
//this._offsetZScale = 1 - scale;
|
||||
}
|
||||
|
||||
lateUpdate (deltaTime: number) {
|
||||
this.smoothDamp(deltaTime);
|
||||
}
|
||||
|
||||
smoothDamp (deltaTime: number) {
|
||||
//UtilVec3.copy(this._pos, this.node.position);
|
||||
UtilVec3.copy(this._target, this._followTarget.position);
|
||||
UtilVec3.copy(this._dir, this._followTarget.forward);
|
||||
if (this._offsetZScale > 0)
|
||||
this._target.add(this._dir.multiplyScalar(this._offsetZ * this._offsetZScale));
|
||||
GVec3.smoothDamp(this._pos, this._target, this._velocity, this.smooth, deltaTime);
|
||||
//this._pos = val[0];
|
||||
//this._velocity = val[1];
|
||||
this.node.setWorldPosition(this._pos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
smoothLerp(deltaTime: number) {
|
||||
var pos = this.node.worldPosition;
|
||||
var target = this._followTarget.worldPosition;
|
||||
Vec3.lerp(pos, this._followTarget.worldPosition, pos, deltaTime * this.smooth);
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ea461914-a22e-409e-b9cf-c28374c09bd2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { _decorator, Component, Node, v3 } from 'cc';
|
||||
import { ActorBase } from '../../core/actor/actor-base';
|
||||
import { UtilVec3 } from '../../core/util/util';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('camera_fps')
|
||||
export class camera_fps extends Component {
|
||||
|
||||
angle = v3(0, 0, 0);
|
||||
|
||||
@property(Node)
|
||||
root:Node | undefined;
|
||||
|
||||
@property(ActorBase)
|
||||
_actor:ActorBase | undefined;
|
||||
|
||||
start() {
|
||||
this._actor = this.root?.getComponent(ActorBase)!;
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
this.updateAngle();
|
||||
}
|
||||
|
||||
updateAngle() {
|
||||
|
||||
UtilVec3.copy(this.angle, this.node.eulerAngles);
|
||||
this.angle.x = this._actor!._angleVertical;
|
||||
this.node.setRotationFromEuler(this.angle);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "893dd4df-a725-423e-ad34-e891440869dc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { _decorator, Component, Node, v3, Vec3, CCFloat } from 'cc';
|
||||
import { UtilVec3 } from '../../core/util/util';
|
||||
import { Msg } from '../../core/msg/msg';
|
||||
import { SensorRayNodeToNode } from '../../core/sensor/sensor-ray-node-to-node';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('CameraMoveTarget')
|
||||
export class CameraMoveTarget extends Component {
|
||||
|
||||
@property({ type: Node, tooltip: 'Target Node' })
|
||||
targetNode: Node | undefined;
|
||||
|
||||
@property({ type: CCFloat, tooltip: 'Smooth position move.' })
|
||||
smoothSlowMove = 5.0;
|
||||
|
||||
@property({ type: CCFloat, tooltip: 'Smooth angle.' })
|
||||
smoothAngle = 5.0;
|
||||
|
||||
@property({ type: CCFloat, tooltip: 'Smooth position move.' })
|
||||
smoothFastMove = 15;
|
||||
|
||||
@property({ type: Node, tooltip: 'Camera Node.' })
|
||||
cameraNode: Node | undefined;
|
||||
|
||||
@property({ type: [Node], tooltip: 'Target node list.' })
|
||||
targets: Node[] = [];
|
||||
|
||||
@property({ type: CCFloat, tooltip: 'Start the waiting time.' })
|
||||
waitTime = 10;
|
||||
|
||||
@property({ type: Node, tooltip: 'Look at target node.' })
|
||||
lookAtTarget: Node | undefined;
|
||||
|
||||
currentPosition = v3(0, 0, 0);
|
||||
currentAngle = v3(0, 0, 0);
|
||||
|
||||
sensor: SensorRayNodeToNode | undefined;
|
||||
|
||||
movePosition = v3(0, 0, 0);
|
||||
|
||||
smoothMove = 5.0;
|
||||
|
||||
start () {
|
||||
Msg.on('msg_change_tps_camera_target', this.setTarget.bind(this));
|
||||
UtilVec3.copy(this.currentPosition, this.cameraNode!.position);
|
||||
UtilVec3.copy(this.currentAngle, this.cameraNode!.eulerAngles);
|
||||
this.sensor = this.getComponent(SensorRayNodeToNode)!;
|
||||
}
|
||||
|
||||
onDestroy () {
|
||||
Msg.off('msg_change_tps_camera_target', this.setTarget.bind(this));
|
||||
}
|
||||
|
||||
update (deltaTime: number) {
|
||||
|
||||
if (this.waitTime > 0) {
|
||||
this.waitTime -= deltaTime;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.targetNode) return;
|
||||
|
||||
// Calculate move position.
|
||||
if (this.sensor!.hitPoint.length() > 0) {
|
||||
UtilVec3.copy(this.movePosition, this.sensor!.hitPoint);
|
||||
this.movePosition.subtract(this.node!.worldPosition);
|
||||
const length = this.movePosition.length();
|
||||
UtilVec3.copy(this.movePosition, this.targetNode.position);
|
||||
this.movePosition.subtract(this.node.position).normalize().multiplyScalar(length);
|
||||
this.smoothMove = this.smoothFastMove;
|
||||
} else {
|
||||
UtilVec3.copy(this.movePosition, this.targetNode.position);
|
||||
this.smoothMove = this.smoothSlowMove;
|
||||
}
|
||||
//const targetPosition = this.sensor!.hitPoint.length() > 0 ? this.sensor!.hitPoint : this.targetNode.position;
|
||||
|
||||
// Smooth move position.
|
||||
Vec3.lerp(this.currentPosition, this.currentPosition, this.movePosition, this.smoothMove * deltaTime);
|
||||
this.cameraNode?.setPosition(this.currentPosition);
|
||||
|
||||
|
||||
// Smooth move angle.
|
||||
Vec3.lerp(this.currentAngle, this.currentAngle, this.targetNode.eulerAngles, this.smoothAngle * deltaTime);
|
||||
this.cameraNode?.setRotationFromEuler(this.currentAngle);
|
||||
|
||||
// Set Look at point.
|
||||
this.lookAtTarget?.setPosition(0, 0, -this.cameraNode!.position.z - 5);
|
||||
|
||||
}
|
||||
|
||||
setTarget (index: number) {
|
||||
this.targetNode = this.targets[index];
|
||||
this.sensor!.endNode = this.targetNode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d4de46af-d2b9-4857-a899-64e1b466627e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { _decorator, Component, Node, Camera, find } from 'cc';
|
||||
import { Msg } from '../../core/msg/msg';
|
||||
import { UtilNode } from '../../core/util/util';
|
||||
import { StaticOcclusionCulling } from '../../../../extensions/pipeline/pipeline/components/occlusion-culling/static/static-occlusion-culling';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('CameraMsg')
|
||||
export class CameraMsg extends Component {
|
||||
|
||||
|
||||
@property
|
||||
msg = "msg_set_camera";
|
||||
|
||||
_cameraNode:Node | undefined;
|
||||
|
||||
_camera:Camera | undefined;
|
||||
|
||||
start() {
|
||||
|
||||
Msg.bind(this.msg, this.setCamera, this);
|
||||
this._cameraNode = this.node.children[0];
|
||||
this._camera = this._cameraNode.getComponent(Camera)!;
|
||||
|
||||
}
|
||||
|
||||
setCamera(active:boolean) {
|
||||
this._cameraNode!.active = active;
|
||||
if(active) {
|
||||
const culling = find('static-occlusion-culling');
|
||||
if (culling === undefined || culling === null) {
|
||||
console.warn(`Can not find static-occlusion-culling.`);
|
||||
return;
|
||||
}
|
||||
const occlusionCulling = culling.getComponent(StaticOcclusionCulling);
|
||||
if(occlusionCulling === null) throw new Error(`culling node not find 'StaticOcclusionCulling'`);
|
||||
|
||||
if(this._camera)
|
||||
occlusionCulling.camera = this._camera;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6ec114b2-a376-4de4-9e50-51ffd15635e0",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { _decorator, Component, math, Node, v3, CCFloat } from 'cc';
|
||||
import { UtilVec3 } from '../../core/util/util';
|
||||
import { ActorMove } from '../actor/actor-move';
|
||||
import { Msg } from '../../core/msg/msg';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('CameraTps')
|
||||
export class CameraTps extends Component {
|
||||
|
||||
@property(Node)
|
||||
rotationNode: Node | undefined;
|
||||
|
||||
@property({ type: ActorMove, tooltip: 'Test actor move.' })
|
||||
actorMove: ActorMove | undefined;
|
||||
|
||||
@property(CCFloat)
|
||||
smoothAngle = 20;
|
||||
|
||||
@property(CCFloat)
|
||||
smoothHeight = 1;
|
||||
|
||||
targetAngle = v3(0, 0, 0);
|
||||
currentAngle = v3(0, 0, 0);
|
||||
|
||||
targetPosition = v3(0, 0, 0);
|
||||
currentPosition = v3(0, 0, 0);
|
||||
|
||||
start () {
|
||||
UtilVec3.copy(this.targetAngle, this.rotationNode!.eulerAngles);
|
||||
UtilVec3.copy(this.currentAngle, this.targetAngle);
|
||||
|
||||
UtilVec3.copy(this.targetPosition, this.rotationNode!.position);
|
||||
UtilVec3.copy(this.currentAngle, this.targetPosition);
|
||||
|
||||
Msg.on('msg_change_tps_camera_height', this.setRootY.bind(this));
|
||||
}
|
||||
|
||||
update (deltaTime: number) {
|
||||
|
||||
this.rotationX(this.actorMove!.angleVertical);
|
||||
|
||||
this.currentAngle.x = math.lerp(this.currentAngle.x, this.targetAngle.x, this.smoothAngle * deltaTime);
|
||||
|
||||
this.rotationNode?.setRotationFromEuler(this.currentAngle);
|
||||
|
||||
this.currentPosition.y = math.lerp(this.currentPosition.y, this.targetPosition.y, this.smoothHeight * deltaTime);
|
||||
|
||||
this.rotationNode?.setPosition(this.currentPosition);
|
||||
|
||||
}
|
||||
|
||||
rotationX (angleX: number) {
|
||||
|
||||
this.targetAngle.x = angleX;
|
||||
|
||||
}
|
||||
|
||||
setRootY (height: number) {
|
||||
this.targetPosition.y = height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d925f921-05b1-4c96-9c69-61543f688804",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { _decorator, Component, Node, Vec3, v3 } from 'cc';
|
||||
import { Msg } from '../../core/msg/msg';
|
||||
import { UtilVec3 } from '../../core/util/util';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('SmoothLocalZ')
|
||||
export class SmoothLocalZ extends Component {
|
||||
|
||||
@property
|
||||
smooth: number = 0.5;
|
||||
|
||||
@property
|
||||
wait: number = 1;
|
||||
|
||||
pos: Vec3 = v3(0, 0, 0);
|
||||
|
||||
cur: Vec3 = v3(0, 0, 0);
|
||||
|
||||
offset: number = 0;
|
||||
|
||||
offset_x: number = 0;
|
||||
|
||||
original: Vec3 = v3(0, 0, 0);
|
||||
|
||||
/*
|
||||
start () {
|
||||
UtilVec3.copy(this.pos, this.node.position);
|
||||
UtilVec3.copy(this.original, this.pos);
|
||||
this.pos.z = this.offset + this.original.z;
|
||||
UtilVec3.copy(this.cur, this.pos);
|
||||
this.cur.z = 30;
|
||||
this.node.setPosition(this.cur);
|
||||
Msg.on('set_offset_x', this.setOffsetX.bind(this));
|
||||
}
|
||||
*/
|
||||
|
||||
init() {
|
||||
UtilVec3.copy(this.pos, this.node.position);
|
||||
UtilVec3.copy(this.original, this.pos);
|
||||
this.pos.z = this.offset + this.original.z;
|
||||
UtilVec3.copy(this.cur, this.pos);
|
||||
this.cur.z = 30;
|
||||
this.pos.z = 30;
|
||||
this.node.setPosition(this.cur);
|
||||
Msg.on('set_offset_x', this.setOffsetX.bind(this));
|
||||
}
|
||||
|
||||
onDestroy () {
|
||||
Msg.off('set_offset_x', this.setOffset.bind(this));
|
||||
}
|
||||
|
||||
setOffset (offset: number) {
|
||||
this.offset = offset;
|
||||
this.pos.z = this.offset + this.original.z;
|
||||
|
||||
}
|
||||
|
||||
setOffsetX (offset: number) {
|
||||
this.pos.x = offset + this.original.x;
|
||||
}
|
||||
|
||||
lateUpdate (deltaTime: number) {
|
||||
if (this.wait > 0) {
|
||||
this.wait -= deltaTime;
|
||||
return;
|
||||
}
|
||||
this.smoothLerp(deltaTime);
|
||||
}
|
||||
|
||||
smoothLerp (deltaTime: number) {
|
||||
Vec3.lerp(this.cur, this.cur, this.pos, deltaTime * this.smooth);
|
||||
this.node.setPosition(this.cur);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "74de3304-6018-43e6-ae76-6fd1b65140a6",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user