Unity3D Model Control Method, System, Terminal and Storage Medium within a Local Area Network
By using WebSocket communication and communication rules to convert gesture instructions within the LAN, real-time control of Unity3D models across devices is realized, solving the convenience and real-time problems of 3D models operation and interaction in the prior art, and improving the user experience.
Patent Information
- Application Number
- CN202410800792.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-20
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2044-06-20
AI Technical Summary
The lack of convenient and flexible real-time remote control methods in the prior art limits the operation and interaction of 3D models among multiple devices.
Communication between Android devices and Windows operating system devices is established through WebSocket communication within the LAN, communication rules are agreed upon and touch screen gesture commands are converted into control commands, real-time control of the Unity3D model is achieved.
It improves the convenience and real-time nature of 3D content interaction, realizes intuitive and efficient control across devices, and overcomes the limitations of the existing technology.
Smart Images

Figure CN118660042B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of Unity3D models, and in particular relates to a Unity3D model control method, system, terminal and storage medium in a local area network. Background Art
[0002] Unity is a real-time 3D interactive content creation and operation platform. Creators across game development, art, architecture, automotive design, and film and television use Unity to turn their ideas into reality. The Unity platform offers a comprehensive suite of software solutions for creating, operating, and monetizing any real-time interactive 2D and 3D content, across mobile phones, tablets, PCs, game consoles, and augmented and virtual reality devices. 3D models are increasingly used in a variety of fields, particularly in education, product demonstrations, and virtual training.
[0003] In the existing technology, the operation and control of 3D models mostly rely on a single device or platform, and lacks a convenient and flexible real-time remote control method. Summary of the Invention
[0004] In view of the above-mentioned deficiencies in the prior art, the present invention provides a Unity3D model control method, system, terminal and storage medium in a local area network to solve the above-mentioned technical problems.
[0005] In a first aspect, the present invention provides a method for controlling a Unity3D model in a local area network, comprising:
[0006] Connecting a first terminal and a second terminal to the same local area network and establishing WebSocket communication between the first terminal and the second terminal, wherein the first terminal is loaded with a Unity3D model;
[0007] The first terminal and the second terminal agree on a communication rule, wherein the communication rule includes a model type, a model name, a subcomponent name, an operation type, and an operation parameter;
[0008] The second terminal obtains the touch screen gesture instruction, converts the touch screen gesture instruction into a control instruction that complies with the communication rule, and sends the control instruction to the first terminal through WebSocket;
[0009] The first terminal executes the control instruction on the Unity3D model.
[0010] In an optional embodiment, a first terminal and a second terminal are connected to the same local area network, and WebSocket communication is established between the first terminal and the second terminal, wherein the first terminal is loaded with a Unity3D model, including:
[0011] Establishing a WebSocket server through WebSocketSharp in Unity of a first terminal, where the first terminal uses a Windows operating system;
[0012] Create a WebSocket client in Unity on the second terminal, and establish a connection between the WebSocket server and the WebSocket client in the local area network.
[0013] In an optional embodiment, the communication rules include:
[0014] Model types include built-in model ExplodeModelOpt and dynamically loaded model GltfModelOpt;
[0015] If the model name belongs to a built-in model, the subcomponent name exists. If the model name does not belong to a built-in model, the subcomponent name does not exist.
[0016] Operation types include opening a model, closing a model, resetting a model state, moving a model, scaling a model, rotating a model, exploding a model, hiding a model, and controlling a model;
[0017] Operation parameters: Parameter items that match multiple operation types.
[0018] In an optional embodiment, the operating parameters include:
[0019] The parameters corresponding to the opened model include the path and name of the 3D model;
[0020] The parameter items corresponding to the closed model include the model name;
[0021] The parameter items corresponding to the reset model include the model name;
[0022] The parameter items corresponding to the mobile model include position, which is in world coordinates;
[0023] The parameter items corresponding to the scaling model include the scaling ratio Vector3;
[0024] The parameter items corresponding to the rotation model include Quaternion;
[0025] There are no restrictions on the parameter items corresponding to the explosion model;
[0026] The parameter items corresponding to the hidden model include true or false
[0027] The parameter items corresponding to the control model include all split parts, select split selected parts, and back return to the original position after selection.
[0028] In an optional embodiment, the second terminal obtains a touch screen gesture instruction, converts the touch screen gesture instruction into a control instruction that complies with the communication rule, and sends the control instruction to the first terminal via WebSocket, including:
[0029] Acquire electrical signals from the touch screen and convert the electrical signals into touch point coordinates;
[0030] Identify the number and position of fingers based on touch point coordinates;
[0031] If the number of fingers is 2, the distance between the fingers is obtained in real time, and the distance difference between the most recently obtained distance and the previously obtained distance is calculated; if the distance difference does not exceed the set distance threshold, the operation type is determined to be a move model; if the distance difference exceeds the distance threshold, the operation type is determined to be a zoom model;
[0032] If the number of fingers is 1, the operation type is determined to be a rotation model, and the horizontal and vertical offsets of touch.deltaPosition are obtained as operation parameters;
[0033] If the touch point coordinates are within the pre-packaged instruction triggering item area, the corresponding control instruction is called.
[0034] In an optional embodiment, if the touch point coordinates are within a pre-packaged instruction triggering item area, calling a corresponding control instruction includes:
[0035] If the touch point coordinates are within the explosion command triggering item area, the explosion model command ExplodeModelOpt*model name*explode*all is called;
[0036] If the touch point coordinates are within the reset instruction triggering item area, call the reset model instruction ExplodeModelOpt*1*reset*all;
[0037] If the touch point coordinates are within the close instruction triggering item area, call the close model instruction ExplodeModelOpt*1*close*all;
[0038] If the touch point coordinates are within the hidden instruction triggering item area, the hidden model instruction ExplodeModelOpt*1*hide*true is called.
[0039] In an optional implementation, the first terminal executes the control instruction on the Unity3D model, including:
[0040] If the control instruction is a moving model or a scaling model, then extracting touch point coordinate data, wherein the touch point coordinate data is a touch point coordinate sequence arranged in chronological order, and the intervals between adjacent touch point coordinates are the same;
[0041] Collecting a sample sequence from the touch point coordinate sequence using a time window;
[0042] Calculating a coordinate difference between the latest touch point coordinates and the coordinates of adjacent touch points in the sample sequence, generating a motion vector based on the coordinate difference, and calculating a current motion speed based on the coordinate difference and the interval time;
[0043] Calculate the motion speed between the coordinates of adjacent touch points in the sample sequence to obtain a motion speed sequence;
[0044] Calculating corresponding accelerations based on adjacent motion speeds in the motion speed sequence to obtain an acceleration sequence, and calculating an average acceleration based on the acceleration sequence;
[0045] generating a predicted speed sequence based on the average acceleration and the current motion speed;
[0046] A relationship function between movement speed and adjustment ratio is established, and timing is started after adjusting the model ratio once. When the timing time reaches the set time, a new adjustment ratio is generated based on the relationship function and the predicted speed in the predicted speed sequence, and the model is adjusted based on the new adjustment ratio.
[0047] In a second aspect, the present invention provides a Unity3D model control system in a local area network, comprising:
[0048] a communication establishing module, configured to connect a first terminal and a second terminal to the same local area network and establish WebSocket communication between the first terminal and the second terminal, wherein the first terminal is loaded with a Unity3D model;
[0049] A rule agreement module, configured to agree on communication rules between the first terminal and the second terminal, wherein the communication rules include a model type, a model name, a subcomponent name, an operation type, and an operation parameter;
[0050] An instruction conversion module is used for the second terminal to obtain a touch screen gesture instruction, convert the touch screen gesture instruction into a control instruction that complies with the communication rule, and send the control instruction to the first terminal via WebSocket;
[0051] The instruction execution module is used for the first terminal to execute the control instruction on the Unity3D model.
[0052] According to a third aspect, a terminal is provided, including:
[0053] processor, memory, wherein
[0054] The memory is used to store computer programs,
[0055] The processor is used to call and run the computer program from the memory, so that the terminal executes the above-mentioned terminal method.
[0056] In a fourth aspect, a computer storage medium is provided, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the methods described in the above aspects.
[0057] The beneficial effects of the present invention are that the Unity3D model control method, system, terminal and storage medium in a local area network provided by the present invention realize real-time control of the Unity3D model running on the Windows operating system by an Android device by establishing WebSocket communication in the local area network, overcoming the limitations of 3D model display and interaction in the existing technology, improving the convenience, real-time nature and user experience of 3D content interaction, and making the control process more intuitive and efficient.
[0058] In addition, the present invention has a reliable design principle, a simple structure and a very broad application prospect. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0060] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention.
[0061] Figure 2 is another schematic flow chart of a method according to an embodiment of the present invention.
[0062] Figure 3 FIG. 4 is a schematic block diagram of a system according to an embodiment of the present invention.
[0063] Figure 4 A schematic diagram of the structure of a terminal provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0064] In order to enable those skilled in the art to better understand the technical solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0065] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0066] The Unity3D model control method in a local area network provided by the embodiment of the present invention is executed by a computer device. Accordingly, the Unity3D model control system in a local area network runs in the computer device.
[0067] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention. Figure 1 The execution subject can be a Unity3D model control system in a local area network. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.
[0068] like Figure 1 As shown, the method includes:
[0069] Step 110: Connecting a first terminal and a second terminal to the same local area network and establishing WebSocket communication between the first terminal and the second terminal, wherein the first terminal is loaded with a Unity3D model;
[0070] Step 120: The first terminal and the second terminal agree on communication rules, wherein the communication rules include model type, model name, subcomponent name, operation type, and operation parameters;
[0071] Step 130: The second terminal obtains a touch screen gesture instruction, converts the touch screen gesture instruction into a control instruction that complies with the communication rule, and sends the control instruction to the first terminal via WebSocket;
[0072] Step 140: The first terminal executes the control instruction on the Unity3D model.
[0073] To facilitate understanding of the present invention, the following further describes the Unity3D model control method within a local area network provided by the present invention based on the principles of the Unity3D model control method within a local area network of the present invention and the process of controlling the Unity3D model within a local area network in the embodiment.
[0074] For details, please refer to Figure 2 , the Unity3D model control method in the local area network includes:
[0075] S1. Connect a first terminal and a second terminal to the same local area network, and establish WebSocket communication between the first terminal and the second terminal, wherein the first terminal is loaded with a Unity3D model.
[0076] A WebSocket server is established through WebSocketSharp in Unity of the first terminal, and the first terminal adopts the Windows operating system; a WebSocket client is established in Unity of the second terminal, and a connection between the WebSocket server and the WebSocket client is established in the local area network.
[0077] Specifically, the Android device and the Windows device are connected to the same local area network; Unity on the Windows side uses WebSocketSharp to establish a WebSocket server, and Unity on the Android side uses WebSocket as a client to connect to the server, thereby establishing WebSocket communication.
[0078] S2. The first terminal and the second terminal agree on communication rules, where the communication rules include model type, model name, subcomponent name, operation type, and operation parameters.
[0079] The two terminals define the communication rules between the devices. Based on this rule of "model type*model name|subcomponent name*operation type*operation parameters", the client sends instructions to the server to execute the operation.
[0080] Model type: built-in model ExplodeModelOpt and dynamically loaded model GltfModelOpt.
[0081] Model name | sub-component name: model name. If it is a built-in model that needs to operate internal parts, "|internal part name" will be present. Otherwise, there will only be the model name.
[0082] Operation types: open (open the model), close (close the model), reset (reset the model state), pan (move the model), scale (scale the model), rotation (rotate the model), explode (explode the model), hide (hide the model), operate (control the model).
[0083] Operation parameters: Different operation types use different parameters. The parameters are as follows:
[0084] open: the path and name of the 3D model;
[0085] close: model name;
[0086] reset: model name;
[0087] pan: position (world coordinate position);
[0088] scale: scaling ratio Vector3;
[0089] rotation: Quaternion;
[0090] explode: no parameters;
[0091] hide:true or false;
[0092] operate:all splits parts, select splits selected parts, back selects and returns to the original position.
[0093] S3. The second terminal obtains a touch screen gesture instruction, converts the touch screen gesture instruction into a control instruction that complies with the communication rule, and sends the control instruction to the first terminal through WebSocket.
[0094] Acquire the electrical signal of the touch screen and convert the electrical signal into the touch point coordinates; identify the number of fingers and the finger positions based on the touch point coordinates; if the number of fingers is 2, obtain the distance between the fingers in real time, and calculate the distance difference between the latest obtained distance and the previously obtained distance; if the distance difference does not exceed the set distance threshold, determine the operation type as a moving model; if the distance difference exceeds the distance threshold, determine the operation type as a zooming model; if the number of fingers is 1, determine the operation type as a rotation model, and obtain the horizontal and vertical offsets of touch.deltaPosition as operation parameters; if the touch point coordinates are within the pre-packaged instruction trigger item area, call the corresponding control instruction. If the touch point coordinates are within the explosion instruction trigger item area, the explosion model instruction ExplodeModelOpt*model name*explode*all is called; if the touch point coordinates are within the reset instruction trigger item area, the reset model instruction ExplodeModelOpt*1*reset*all is called; if the touch point coordinates are within the close instruction trigger item area, the close model instruction ExplodeModelOpt*1*close*all is called; if the touch point coordinates are within the hide instruction trigger item area, the hide model instruction ExplodeModelOpt*1*hide*true is called.
[0095] Specifically, to move the 3D model, the Android device recognizes Input.touchCount = 2 to determine two fingers, calculates the distance oldDistance between the two fingers, and after the two fingers slide, recalculates the distance newDistance between the two fingers. If the difference between oldDistance and newDistance is less than a certain range, indicating a fixed two-finger slide, the 3D model is moved, and then a pan command is sent to the Windows end for synchronous movement.
[0096] To scale a 3D model, the Android device recognizes Input.touchCount = 2 to identify two fingers, calculates the distance between the two fingers, and then calculates the distance between the two fingers. When the two fingers are pinched or spread apart, the distance between the two fingers, newDistance, is calculated again. If the difference between oldDistance and newDistance is greater than a certain range, it indicates a scaling operation. The device then sends a scale command to the Windows client for synchronous scaling.
[0097] 3D model rotation: The Android device recognizes Input.touchCount=1 to determine a single finger. When a single finger slides, it obtains the horizontal and vertical offsets of touch.deltaPosition, rotates horizontally according to its own coordinate axis, and vertically according to the world coordinate axis. Then, it sends a rotation command to the Windows end for synchronous rotation.
[0098] To explode a 3D model, the Android device directly sends an explode command, traverses each internal part of the 3D model, and offsets its x and y positions by 1.5 times the distance around the center point of the model. The z axis remains unchanged, and an offset animation is added to achieve the explosion effect.
[0099] To split a 3D model, the Android device directly sends the "ExplodeModelOpt*model name*explode*all" command to split the internal parts of the model, keep the z-axis position unchanged, change the x and y axes, and arrange them neatly on the screen.
[0100] S4. The first terminal executes the control instruction on the Unity3D model.
[0101] The first terminal performs corresponding operations on the Unity3D model based on the received control instructions, such as opening, closing, exploding, resetting, hiding, moving, and scaling the model.
[0102] 3D model is opened. After opening, the Android terminal sends the open command to the Windows terminal to open a model synchronously, for example, ExplodeModelOpt*1*open*Prefabs / mr / Prefab / mr;
[0103] To move the 3D model, the Android device recognizes Input.touchCount = 2 to identify two fingers, calculates the distance between the two fingers, and calculates the distance between the two fingers. After the two fingers slide, the distance between the two fingers is calculated again. If the difference between the oldDistance and the newDistance is less than a certain range, indicating a fixed two-finger slide, the 3D model is moved. Then, a pan command is sent to the Windows end for synchronous movement, for example, ExplodeModelOpt*1*pan*-3.6,-2.729999.
[0104] To scale a 3D model, the Android device recognizes Input.touchCount = 2 to identify two fingers, calculates the distance between the two fingers, and calculates the distance between them. When the two fingers are pinched or spread apart, the distance between the two fingers is recalculated. If the difference between oldDistance and newDistance is greater than a certain range, it indicates a scaling operation. The device then sends a scale command to the Windows client for synchronous scaling. For example, the command is: ExplodeModelOpt*1*scale*36.4776,36.4776,36.4776.
[0105] 3D model rotation: The Android device recognizes Input.touchCount = 1 to determine a single finger. When a single finger slides, it obtains the horizontal and vertical offsets of touch.deltaPosition. The horizontal direction rotates according to the local coordinate axis, and the vertical line rotates according to the world coordinate axis. Then, a rotation command is sent to the Windows end for synchronous rotation, for example, ExplodeModelOpt*1*rotation*-0.3567967,0.4925614,-0.02604741,0.793348;
[0106] To explode a 3D model, the Android device directly sends the explode command, which iterates through each internal part of the 3D model and offsets its x and y positions by 1.5 times the distance around the model's center point. The z axis remains unchanged, and an offset animation is added to create the explosion effect. For example, ExplodeModelOpt*1*explode*show;
[0107] To split a 3D model, send the command "ExplodeModelOpt*model name*explode*all" to your Android device to split the model's internal parts, keeping the z-axis position unchanged and adjusting the x and y axes to neatly arrange them on the screen. For example, "ExplodeModelOpt*1*operate*all";
[0108] To manipulate individual parts of a 3D model, after splitting it on the Android device, you can select a single part and send a selection command, such as ExplodeModelOpt*1|12_lp*operate*select. After selection, each part can be manipulated as a 3D model, and can be rotated, moved, and scaled. For example, to rotate, use ExplodeModelOpt*1|12_lp *rotation*-0.2667555,0.7827646,-0.2031474,0.5242636.
[0109] 3D model reset: After operating the model, you can use the reset function to restore the model to its initial state and send the reset command to the Windows end for synchronization, for example, ExplodeModelOpt*1*reset*all;
[0110] The 3D model is closed and hidden. When closing the model, you can send the close command, such as ExplodeModelOpt*1*close*all; when temporarily hiding or showing the model, you can send the hide command, such as ExplodeModelOpt*1*hide*true.
[0111] When moving or scaling a 3D model, lag is likely to occur when communication is unstable. Therefore, the following methods are used to handle this:
[0112] (1) If the control instruction is to move the model or scale the model, touch point coordinate data is extracted. The touch point coordinate data is a sequence of touch point coordinates arranged in chronological order according to generation time, and the intervals between adjacent touch point coordinates are the same. The second terminal packages the touch point coordinate data generated during this period and sends it to the second terminal every t1. The second terminal buffers the received touch point coordinate data.
[0113] (2) Using a time window to collect a sample sequence from the touch point coordinate sequence. The time window length is set to 5, that is, the 5 latest touch point coordinates are extracted each time.
[0114] (3) Calculate the coordinate difference between the latest touch point coordinates and the adjacent touch point coordinates in the sample sequence, generate a motion vector based on the coordinate difference, and calculate the current motion speed v0 based on the coordinate difference and the interval time t2.
[0115] (4) Calculate the motion speed between the coordinates of adjacent touch points in the sample sequence to obtain a motion speed sequence.
[0116] (5) Calculating corresponding accelerations based on adjacent motion speeds in the motion speed sequence to obtain an acceleration sequence, and calculating an average acceleration a based on the acceleration sequence.
[0117] (6) Generate a predicted velocity sequence [v1, v2, v3] based on the average acceleration and the current motion velocity, where v1 = v0 + a × t2, v2 = v0 + 2a × t2, and v3 = v0 + 3a × t2.
[0118] (7) Establish a relationship function between movement speed and adjustment ratio, start timing after adjusting the model ratio once, and when the timing time reaches the set time, generate a new adjustment ratio based on the relationship function and the predicted speed in the predicted speed sequence, and adjust the model based on the new adjustment ratio.
[0119] When performing scaling, if the velocity of both finger touch points is v, calculate the angle α between the motion vectors of the two finger touch points, and the scaling ratio y1 = k1 × vα, where k1 is the first fixed coefficient. Simultaneously, calculate the dot product of the motion vectors of the two finger touch points. If the dot product is positive, the model is scaled down; if not, the model is scaled up. Set the scaling adjustment interval to t3, and adjust the model every t3. Each adjustment obtains the scaling ratio, and the new volume is the product of the original model volume and the scaling ratio.
[0120] When performing rotation, if the speed of the finger contact point is v and the base rotation angular velocity is set to ω0, the actual rotation angular velocity ω = k2vω0. The direction of the motion vector is regarded as the rotation direction.
[0121] If the first terminal does not receive a new touch point coordinate sequence within time t4 after the first adjustment, a new adjustment ratio is generated based on the relationship function and the predicted speed in the predicted speed sequence, and the model is adjusted based on the new adjustment ratio.
[0122] In some embodiments, the Unity3D model control system in the local area network may include multiple functional modules composed of computer program segments. The computer program of each program segment in the Unity3D model control system in the local area network may be stored in a memory of a computer device and executed by at least one processor to perform (see Figure 1 Description) Function of controlling Unity3D models within a local area network.
[0123] In this embodiment, the Unity3D model control system in the local area network can be divided into multiple functional modules according to the functions it performs, such as Figure 3 As shown. The functional modules of system 300 may include: a communication establishment module 310, a rule agreement module 320, an instruction conversion module 330, and an instruction execution module 340. A module as referred to in the present invention refers to a series of computer program segments that can be executed by at least one processor and can perform fixed functions, and is stored in a memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments.
[0124] a communication establishing module, configured to connect a first terminal and a second terminal to the same local area network and establish WebSocket communication between the first terminal and the second terminal, wherein the first terminal is loaded with a Unity3D model;
[0125] A rule agreement module, configured to agree on communication rules between the first terminal and the second terminal, wherein the communication rules include a model type, a model name, a subcomponent name, an operation type, and an operation parameter;
[0126] An instruction conversion module is used for the second terminal to obtain a touch screen gesture instruction, convert the touch screen gesture instruction into a control instruction that complies with the communication rule, and send the control instruction to the first terminal via WebSocket;
[0127] The instruction execution module is used for the first terminal to execute the control instruction on the Unity3D model.
[0128] Optionally, as an embodiment of the present invention, a first terminal and a second terminal are connected to the same local area network, and WebSocket communication is established between the first terminal and the second terminal, wherein the first terminal is loaded with a Unity3D model, including:
[0129] Establishing a WebSocket server through WebSocketSharp in Unity of a first terminal, where the first terminal uses a Windows operating system;
[0130] Create a WebSocket client in Unity on the second terminal, and establish a connection between the WebSocket server and the WebSocket client in the local area network.
[0131] Optionally, as an embodiment of the present invention, the communication rules include:
[0132] Model types include built-in model ExplodeModelOpt and dynamically loaded model GltfModelOpt;
[0133] If the model name belongs to a built-in model, the subcomponent name exists. If the model name does not belong to a built-in model, the subcomponent name does not exist.
[0134] Operation types include opening a model, closing a model, resetting a model state, moving a model, scaling a model, rotating a model, exploding a model, hiding a model, and controlling a model;
[0135] Operation parameters: Parameter items that match multiple operation types.
[0136] Optionally, as an embodiment of the present invention, the operating parameters include:
[0137] The parameters corresponding to the opened model include the path and name of the 3D model;
[0138] The parameter items corresponding to the closed model include the model name;
[0139] The parameter items corresponding to the reset model include the model name;
[0140] The parameter items corresponding to the mobile model include position, which is in world coordinates;
[0141] The parameter items corresponding to the scaling model include the scaling ratio Vector3;
[0142] The parameter items corresponding to the rotation model include Quaternion;
[0143] There are no restrictions on the parameter items corresponding to the explosion model;
[0144] The parameter items corresponding to the hidden model include true or false
[0145] The parameter items corresponding to the control model include all split parts, select split selected parts, and back return to the original position after selection.
[0146] Optionally, as an embodiment of the present invention, the second terminal obtains a touch screen gesture instruction, converts the touch screen gesture instruction into a control instruction that complies with the communication rule, and sends the control instruction to the first terminal via WebSocket, including:
[0147] Acquire electrical signals from the touch screen and convert the electrical signals into touch point coordinates;
[0148] Identify the number and position of fingers based on touch point coordinates;
[0149] If the number of fingers is 2, the distance between the fingers is obtained in real time, and the distance difference between the most recently obtained distance and the previously obtained distance is calculated; if the distance difference does not exceed the set distance threshold, the operation type is determined to be a move model; if the distance difference exceeds the distance threshold, the operation type is determined to be a zoom model;
[0150] If the number of fingers is 1, the operation type is determined to be a rotation model, and the horizontal and vertical offsets of touch.deltaPosition are obtained as operation parameters;
[0151] If the touch point coordinates are within the pre-packaged instruction triggering item area, the corresponding control instruction is called.
[0152] Optionally, as an embodiment of the present invention, if the touch point coordinates are within a pre-packaged instruction triggering item area, calling a corresponding control instruction includes:
[0153] If the touch point coordinates are within the explosion command triggering item area, the explosion model command ExplodeModelOpt*model name*explode*all is called;
[0154] If the touch point coordinates are within the reset instruction triggering item area, call the reset model instruction ExplodeModelOpt*1*reset*all;
[0155] If the touch point coordinates are within the close instruction triggering item area, call the close model instruction ExplodeModelOpt*1*close*all;
[0156] If the touch point coordinates are within the hidden instruction triggering item area, the hidden model instruction ExplodeModelOpt*1*hide*true is called.
[0157] Optionally, as an embodiment of the present invention, the first terminal executes the control instruction on the Unity3D model, including:
[0158] If the control instruction is a moving model or a scaling model, then extracting touch point coordinate data, wherein the touch point coordinate data is a touch point coordinate sequence arranged in chronological order, and the intervals between adjacent touch point coordinates are the same;
[0159] Collecting a sample sequence from the touch point coordinate sequence using a time window;
[0160] Calculating a coordinate difference between the latest touch point coordinates and the coordinates of adjacent touch points in the sample sequence, generating a motion vector based on the coordinate difference, and calculating a current motion speed based on the coordinate difference and the interval time;
[0161] Calculate the motion speed between the coordinates of adjacent touch points in the sample sequence to obtain a motion speed sequence;
[0162] Calculating corresponding accelerations based on adjacent motion speeds in the motion speed sequence to obtain an acceleration sequence, and calculating an average acceleration based on the acceleration sequence;
[0163] generating a predicted speed sequence based on the average acceleration and the current motion speed;
[0164] A relationship function between movement speed and adjustment ratio is established, and timing is started after adjusting the model ratio once. When the timing time reaches the set time, a new adjustment ratio is generated based on the relationship function and the predicted speed in the predicted speed sequence, and the model is adjusted based on the new adjustment ratio.
[0165] Figure 4 This is a structural diagram of a terminal 400 provided in an embodiment of the present invention. The terminal 400 can be used to execute the Unity3D model control method in a local area network provided in an embodiment of the present invention.
[0166] The terminal 400 may include a processor 410, a memory 420, and a communication unit 430. These components communicate via one or more buses. Those skilled in the art will appreciate that the server structure shown in the figure does not limit the present invention. The server structure may be a bus structure or a star structure, and may include more or fewer components than shown, or may combine certain components or arrange the components differently.
[0167] Memory 420 can be used to store execution instructions of processor 410. Memory 420 can be implemented by any type of volatile or non-volatile storage device, or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk, or optical disk. When the execution instructions in memory 420 are executed by processor 410, terminal 400 can perform some or all of the steps in the above-described method embodiments.
[0168] The processor 410 is the control center of the storage terminal. It uses various interfaces and lines to connect various parts of the entire electronic terminal. It executes various functions of the electronic terminal and / or processes data by running or executing software programs and / or modules stored in the memory 420, and calling data stored in the memory. The processor can be composed of an integrated circuit (IC), for example, it can be composed of a single packaged IC, or it can be composed of multiple packaged ICs with the same or different functions. For example, the processor 410 can only include a central processing unit (CPU). In an embodiment of the present invention, the CPU can be a single computing core or multiple computing cores.
[0169] The communication unit 430 is configured to establish a communication channel so that the storage terminal can communicate with other terminals, receive user data sent by other terminals, or send user data to other terminals.
[0170] The present invention also provides a computer storage medium, wherein the computer storage medium may store a program that, when executed, may include some or all of the steps of each embodiment provided herein. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0171] Therefore, the present invention establishes WebSocket communication within the local area network to achieve real-time control of the Unity3D model running on the Windows operating system by the Android device, overcoming the limitations of 3D model display and interaction in the existing technology, improving the convenience, real-time nature and user experience of 3D content interaction, and making the control process more intuitive and efficient. The technical effects that can be achieved by this embodiment can be found in the description above and will not be repeated here.
[0172] Those skilled in the art will clearly understand that the techniques in the embodiments of the present invention can be implemented using software plus a necessary general-purpose hardware platform. Based on this understanding, the technical solutions in the embodiments of the present invention, or the portion that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium such as a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, among other media capable of storing program code, and includes instructions for causing a computer terminal (which can be a personal computer, a server, or a second terminal, a network terminal, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention.
[0173] In this specification, the same or similar parts between the various embodiments can be referred to each other. In particular, for the terminal embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.
[0174] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For example, the division of the modules is merely a logical function division. In actual implementation, there may be other division methods, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or modules, and can be electrical, mechanical or other forms.
[0175] The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules may be selected to achieve the purpose of the present embodiment according to actual needs.
[0176] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0177] Although the present invention has been described in detail with reference to the accompanying drawings and in conjunction with preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, persons of ordinary skill in the art may make various equivalent modifications or substitutions to the embodiments of the present invention, and such modifications or substitutions shall be within the scope of the present invention. Any changes or substitutions that can be easily conceived by persons skilled in the art within the technical scope disclosed in the present invention shall be within the scope of protection of the present invention.
Claims
1. A Unity3D model control method in a local area network, characterized in that: include: Connecting a first terminal and a second terminal to the same local area network and establishing WebSocket communication between the first terminal and the second terminal, wherein the first terminal is loaded with a Unity3D model; The first terminal and the second terminal agree on a communication rule, wherein the communication rule includes a model type, a model name, a subcomponent name, an operation type, and an operation parameter; The second terminal obtains a touch screen gesture instruction, obtains an electrical signal from the touch screen, converts the electrical signal into touch point coordinates, identifies the number and position of fingers based on the touch point coordinates, converts the touch screen gesture instruction into a control instruction that complies with the communication rule, and sends the control instruction to the first terminal via WebSocket; the first terminal executes the control instruction on the Unity3D model, and if the control instruction is to move the model or scale the model, extracts touch point coordinate data, the touch point coordinate data being a touch point coordinate sequence arranged in chronological order, with the interval time between adjacent touch point coordinates being the same; and uses a time window to collect a sample sequence from the touch point coordinate sequence; Calculating a coordinate difference between the latest touch point coordinates and the coordinates of adjacent touch points in the sample sequence, generating a motion vector based on the coordinate difference, and calculating a current motion speed based on the coordinate difference and the interval time; Calculating motion speeds between adjacent touch point coordinates in a sample sequence to obtain a motion speed sequence; calculating corresponding accelerations based on adjacent motion speeds in the motion speed sequence to obtain an acceleration sequence; and calculating an average acceleration based on the acceleration sequence; A predicted speed sequence is generated based on the average acceleration and the current movement speed; a relationship function between the movement speed and the adjustment ratio is established, timing is started after the model ratio is adjusted once, and when the timing time reaches the set time, a new adjustment ratio is generated based on the relationship function and the predicted speed in the predicted speed sequence, and the model is adjusted based on the new adjustment ratio.
2. The method according to claim 1, characterized in that Connecting a first terminal and a second terminal to the same local area network and establishing WebSocket communication between the first terminal and the second terminal, wherein the first terminal is loaded with a Unity3D model, including: establishing a WebSocket server through WebSocketSharp in Unity on the first terminal, wherein the first terminal uses a Windows operating system; Create a WebSocket client in Unity on the second terminal, and establish a connection between the WebSocket server and the WebSocket client in the local area network.
3. The method according to claim 1, characterized in that The communication rules include: Model types include built-in model ExplodeModelOpt and dynamically loaded model GltfModelOpt; If the model name belongs to a built-in model, the subcomponent name exists. If the model name does not belong to a built-in model, the subcomponent name does not exist. Operation types include opening a model, closing a model, resetting a model state, moving a model, scaling a model, rotating a model, exploding a model, hiding a model, and controlling a model; Operation parameters: Parameter items that match multiple operation types.
4. The method according to claim 3, characterized in that The operating parameters include: The parameters corresponding to the opened model include the path and name of the 3D model; The parameter items corresponding to the closed model include the model name; The parameter items corresponding to the reset model include the model name; The parameter items corresponding to the mobile model include position, which is in world coordinates; The parameter items corresponding to the scaling model include the scaling ratio Vector3; The parameter items corresponding to the rotation model include Quaternion; There are no restrictions on the parameter items corresponding to the explosion model; The parameter items corresponding to the hidden model include true or false; The parameter items corresponding to the control model include all split parts, select split selected parts, and back return to the original position after selection.
5. The method according to claim 1, wherein The second terminal obtains a touch screen gesture instruction, obtains an electrical signal from the touch screen, converts the electrical signal into touch point coordinates, identifies the number of fingers and finger positions based on the touch point coordinates, converts the touch screen gesture instruction into a control instruction that complies with the communication rule, and sends the control instruction to the first terminal through the WebSocket, including: If the number of fingers is 2, the distance between the fingers is obtained in real time, and the distance difference between the most recently obtained distance and the previously obtained distance is calculated; if the distance difference does not exceed the set distance threshold, the operation type is determined to be a move model; if the distance difference exceeds the distance threshold, the operation type is determined to be a zoom model; If the number of fingers is 1, the operation type is determined to be a rotation model, and the horizontal and vertical offsets of touch.deltaPosition are obtained as operation parameters; if the touch point coordinates are within the pre-packaged instruction trigger item area, the corresponding control instruction is called.
6. The method according to claim 5, characterized in that If the touch point coordinates are within the pre-packaged instruction triggering item area, the corresponding control instruction is called, including: If the touch point coordinates are within the explosion instruction triggering item area, the explosion model instruction ExplodeModelOpt*model name*explode*all is called; If the touch point coordinates are within the reset instruction triggering item area, call the reset model instruction ExplodeModelOpt*model name*reset*all; If the touch point coordinates are within the close instruction triggering item area, call the close model instruction ExplodeModelOpt*model name*close*all; If the touch point coordinates are within the hide instruction triggering item area, the hide model instruction ExplodeModelOpt*model name*hide*true is called.
7. A Unity3D model control system in a local area network, characterized in that: include: a communication establishing module, configured to connect a first terminal and a second terminal to the same local area network and establish WebSocket communication between the first terminal and the second terminal, wherein the first terminal is loaded with a Unity3D model; A rule agreement module, configured to agree on communication rules between the first terminal and the second terminal, wherein the communication rules include a model type, a model name, a subcomponent name, an operation type, and an operation parameter; An instruction conversion module is used for the second terminal to obtain a touch screen gesture instruction, convert the touch screen gesture instruction into a control instruction that complies with the communication rule, and send the control instruction to the first terminal via WebSocket; The instruction execution module is used for the first terminal to execute the control instruction on the Unity3D model.
8. A terminal, characterized in that: include: Memory, used to store Unity3D model control program in the local area network; A processor is configured to implement the steps of the method for controlling a Unity3D model in a local area network as claimed in any one of claims 1 to 6 when executing the Unity3D model control program in the local area network.
9. A computer-readable storage medium storing a computer program, characterized in that: The readable storage medium stores a Unity3D model control program in a local area network. When the Unity3D model control program in a local area network is executed by a processor, the steps of the Unity3D model control method in a local area network are implemented as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Three-dimensional model gesture touch browsing interaction method based on mobile terminal
CN103942053A
Method and system for using sensors of control device for control of game
CN110382064A
Visual remote control method, control device, storage medium and interaction system
CN117880574A