我有一个场景,其中有几个物体和一些物体,在这些情况下,我希望球体受到粉色和蓝色灯光的影响。但我还有一个管几何形状,它应该只受白光影响,而不受粉红色和蓝色光的影响。
请参阅下图以了解问题的演示: 现在发生了什么:
但我希望管子不是粉色和蓝色的,而是灰色的:
目前,我用 a 来做到这一点,meshBasicMaterial
但这会阻止管子看起来 3D。
那么我如何创建这个MeshLambertMaterial
不受粉色和蓝色光影响的灰色管呢?
请参阅下面的代码了解我现在如何生成场景:
# Generating of spheres:
for (var i = 0; i < 5; i++) {
var SphereGeometry = new THREE.SphereGeometry(2, 20, 20);
var SphereMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
var Sphere = new THREE.Mesh(SphereGeometry, SphereMaterial);
Sphere.position.set(i * 7 -14, 0 + Math.random() * 5 - 2.5, 2);
spheresArray.push(Sphere);
scene.add(Sphere);
}
#Generation of tubes:
for (var i = 0; i < CurvesArray.length; i++) {
var geometry = …
Run Code Online (Sandbox Code Playgroud) 我有一个附加到一个盒子的脚本,该盒子有两个用于物理的碰撞器,一个(稍大)用于当我的玩家走过它时检测 OntriggerEnters。我在盒子上附加了一个脚本,它执行以下操作:
public class ColorChangeCollision : MonoBehaviour {
private GameObject Element;
private Color32 BaseColor, CollisionColor;
private Material ElementMaterial;
void Start () {
Element = this.gameObject;
BaseColor = new Color32(255,255,255,255);
CollisionColor = new Color32((byte)Random.Range(0, 255),(byte)Random.Range(0, 255),(byte)Random.Range(0, 255), 255);
ElementMaterial = Element.gameObject.GetComponent<Renderer>().material;
}
private void OnControllerColliderHit(ControllerColliderHit other)
{
Debug.Log("collision...");
ElementMaterial.color = CollisionColor;
}
private void OnTriggerEnter(Collider other)
{
Debug.Log("enter");
}
private void OnTriggerStay(Collider other)
{
Debug.Log("staying..");
}
private void OnTriggerExit(Collider other)
{
Debug.Log("left...");
ElementMaterial.color = BaseColor;
}
}
Run Code Online (Sandbox Code Playgroud)
主要问题 OnTriggerEnter
是OnControllerColliderHit …
我有以下代码来锁定光标(效果很好):
var element = document.body;
var controls;
var instructions = document.getElementById( 'start' );
var havePointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
if ( havePointerLock ) {
var pointerlockchange = function ( event ) {
if ( document.pointerLockElement === element || document.mozPointerLockElement === element || document.webkitPointerLockElement === element ) {
controlsEnabled = true;
controls.enabled = true;
} else {
controlsEnabled = false;
controls.enabled = false;
instructions.style.display = '';
}
};
var pointerlockerror = function ( …
Run Code Online (Sandbox Code Playgroud) 嘿,我有以下代码以度为单位计算角度:
var angleDeg = Math.atan2(mouse.y - base.y, mouse.x - base.x) * 180 / Math.PI;
console.log(angleDeg);
Run Code Online (Sandbox Code Playgroud)
但目前我得到了 0 到 180 度之间的正负角度。右侧为 0 度,请参见图像。但我希望返回的角度在 0 到 360 之间都是正的。顶部为 0 度。看图片。
我如何更新我的功能以使其有效?我用javascript写这个。所以最后我希望角度值作为图像中的粉红色返回。任何帮助是极大的赞赏!!!
希望这很清楚,如果不是,请让我知道,以便我可以更新我的问题。
我有一些代码可以创建自定义UI类.这是通过以下方式完成的:
public class EasyUIData
{
protected static Canvas EasyCanvasOptions;
protected static Vector2 EasyCanvasDimensions;
}
public class UIBaseProperties : EasyUIData
{
protected GameObject UIElement;
protected RectTransform Anchor;
protected Vector2 Loc;
protected int? SizeX, SizeY;
public UIBaseProperties(Vector2 loc, int? sizeX = null, int? sizeY = null)
{
UIElement = new GameObject();
this.Loc = loc;
this.SizeX = sizeX;
this.SizeY = sizeY;
}
}
public class RawImage : UIBaseProperties
{
private RawImage UIImageComponent;
private Texture2D Img;
public RawImage(Texture2D img, Vector2 loc, int? sizeX = …
Run Code Online (Sandbox Code Playgroud) 我有一个项目,我正在添加一些打字稿,但打字稿不会自动导入。我不明白为什么。请参阅下面我的文件结构、tsconfig 和示例:
配置文件
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"pretty": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noImplicitAny": true,
"noImplicitReturns": false,
"noImplicitUseStrict": false,
"outDir": "../Js/",
"baseUrl": "./",
},
"include":[
"*.ts"
],
"compileOnSave": true
}
Run Code Online (Sandbox Code Playgroud)
应用 ts 预期导入建议
在这里,我期待看到
ImageRowsInitializer
从名为images-row.ts
.
图像行.ts
export class ImageRowsInitializer {
private image_rows : ImagesRow[];
constructor() {
const htmlImageRows = document.getElementsByClassName("row-container");
for (let i = 0; i < htmlImageRows.length; i++) {
const imagerow = htmlImageRows[i];
this.image_rows.push(new …
Run Code Online (Sandbox Code Playgroud) 我有一个从网络获取一些数据的自定义类。
当我获得这些数据时,我想将它设置为一个属性的值,但是当我这样做时,统一崩溃了。注释行会在没有此行的情况下生成崩溃,一切正常。请参阅下面的代码:
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class GetDB
{
private readonly Main m;
private readonly string Url;
public string DBData {
get
{
if(DBData == null)
return null;
else
return DBData;
}
private set
{
DBData = value;
}
}
public GetDB(Main m, string url)
{
this.m = m;
this.Url = url;
}
public void GetServerData(){
m.StartCoroutine(GetText(Url, (result) =>{
this.DBData = result; //THIS LINE CRASHES UNITY
Debug.Log(result);
}));
}
IEnumerator GetText(string url, Action<string> result) { …
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个在发生某些事情时引发的事件。因此,包含对引发事件的类的引用的其他类会得到通知。这是我到目前为止所得到的:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DropArea : MonoBehaviour {
public event EventHandler ObjectChange;
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
var correctType = FindParentWithComponent(other.gameObject);
if (correctType != null)
{
var cc = correctType.GetComponent<Object_properties>();
if(cc.VariableTypeSelector == AcceptedVariableType)
{
DetectedObjectChange(null); // here i want to raise the event
}
}
}
protected virtual void DetectedObjectChange(EventArgs e)
{
EventHandler handler = ObjectChange;
if …
Run Code Online (Sandbox Code Playgroud) 我试图在大写字母后找到所有数字.请参阅以下示例:
E1S1
应该给我一个数组包含: [1 , 1]
S123455D1223
应该给我一个数组包含: [123455 , 1223]
我试过以下但没有得到上面显示的任何例子的任何匹配:(
$loc = "E123S5";
$locs = array();
preg_match('/\[A-Z]([0-9])/', $loc, $locs);
Run Code Online (Sandbox Code Playgroud)
任何帮助非常感谢我是regex的新手.
我有一个类,它对<p>
包含一些文本的元素创建一个打字机效果.请参阅下面的HTML和JavaScript.
我有一个用JavaScript处理动画部分的类.这必须是一个班级,因为会有其他事情发生.
var ani;
$(document).ready(function() {
ani = new Animate_text("test sentence", false, 30);
ani.writer();
});
class Animate_text {
constructor(text, dynamic, speed) {
this.text = text;
this.speed = speed;
this.dynamic = dynamic;
this.chars = text.length;
this.text_loc = 0;
this.timerID = null;
this.animate_image = false;
}
writer() {
var sContents = "";
var destination = document.getElementById("text");
console.log(destination.innerHTML);
destination.innerHTML = this.sContents + this.text.substring(0, this.text_loc) + "";
if (this.text_loc++ == this.chars) {
this.text_loc = 0;
if (this.dynamic) {
window.clearTimeout(this.timerID);
ani = null; …
Run Code Online (Sandbox Code Playgroud)c# ×4
javascript ×4
three.js ×2
3d ×1
angle ×1
auto-import ×1
class ×1
components ×1
coroutine ×1
degrees ×1
delegates ×1
events ×1
function ×1
html ×1
innerhtml ×1
jquery ×1
light ×1
php ×1
pointerlock ×1
properties ×1
regex ×1
triggers ×1
typescript ×1
vector ×1