added and fixed many blocks
This commit is contained in:
parent
9dbd8d607c
commit
b017beca2d
|
|
@ -4,12 +4,12 @@ import { javascriptGenerator, Order } from "blockly/javascript";
|
||||||
Blockly.Blocks['physics_apply_impulse_action'] = {
|
Blockly.Blocks['physics_apply_impulse_action'] = {
|
||||||
init(this: Blockly.Block) {
|
init(this: Blockly.Block) {
|
||||||
this.appendDummyInput('')
|
this.appendDummyInput('')
|
||||||
.appendField('Push me to');
|
.appendField('Push me in direction of');
|
||||||
this.appendValueInput('POSITION')
|
this.appendValueInput('POSITION')
|
||||||
.setCheck('Pos');
|
.setCheck('DPos');
|
||||||
this.appendDummyInput('')
|
this.appendDummyInput('')
|
||||||
.appendField('with force')
|
.appendField('with force')
|
||||||
.appendField(new Blockly.FieldNumber(1, -10, 10, 2), 'FORCE');
|
.appendField(new Blockly.FieldNumber(1, -10, 10, 0.01), 'FORCE');
|
||||||
|
|
||||||
|
|
||||||
this.setInputsInline(true)
|
this.setInputsInline(true)
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,10 @@ export function generateCode(workspace: Blockly.WorkspaceSvg): string {
|
||||||
}
|
}
|
||||||
body = javascriptGenerator.prefixLines(body, javascriptGenerator.INDENT);
|
body = javascriptGenerator.prefixLines(body, javascriptGenerator.INDENT);
|
||||||
|
|
||||||
const args = Array.from(block.getFields())
|
// const args = Array.from(block.getFields())
|
||||||
.filter(field => field.name !== undefined)
|
// .filter(field => field.name !== undefined)
|
||||||
.map(field => `${field.name}: ${JSON.stringify(field.getValue())}`)
|
// .map(field => `${field.name}: ${JSON.stringify(field.getValue())}`)
|
||||||
.join(', ');
|
// .join(', ');
|
||||||
|
|
||||||
//TODO use args
|
//TODO use args
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
import * as Blockly from "blockly";
|
||||||
|
import { javascriptGenerator, Order } from "blockly/javascript";
|
||||||
|
|
||||||
|
Blockly.Blocks['dpos_value'] = {
|
||||||
|
init(this: Blockly.Block) {
|
||||||
|
this.appendDummyInput()
|
||||||
|
.appendField('Direction [')
|
||||||
|
.appendField(new Blockly.FieldNumber(0, -Infinity, Infinity, 0.01), 'X')
|
||||||
|
.appendField(',')
|
||||||
|
.appendField(new Blockly.FieldNumber(0, -Infinity, Infinity, 0.01), 'Y')
|
||||||
|
.appendField(',')
|
||||||
|
.appendField(new Blockly.FieldNumber(0, -Infinity, Infinity, 0.01), 'Z');
|
||||||
|
this.appendDummyInput()
|
||||||
|
.appendField(']');
|
||||||
|
this.setInputsInline(true);
|
||||||
|
this.setOutput(true, 'DPos');
|
||||||
|
this.setTooltip('Direction [dx,dy,dz]');
|
||||||
|
this.setColour(315);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
javascriptGenerator.forBlock['dpos_value'] = function (block, _generator) {
|
||||||
|
const xValue = block.getFieldValue('X');
|
||||||
|
const yValue = block.getFieldValue('Y');
|
||||||
|
const zValue = block.getFieldValue('Z');
|
||||||
|
return [`[${xValue},${yValue},${zValue}]`, Order.ATOMIC];
|
||||||
|
};
|
||||||
|
|
||||||
|
export { };
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
import * as Blockly from "blockly";
|
||||||
|
import { javascriptGenerator, Order } from "blockly/javascript";
|
||||||
|
|
||||||
|
Blockly.Blocks['direction_to_position_value'] = {
|
||||||
|
init(this: Blockly.Block) {
|
||||||
|
this.appendDummyInput()
|
||||||
|
.appendField('Direction to');
|
||||||
|
this.appendValueInput('TARGET')
|
||||||
|
.setCheck('Pos');
|
||||||
|
this.setInputsInline(true);
|
||||||
|
this.setOutput(true, 'DPos');
|
||||||
|
this.setTooltip('Direction to a position');
|
||||||
|
this.setColour(315);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
javascriptGenerator.forBlock['direction_to_position_value'] = function (block, generator) {
|
||||||
|
const targetValue = generator.valueToCode(block, 'TARGET', Order.ATOMIC);
|
||||||
|
return [`((a,b)=>[a[0]-b[0],a[1]-b[1],a[2]-b[2]])(${targetValue},object.position)`, Order.NONE];
|
||||||
|
};
|
||||||
|
|
||||||
|
export { };
|
||||||
|
|
@ -4,3 +4,6 @@ export * from './anyObjectOfType';
|
||||||
export * from './objectType';
|
export * from './objectType';
|
||||||
export * from './positionOfObject';
|
export * from './positionOfObject';
|
||||||
export * from './position';
|
export * from './position';
|
||||||
|
export * from './direction';
|
||||||
|
export * from './objectById';
|
||||||
|
export * from './directionToPosition';
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
import * as Blockly from "blockly";
|
||||||
|
import { javascriptGenerator, Order } from "blockly/javascript";
|
||||||
|
|
||||||
|
Blockly.Blocks['object_by_id_value'] = {
|
||||||
|
init(this: Blockly.Block) {
|
||||||
|
this.appendEndRowInput()
|
||||||
|
.appendField('Object with id')
|
||||||
|
.appendField(new Blockly.FieldTextInput(''), 'TARGET_ID');
|
||||||
|
this.setInputsInline(false)
|
||||||
|
this.setOutput(true, 'Object');
|
||||||
|
this.setTooltip('Returns object by id, if any');
|
||||||
|
this.setColour(315);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
javascriptGenerator.forBlock['object_by_id_value'] = function (block, _generator) {
|
||||||
|
const targetIdValue = block.getFieldValue('TARGET_ID');
|
||||||
|
return [`context.scene.objects['${targetIdValue}']`, Order.ATOMIC];
|
||||||
|
};
|
||||||
|
|
||||||
|
export { };
|
||||||
|
|
@ -4,12 +4,12 @@ import { javascriptGenerator, Order } from "blockly/javascript";
|
||||||
Blockly.Blocks['pos_value'] = {
|
Blockly.Blocks['pos_value'] = {
|
||||||
init(this: Blockly.Block) {
|
init(this: Blockly.Block) {
|
||||||
this.appendDummyInput('POSITION')
|
this.appendDummyInput('POSITION')
|
||||||
.appendField('[')
|
.appendField('Position [')
|
||||||
.appendField(new Blockly.FieldNumber(0, -Infinity, Infinity, 2), 'X')
|
.appendField(new Blockly.FieldNumber(0, -Infinity, Infinity, 0.01), 'X')
|
||||||
.appendField(',')
|
.appendField(',')
|
||||||
.appendField(new Blockly.FieldNumber(0, -Infinity, Infinity, 2), 'Y')
|
.appendField(new Blockly.FieldNumber(0, -Infinity, Infinity, 0.01), 'Y')
|
||||||
.appendField(',')
|
.appendField(',')
|
||||||
.appendField(new Blockly.FieldNumber(0, -Infinity, Infinity, 2), 'Z');
|
.appendField(new Blockly.FieldNumber(0, -Infinity, Infinity, 0.01), 'Z');
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(']');
|
.appendField(']');
|
||||||
this.setInputsInline(true);
|
this.setInputsInline(true);
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ import { javascriptGenerator, Order } from "blockly/javascript";
|
||||||
|
|
||||||
Blockly.Blocks['position_of_object_value'] = {
|
Blockly.Blocks['position_of_object_value'] = {
|
||||||
init(this: Blockly.Block) {
|
init(this: Blockly.Block) {
|
||||||
this.appendDummyInput('NAME')
|
this.appendDummyInput()
|
||||||
.appendField('Position of');
|
.appendField('Position of');
|
||||||
this.appendValueInput('NAME')
|
this.appendValueInput('TARGET')
|
||||||
.setCheck('Object');
|
.setCheck('Object');
|
||||||
this.setInputsInline(true);
|
this.setInputsInline(true);
|
||||||
this.setOutput(true, 'Pos');
|
this.setOutput(true, 'Pos');
|
||||||
|
|
@ -14,8 +14,9 @@ Blockly.Blocks['position_of_object_value'] = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
javascriptGenerator.forBlock['position_of_object_value'] = function (_block, _generator) {
|
javascriptGenerator.forBlock['position_of_object_value'] = function (block, generator) {
|
||||||
return ['123', Order.NONE];
|
const targetValue = generator.valueToCode(block, 'TARGET', Order.ATOMIC);
|
||||||
|
return [`${targetValue}.position`, Order.NONE];
|
||||||
};
|
};
|
||||||
|
|
||||||
export { };
|
export { };
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ export const PlayerObjectView = observer(function ({ object, objectType }: Playe
|
||||||
const W = bb.max[0] - bb.min[0];
|
const W = bb.max[0] - bb.min[0];
|
||||||
const H = bb.max[1] - bb.min[1];
|
const H = bb.max[1] - bb.min[1];
|
||||||
const D = bb.max[2] - bb.min[2];
|
const D = bb.max[2] - bb.min[2];
|
||||||
const radius = Math.sqrt(W * W + H * H + D * D) / 2;
|
const radius = Math.sqrt(W * W + H * H + D * D);
|
||||||
const centerY = (bb.min[1] + bb.max[1]) / 2;
|
const centerY = (bb.min[1] + bb.max[1]) / 2;
|
||||||
return {
|
return {
|
||||||
shoulderOffset: new Vector3(W * 0.1, centerY + H * 0.3, bb.max[2] + radius),
|
shoulderOffset: new Vector3(W * 0.1, centerY + H * 0.3, bb.max[2] + radius),
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,8 @@ export const ObjectViewInternal = function ({ object, objectType, ref, ...props
|
||||||
if (!impulse) return;
|
if (!impulse) return;
|
||||||
if (!rbRef.current) { console.warn('applyImpulse: rbRef is null for', gameObj.id); return; }
|
if (!rbRef.current) { console.warn('applyImpulse: rbRef is null for', gameObj.id); return; }
|
||||||
|
|
||||||
const { direction, amplitude } = impulse;
|
let { direction, amplitude } = impulse;
|
||||||
|
amplitude *= 100;
|
||||||
const v = { x: direction[0] * amplitude, y: direction[1] * amplitude, z: direction[2] * amplitude };
|
const v = { x: direction[0] * amplitude, y: direction[1] * amplitude, z: direction[2] * amplitude };
|
||||||
console.log('applyImpulse', gameObj.id, v, 'bodyType', rbRef.current.bodyType());
|
console.log('applyImpulse', gameObj.id, v, 'bodyType', rbRef.current.bodyType());
|
||||||
rbRef.current.applyImpulse(v, true);
|
rbRef.current.applyImpulse(v, true);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@ const TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
|
||||||
{ kind: 'block', type: 'any_object_of_type_value' },
|
{ kind: 'block', type: 'any_object_of_type_value' },
|
||||||
{ kind: 'block', type: 'position_of_object_value' },
|
{ kind: 'block', type: 'position_of_object_value' },
|
||||||
{ kind: 'block', type: 'pos_value' },
|
{ kind: 'block', type: 'pos_value' },
|
||||||
|
{ kind: 'block', type: 'dpos_value' },
|
||||||
|
{ kind: 'block', type: 'direction_to_position_value' },
|
||||||
|
{ kind: 'block', type: 'object_by_id_value' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue