server-side message position validation with o3d
This commit is contained in:
parent
462399de43
commit
f71056b9b4
15
api/api.py
15
api/api.py
@ -4,8 +4,11 @@ from uuid import uuid4
|
||||
import sqlite3
|
||||
import numbers
|
||||
from flask import g
|
||||
import open3d
|
||||
import numpy
|
||||
|
||||
DATABASE = './forum.db'
|
||||
TERRAIN_MODEL = './terrain.glb'
|
||||
|
||||
def get_db():
|
||||
db = getattr(g, '__database', None)
|
||||
@ -15,6 +18,13 @@ def get_db():
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
terrain_mesh = open3d.io.read_triangle_mesh('./terrain.glb')
|
||||
terrain_mesh = open3d.t.geometry.TriangleMesh.from_legacy(terrain_mesh)
|
||||
print('loaded terrain mesh')
|
||||
scene = open3d.t.geometry.RaycastingScene()
|
||||
_ = scene.add_triangles(terrain_mesh)
|
||||
print('created raycasting scene')
|
||||
|
||||
@app.teardown_appcontext
|
||||
def close_connection(_):
|
||||
db = getattr(g, '__database', None)
|
||||
@ -41,6 +51,11 @@ def new_message():
|
||||
for elem in position:
|
||||
if not isinstance(elem, numbers.Number):
|
||||
return Response(status=HTTPStatus.BAD_REQUEST)
|
||||
query_point = open3d.core.Tensor([position], dtype=open3d.core.Dtype.Float32)
|
||||
unsigned_distance = scene.compute_distance(query_point)
|
||||
print(unsigned_distance)
|
||||
if unsigned_distance > 0.25:
|
||||
return Response(status=HTTPStatus.BAD_REQUEST)
|
||||
position = json.dumps(position)
|
||||
message = str(request.form['message'])
|
||||
token = request.form['token']
|
||||
|
BIN
api/terrain.glb
Normal file
BIN
api/terrain.glb
Normal file
Binary file not shown.
Binary file not shown.
@ -5,14 +5,15 @@ import { useGLTF } from '@react-three/drei';
|
||||
import terrainModelURL from '../assets/terrain.glb';
|
||||
|
||||
export default function Ground() {
|
||||
const meshRef = useRef();
|
||||
const { nodes } = useGLTF(terrainModelURL);
|
||||
|
||||
const { nodes, materials } = useGLTF(terrainModelURL);
|
||||
return (
|
||||
<RigidBody type='fixed' colliders="trimesh">
|
||||
<mesh ref={meshRef} position={[0, 0, 0]} rotation={[-Math.PI / 2, 0, 0]} geometry={nodes.Plane.geometry} name='ground'>
|
||||
<mesh position={[0, 0, 0]} geometry={nodes.ground.geometry} name='ground'>
|
||||
<meshStandardMaterial color={everforest.yellow}/>
|
||||
</mesh>
|
||||
<mesh geometry={nodes.pyramid.geometry} name='ground'>
|
||||
<meshStandardMaterial color={everforest.bg2}/>
|
||||
</mesh>
|
||||
</RigidBody>
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user